Skip to content

Commit a7c2387

Browse files
committed
More elegant solution to dummymessage
1 parent 27afe7d commit a7c2387

File tree

6 files changed

+49
-12
lines changed

6 files changed

+49
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66
This project mostly adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html);
77
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.
88

9-
# v3.7.0-dev10
9+
# v3.7.0-dev11
1010

1111
### Added
1212

bot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "3.7.0-dev10"
1+
__version__ = "3.7.0-dev11"
22

33

44
import asyncio

cogs/modmail.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,7 @@ async def move(self, ctx, *, arguments):
338338
await thread.channel.send(f"{mention}, thread has been moved.")
339339

340340
sent_emoji, _ = await self.bot.retrieve_emoji()
341-
try:
342-
await self.bot.add_reaction(ctx.message, sent_emoji)
343-
except discord.NotFound:
344-
pass
341+
await self.bot.add_reaction(ctx.message, sent_emoji)
345342

346343
async def send_scheduled_close_message(self, ctx, after, silent=False):
347344
human_delta = human_timedelta(after.dt)

cogs/utility.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,7 @@ async def oauth_show(self, ctx):
17071707
@commands.group(invoke_without_command=True)
17081708
@checks.has_permissions(PermissionLevel.OWNER)
17091709
async def autotrigger(self, ctx):
1710-
"""Automatically trigger alias-like commands based on a certain keyword"""
1710+
"""Automatically trigger alias-like commands based on a certain keyword in the user's inital message"""
17111711
await ctx.send_help(ctx.command)
17121712

17131713
@autotrigger.command(name="add")

core/models.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,46 @@ def check(c):
211211
raise commands.ChannelNotFound(argument)
212212

213213
return result
214+
215+
216+
class DummyMessage:
217+
"""
218+
A class mimicking the original :class:discord.Message
219+
where all functions that require an actual message to exist
220+
is replaced with a dummy function
221+
"""
222+
def __init__(self, message):
223+
self._message = message
224+
225+
def __getattr__(self, name: str):
226+
return getattr(self._message, name)
227+
228+
async def delete(self, *, delay=None):
229+
return
230+
231+
async def edit(self, **fields):
232+
return
233+
234+
async def add_reaction(self, emoji):
235+
return
236+
237+
async def remove_reaction(self, emoji):
238+
return
239+
240+
async def clear_reaction(self, emoji):
241+
return
242+
243+
async def clear_reactions(self):
244+
return
245+
246+
async def pin(self, *, reason=None):
247+
return
248+
249+
async def unpin(self, *, reason=None):
250+
return
251+
252+
async def publish(self):
253+
return
254+
255+
async def ack(self):
256+
return

core/thread.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
import discord
1212
from discord.ext.commands import MissingRequiredArgument, CommandError
1313

14-
from core import checks
15-
from core.models import PermissionLevel, getLogger
14+
from core.models import DummyMessage, getLogger
1615
from core.time import human_timedelta
1716
from core.utils import (
1817
is_image_url,
@@ -200,7 +199,7 @@ async def send_recipient_genesis_message():
200199
await self.bot.add_reaction(msg, close_emoji)
201200

202201
async def activate_auto_triggers():
203-
message = copy.copy(initial_message)
202+
message = DummyMessage(copy.copy(initial_message))
204203
if message:
205204
for keyword in list(self.bot.auto_triggers):
206205
if keyword in message.content:
@@ -894,8 +893,6 @@ async def send(
894893
if delete_message and destination == self.channel:
895894
try:
896895
await message.delete()
897-
except discord.NotFound:
898-
pass
899896
except Exception as e:
900897
logger.warning("Cannot delete message: %s.", e)
901898

0 commit comments

Comments
 (0)