Skip to content

Commit 5f52895

Browse files
committed
Improve block command and setup command
1 parent a0f4d21 commit 5f52895

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
# v2.0.1
8+
9+
### Changed
10+
- Improved block/unblock commands.
11+
- They now take a wider range of arguments: Usernames, nicknames, mentions and user IDs.
12+
13+
### Fixed
14+
- Setup command now configures permissions correctly so that the bot will always be able to see the main operations category.
15+
716
# v2.0.0
817

918
This release introduces the use of our centralized [API service](https://github.com/kyb3r/webserver) to enable dynamic configuration, auto-updates, and thread logs. To use this release you must acquire an API token from https://modmail.tk. Read the updated installation guide [here](https://github.com/kyb3r/modmail/wiki/installation).

cogs/modmail.py

+16-14
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ async def contact(self, ctx, *, user: Union[discord.Member, discord.User]):
287287

288288
await ctx.send(embed=em)
289289

290+
def obj(arg):
291+
return discord.Object(int(arg))
292+
290293
@commands.command()
291294
@trigger_typing
292295
@commands.has_permissions(manage_channels=True)
@@ -319,28 +322,27 @@ async def blocked(self, ctx):
319322
@commands.command()
320323
@trigger_typing
321324
@commands.has_permissions(manage_channels=True)
322-
async def block(self, ctx, id=None):
325+
async def block(self, ctx, *, user: Union[discord.Member, discord.User, obj]=None):
323326
"""Block a user from using modmail."""
324327

325-
if id is None:
328+
if user is None:
326329
thread = await self.bot.threads.find(channel=ctx.channel)
327330
if thread:
328-
id = str(thread.recipient.id)
331+
user = thread.recipient
329332
else:
330333
raise commands.UserInputError
331334

332335
categ = self.bot.main_category
333336
top_chan = categ.channels[0] # bot-info
334337
topic = str(top_chan.topic)
335-
topic += '\n' + id
338+
topic += '\n' + str(user.id)
336339

337-
user = self.bot.get_user(int(id))
338-
mention = user.mention if user else f'`{id}`'
340+
mention = user.mention if hasattr(user, 'mention') else f'`{user.id}`'
339341

340342
em = discord.Embed()
341343
em.color = discord.Color.green()
342344

343-
if id not in top_chan.topic:
345+
if str(user.id) not in top_chan.topic:
344346
await top_chan.edit(topic=topic)
345347

346348
em.title = 'Success'
@@ -357,27 +359,27 @@ async def block(self, ctx, id=None):
357359
@commands.command()
358360
@trigger_typing
359361
@commands.has_permissions(manage_channels=True)
360-
async def unblock(self, ctx, id=None):
362+
async def unblock(self, ctx, *, user: Union[discord.Member, discord.User, obj]=None):
361363
"""Unblocks a user from using modmail."""
362-
if id is None:
364+
365+
if user is None:
363366
thread = await self.bot.threads.find(channel=ctx.channel)
364367
if thread:
365-
id = str(thread.recipient.id)
368+
user = thread.recipient
366369
else:
367370
raise commands.UserInputError
368371

369372
categ = self.bot.main_category
370373
top_chan = categ.channels[0] # thread-logs
371374
topic = str(top_chan.topic)
372-
topic = topic.replace('\n' + id, '')
375+
topic = topic.replace('\n' + str(user.id), '')
373376

374-
user = self.bot.get_user(int(id))
375-
mention = user.mention if user else f'`{id}`'
377+
mention = user.mention if hasattr(user, 'mention') else f'`{user.id}`'
376378

377379
em = discord.Embed()
378380
em.color = discord.Color.green()
379381

380-
if id in top_chan.topic:
382+
if str(user.id) in top_chan.topic:
381383
await top_chan.edit(topic=topic)
382384

383385
em.title = 'Success'

0 commit comments

Comments
 (0)