Skip to content

Commit a9c4040

Browse files
committed
Add anonymous functionality
1 parent 2d54506 commit a9c4040

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

core/thread.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ async def note(self, message):
184184
)
185185

186186

187-
async def reply(self, message):
187+
async def reply(self, message, anonymous=False):
188188
if not message.content and not message.attachments:
189189
raise commands.UserInputError
190190
if all(not g.get_member(self.id) for g in self.bot.guilds):
@@ -196,13 +196,14 @@ async def reply(self, message):
196196

197197
tasks = [
198198
# in thread channel
199-
self.send(message, self.channel, from_mod=True),
199+
self.send(message, destination=self.channel, from_mod=True, anonymous=True),
200200
# to user
201-
self.send(message, self.recipient, from_mod=True)
201+
self.send(message, destination=self.recipient, from_mod=True, anonymous=True)
202202
]
203203

204+
204205
self.bot.loop.create_task(
205-
self.bot.modmail_api.append_log(message, self.channel.id)
206+
self.bot.modmail_api.append_log(message, self.channel.id, type='anonymous' if anonymous else 'thread_message')
206207
)
207208

208209
if self.close_task is not None:
@@ -215,7 +216,7 @@ async def reply(self, message):
215216

216217
await asyncio.gather(*tasks)
217218

218-
async def send(self, message, destination=None, from_mod=False, note=False):
219+
async def send(self, message, destination=None, from_mod=False, note=False, anonymous=False):
219220
if self.close_task is not None:
220221
# cancel closing if a thread message is sent.
221222
await self.cancel_closure()
@@ -244,10 +245,21 @@ async def send(self, message, destination=None, from_mod=False, note=False):
244245

245246
# store message id in hidden url
246247
if not note:
247-
em.set_author(name=author,
248-
icon_url=author.avatar_url,
248+
249+
if anonymous and from_mod and not isinstance(destination, discord.TextChannel):
250+
# Anonymously sending to the user.
251+
name = self.bot.config.get('anon_username', self.bot.config.get('mod_tag', 'Moderator'))
252+
avatar_url = self.bot.config.get('anon_avatar_url', self.bot.guild.icon_url)
253+
else:
254+
# Normal message
255+
name = str(author)
256+
avatar_url = author.avatar_url
257+
258+
em.set_author(name=name,
259+
icon_url=avatar_url,
249260
url=message.jump_url)
250261
else:
262+
# Special note messages
251263
em.set_author(
252264
name=f'Note ({author.name})',
253265
icon_url=system_avatar_url,
@@ -301,7 +313,13 @@ def is_image_url(u, _):
301313

302314
if from_mod:
303315
em.color = self.bot.mod_color
304-
em.set_footer(text=self.bot.config.get('mod_tag', 'Moderator'))
316+
if anonymous and isinstance(destination, discord.TextChannel): # Anonymous reply sent in thread channel
317+
em.set_footer(text='Anonymous Reply')
318+
elif not anonymous:
319+
em.set_footer(text=self.bot.config.get('mod_tag', 'Moderator')) # Normal messages
320+
else:
321+
em.set_footer(text='\u200b') # Anonymous reply sent to user
322+
305323
elif note:
306324
em.color = discord.Color.blurple()
307325
else:

0 commit comments

Comments
 (0)