Skip to content

Commit

Permalink
More elegant solution to dummymessage
Browse files Browse the repository at this point in the history
  • Loading branch information
fourjr committed Nov 10, 2020
1 parent 27afe7d commit a7c2387
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
This project mostly adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html);
however, insignificant breaking changes do not guarantee a major version bump, see the reasoning [here](https://github.com/kyb3r/modmail/issues/319). If you're a plugins developer, note the "BREAKING" section.

# v3.7.0-dev10
# v3.7.0-dev11

### Added

Expand Down
2 changes: 1 addition & 1 deletion bot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "3.7.0-dev10"
__version__ = "3.7.0-dev11"


import asyncio
Expand Down
5 changes: 1 addition & 4 deletions cogs/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,7 @@ async def move(self, ctx, *, arguments):
await thread.channel.send(f"{mention}, thread has been moved.")

sent_emoji, _ = await self.bot.retrieve_emoji()
try:
await self.bot.add_reaction(ctx.message, sent_emoji)
except discord.NotFound:
pass
await self.bot.add_reaction(ctx.message, sent_emoji)

async def send_scheduled_close_message(self, ctx, after, silent=False):
human_delta = human_timedelta(after.dt)
Expand Down
2 changes: 1 addition & 1 deletion cogs/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -1707,7 +1707,7 @@ async def oauth_show(self, ctx):
@commands.group(invoke_without_command=True)
@checks.has_permissions(PermissionLevel.OWNER)
async def autotrigger(self, ctx):
"""Automatically trigger alias-like commands based on a certain keyword"""
"""Automatically trigger alias-like commands based on a certain keyword in the user's inital message"""
await ctx.send_help(ctx.command)

@autotrigger.command(name="add")
Expand Down
43 changes: 43 additions & 0 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,46 @@ def check(c):
raise commands.ChannelNotFound(argument)

return result


class DummyMessage:
"""
A class mimicking the original :class:discord.Message
where all functions that require an actual message to exist
is replaced with a dummy function
"""
def __init__(self, message):
self._message = message

def __getattr__(self, name: str):
return getattr(self._message, name)

async def delete(self, *, delay=None):
return

async def edit(self, **fields):
return

async def add_reaction(self, emoji):
return

async def remove_reaction(self, emoji):
return

async def clear_reaction(self, emoji):
return

async def clear_reactions(self):
return

async def pin(self, *, reason=None):
return

async def unpin(self, *, reason=None):
return

async def publish(self):
return

async def ack(self):
return
7 changes: 2 additions & 5 deletions core/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
import discord
from discord.ext.commands import MissingRequiredArgument, CommandError

from core import checks
from core.models import PermissionLevel, getLogger
from core.models import DummyMessage, getLogger
from core.time import human_timedelta
from core.utils import (
is_image_url,
Expand Down Expand Up @@ -200,7 +199,7 @@ async def send_recipient_genesis_message():
await self.bot.add_reaction(msg, close_emoji)

async def activate_auto_triggers():
message = copy.copy(initial_message)
message = DummyMessage(copy.copy(initial_message))
if message:
for keyword in list(self.bot.auto_triggers):
if keyword in message.content:
Expand Down Expand Up @@ -894,8 +893,6 @@ async def send(
if delete_message and destination == self.channel:
try:
await message.delete()
except discord.NotFound:
pass
except Exception as e:
logger.warning("Cannot delete message: %s.", e)

Expand Down

0 comments on commit a7c2387

Please sign in to comment.