Skip to content

Commit 1860faa

Browse files
committed
Add a blocked command and improve user interface
1 parent 158e459 commit 1860faa

File tree

1 file changed

+83
-12
lines changed

1 file changed

+83
-12
lines changed

bot.py

Lines changed: 83 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,9 @@ def help_embed(self, prefix):
171171
f'`{prefix}reply <message...>` - Sends a message to the current thread\'s recipient.\n' \
172172
f'`{prefix}close` - Closes the current thread and deletes the channel.\n' \
173173
f'`{prefix}archive` - Closes the current thread and moves the channel to archive category.\n' \
174-
f'`{prefix}block` - Blocks a user from using modmail\n' \
175-
f'`{prefix}unblock` - Unblocks a user from using modmail\n' \
174+
f'`{prefix}block` - Blocks a user from using modmail.\n' \
175+
f'`{prefix}blocked` - Shows a list of currently blocked users.\n' \
176+
f'`{prefix}unblock` - Unblocks a user from using modmail.\n' \
176177
f'`{prefix}snippets` - See a list of snippets that are currently configured.\n' \
177178
f'`{prefix}customstatus` - Sets the Bot status to whatever you want.\n' \
178179
f'`{prefix}disable` - Closes all threads and disables modmail for the server.\n'
@@ -317,7 +318,7 @@ async def archive(self, ctx):
317318
em = discord.Embed(title='Thread Closed')
318319
em.description = f'{ctx.author.mention} has closed this modmail session.'
319320
em.color = discord.Color.red()
320-
321+
321322
try:
322323
await user.send(embed=em)
323324
except:
@@ -546,12 +547,17 @@ async def reply(self, ctx, *, msg=''):
546547
await self.process_reply(ctx.message, user_id=user_id)
547548

548549
@commands.command()
550+
@commands.has_permissions(manage_channels=True)
549551
async def contact(self, ctx, *, user: discord.Member):
550552
'''Create a thread with a specified member.'''
551553
categ = discord.utils.get(ctx.guild.categories, id=ctx.channel.category_id)
552-
if categ is not None and categ.name == 'Mod Mail':
553-
channel = await self.create_thread(user, creator=ctx.author)
554-
await ctx.send(f'Created thread {channel.mention}')
554+
channel = await self.create_thread(user, creator=ctx.author)
555+
556+
em = discord.Embed(title='Created Thread')
557+
em.description = f'Thread started in {channel.mention} for {user.mention}'
558+
em.color = discord.Color.green()
559+
560+
await ctx.send(embed=em)
555561

556562
@commands.command(name="customstatus", aliases=['status', 'presence'])
557563
@commands.has_permissions(administrator=True)
@@ -560,8 +566,45 @@ async def _status(self, ctx, *, message):
560566
if message == 'clear':
561567
return await self.change_presence(activity=None)
562568
await self.change_presence(activity=discord.Game(message))
563-
await ctx.send(f"Changed status to **{message}**")
569+
em = discord.Embed(title='Status Changed')
570+
em.description = message
571+
em.color = discord.Color.green()
572+
em.set_footer(text='Note: this change is temporary.')
573+
await ctx.send(embed=em)
574+
575+
@commands.command()
576+
@commands.has_permissions(manage_channels=True)
577+
async def blocked(self, ctx):
578+
'''Returns a list of blocked users'''
579+
categ = discord.utils.get(ctx.guild.categories, name='Mod Mail')
580+
top_chan = categ.channels[0] #bot-info
581+
ids = re.findall(r'\d+', top_chan.topic)
582+
583+
em = discord.Embed(title='Blocked Users', color=discord.Color.green())
584+
em.description = ''
585+
586+
users = []
587+
not_reachable = []
588+
589+
for id in ids:
590+
user = self.get_user(int(id))
591+
if user:
592+
users.append(user)
593+
else:
594+
not_reachable.append(id)
595+
596+
em.description = 'Here is a list of blocked users.'
597+
598+
if users:
599+
em.add_field(name='Currently Known', value=' '.join(u.mention for u in users))
600+
if not_reachable:
601+
em.add_field(name='Unknown', value='\n'.join(f'`{i}`' for i in not_reachable), inline=False)
602+
603+
if not users and not not_reachable:
604+
em.description = 'Currently there are no blocked users'
564605

606+
await ctx.send(embed=em)
607+
565608
@commands.command()
566609
@commands.has_permissions(manage_channels=True)
567610
async def block(self, ctx, id=None):
@@ -577,11 +620,25 @@ async def block(self, ctx, id=None):
577620
topic = str(top_chan.topic)
578621
topic += '\n' + id
579622

623+
user = self.get_user(int(id))
624+
mention = user.mention if user else f'`{id}`'
625+
626+
em = discord.Embed()
627+
em.color = discord.Color.green()
628+
580629
if id not in top_chan.topic:
581630
await top_chan.edit(topic=topic)
582-
await ctx.send('User successfully blocked!')
631+
632+
em.title = 'Success'
633+
em.description = f'{mention} is now blocked'
634+
635+
await ctx.send(embed=em)
583636
else:
584-
await ctx.send('User is already blocked.')
637+
em.title = 'Error'
638+
em.description = f'{mention} is already blocked'
639+
em.color = discord.Color.red()
640+
641+
await ctx.send(embed=em)
585642

586643
@commands.command()
587644
@commands.has_permissions(manage_channels=True)
@@ -598,11 +655,25 @@ async def unblock(self, ctx, id=None):
598655
topic = str(top_chan.topic)
599656
topic = topic.replace('\n'+id, '')
600657

601-
if id in top_chan.topic:
658+
user = self.get_user(int(id))
659+
mention = user.mention if user else f'`{id}`'
660+
661+
em = discord.Embed()
662+
em.color = discord.Color.green()
663+
664+
if id in top_chan.topic:
602665
await top_chan.edit(topic=topic)
603-
await ctx.send('User successfully unblocked!')
666+
667+
em.title = 'Success'
668+
em.description = f'{mention} is no longer blocked'
669+
670+
await ctx.send(embed=em)
604671
else:
605-
await ctx.send('User is not already blocked.')
672+
em.title = 'Error'
673+
em.description = f'{mention} is not already blocked'
674+
em.color = discord.Color.red()
675+
676+
await ctx.send(embed=em)
606677

607678
@commands.command(hidden=True, name='eval')
608679
async def _eval(self, ctx, *, body: str):

0 commit comments

Comments
 (0)