Skip to content

Commit 987e36e

Browse files
committed
Unnotify, notify/sub with users, pylint
1 parent af65a09 commit 987e36e

File tree

6 files changed

+98
-55
lines changed

6 files changed

+98
-55
lines changed

.pylintrc

-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,6 @@ function-naming-style=snake_case
359359
# Good variable names which should always be accepted, separated by a comma.
360360
good-names=i,
361361
j,
362-
k,
363362
ex,
364363
_,
365364
id,

CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
# v2.20.1
99

10+
### What's new?
11+
12+
- New error message when using thread-only commands outside of threads.
13+
- `?unnotify`, ability to undo `?notify`.
14+
- `?notify` and `?subscribe` now accepts other users.
15+
1016
### Changes
1117

1218
This update contains mostly internal changes.
1319
- Implemented support for the new discord.py v1.1.1.
14-
- New error message when using thread-only commands outside of threads.
1520
- Improved help text for most commands.
1621
- Completely revamped help command, few user changes.
1722
- Removed abc (internal).

cogs/modmail.py

+70-31
Original file line numberDiff line numberDiff line change
@@ -266,26 +266,26 @@ async def close(self, ctx, *, after: UserFriendlyTime = None):
266266
@commands.command(aliases=['alert'])
267267
@checks.has_permissions(PermissionLevel.SUPPORTER)
268268
@checks.thread_only()
269-
async def notify(self, ctx, *, role: Union[discord.Role, str.lower, None] = None):
269+
async def notify(self, ctx, *, user_or_role: Union[discord.Role, User, str.lower, None] = None):
270270
"""
271-
Notify a role or yourself when the next thread message received.
271+
Notify a user, role, or yourself when the next thread message received.
272272
273-
Once a thread message is received, `role` will only be pinged once.
273+
Once a thread message is received, `user_or_role` will only be pinged once.
274274
275-
Leave `role` empty to notify yourself.
275+
Leave `user_or_role` empty to notify yourself.
276276
`@here` and `@everyone` can be substituted with `here` and `everyone`.
277-
`role` may be a role ID, mention, name, "everyone", or "here".
277+
`user_or_role` may be a user ID, mention, name. role ID, mention, name, "everyone", or "here".
278278
"""
279279
thread = ctx.thread
280280

281-
if role is None:
281+
if user_or_role is None:
282282
mention = ctx.author.mention
283-
elif isinstance(role, discord.Role):
284-
mention = role.mention
285-
elif role in {'here', 'everyone', '@here', '@everyone'}:
286-
mention = '@' + role.lstrip('@')
283+
elif hasattr(user_or_role, 'mention'):
284+
mention = user_or_role.mention
285+
elif user_or_role in {'here', 'everyone', '@here', '@everyone'}:
286+
mention = '@' + user_or_role.lstrip('@')
287287
else:
288-
raise commands.BadArgument(f'{role} is not a valid role.')
288+
raise commands.BadArgument(f'{user_or_role} is not a valid role.')
289289

290290
if str(thread.id) not in self.bot.config['notification_squad']:
291291
self.bot.config['notification_squad'][str(thread.id)] = []
@@ -304,29 +304,68 @@ async def notify(self, ctx, *, role: Union[discord.Role, str.lower, None] = None
304304
'on the next message received.')
305305
return await ctx.send(embed=embed)
306306

307+
@commands.command(aliases=['unalert'])
308+
@checks.has_permissions(PermissionLevel.SUPPORTER)
309+
@checks.thread_only()
310+
async def unnotify(self, ctx, *, user_or_role: Union[discord.Role, User, str.lower, None] = None):
311+
"""
312+
Un-notify a user, role, or yourself from a thread.
313+
314+
Leave `user_or_role` empty to un-notify yourself.
315+
`@here` and `@everyone` can be substituted with `here` and `everyone`.
316+
`user_or_role` may be a user ID, mention, name, role ID, mention, name, "everyone", or "here".
317+
"""
318+
thread = ctx.thread
319+
320+
if user_or_role is None:
321+
mention = ctx.author.mention
322+
elif hasattr(user_or_role, 'mention'):
323+
mention = user_or_role.mention
324+
elif user_or_role in {'here', 'everyone', '@here', '@everyone'}:
325+
mention = '@' + user_or_role.lstrip('@')
326+
else:
327+
mention = f'`{user_or_role}`'
328+
329+
if str(thread.id) not in self.bot.config['notification_squad']:
330+
self.bot.config['notification_squad'][str(thread.id)] = []
331+
332+
mentions = self.bot.config['notification_squad'][str(thread.id)]
333+
334+
if mention not in mentions:
335+
embed = discord.Embed(color=discord.Color.red(),
336+
description=f'{mention} does not have a '
337+
'pending notification.')
338+
else:
339+
mentions.remove(mention)
340+
await self.bot.config.update()
341+
embed = discord.Embed(color=self.bot.main_color,
342+
description=f'{mention} will no longer '
343+
'be notified.')
344+
return await ctx.send(embed=embed)
345+
307346
@commands.command(aliases=['sub'])
308347
@checks.has_permissions(PermissionLevel.SUPPORTER)
309348
@checks.thread_only()
310-
async def subscribe(self, ctx, *, role: Union[discord.Role, str.lower, None] = None):
349+
async def subscribe(self, ctx, *, user_or_role: Union[discord.Role, User, str.lower, None] = None):
311350
"""
312-
Notify a role or yourself for every thread message received.
351+
Notify a user, role, or yourself for every thread message received.
313352
314353
You will be pinged for every thread message received until you unsubscribe.
315354
316-
Leave `role` empty to subscribe yourself.
355+
Leave `user_or_role` empty to subscribe yourself.
317356
`@here` and `@everyone` can be substituted with `here` and `everyone`.
318-
`role` may be a role ID, mention, name, "everyone", or "here".
357+
`user_or_role` may be a user ID, mention, name, role ID, mention, name, "everyone", or "here".
319358
"""
320359
thread = ctx.thread
321360

322-
if role is None:
361+
if user_or_role is None:
323362
mention = ctx.author.mention
324-
elif isinstance(role, discord.Role):
325-
mention = role.mention
326-
elif role in {'here', 'everyone', '@here', '@everyone'}:
327-
mention = '@' + role.lstrip('@')
363+
elif hasattr(user_or_role, 'mention'):
364+
mention = user_or_role.mention
365+
elif user_or_role in {'here', 'everyone', '@here', '@everyone'}:
366+
mention = '@' + user_or_role.lstrip('@')
328367
else:
329-
raise commands.BadArgument(f'{role} is not a valid role.')
368+
raise commands.BadArgument(f'{user_or_role} is not a valid role.')
330369

331370
if str(thread.id) not in self.bot.config['subscriptions']:
332371
self.bot.config['subscriptions'][str(thread.id)] = []
@@ -350,24 +389,24 @@ async def subscribe(self, ctx, *, role: Union[discord.Role, str.lower, None] = N
350389
@commands.command(aliases=['unsub'])
351390
@checks.has_permissions(PermissionLevel.SUPPORTER)
352391
@checks.thread_only()
353-
async def unsubscribe(self, ctx, *, role=None):
392+
async def unsubscribe(self, ctx, *, user_or_role: Union[discord.Role, User, str.lower, None] = None):
354393
"""
355-
Unsubscribe a role or yourself from a thread.
394+
Unsubscribe a user, role, or yourself from a thread.
356395
357-
Leave `role` empty to unsubscribe yourself.
396+
Leave `user_or_role` empty to unsubscribe yourself.
358397
`@here` and `@everyone` can be substituted with `here` and `everyone`.
359-
`role` may be a role ID, mention, name, "everyone", or "here".
398+
`user_or_role` may be a user ID, mention, name, role ID, mention, name, "everyone", or "here".
360399
"""
361400
thread = ctx.thread
362401

363-
if not role:
402+
if user_or_role is None:
364403
mention = ctx.author.mention
365-
elif role.lower() in ('here', 'everyone'):
366-
mention = '@' + role
404+
elif hasattr(user_or_role, 'mention'):
405+
mention = user_or_role.mention
406+
elif user_or_role in {'here', 'everyone', '@here', '@everyone'}:
407+
mention = '@' + user_or_role.lstrip('@')
367408
else:
368-
converter = commands.RoleConverter()
369-
role = await converter.convert(ctx, role)
370-
mention = role.mention
409+
mention = f'`{user_or_role}`'
371410

372411
if str(thread.id) not in self.bot.config['subscriptions']:
373412
self.bot.config['subscriptions'][str(thread.id)] = []

cogs/utility.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ async def send_error_message(self, msg): # pylint: disable=W0221
148148

149149
choices = set()
150150

151-
for name, c in self.context.bot.all_commands.items():
152-
if not c.hidden:
151+
for name, cmd in self.context.bot.all_commands.items():
152+
if not cmd.hidden:
153153
choices.add(name)
154154
command = self.context.kwargs.get('command')
155155
# print(self.context.message.content[self.context.in])
@@ -789,8 +789,8 @@ async def config_get(self, ctx, key: str.lower = None):
789789
icon_url=self.bot.user.avatar_url)
790790

791791
config = {
792-
k: v for k, v in self.bot.config.cache.items()
793-
if v and k in keys
792+
key: val for key, val in self.bot.config.cache.items()
793+
if val and key in keys
794794
}
795795

796796
for k, v in reversed(list(config.items())):
@@ -1250,7 +1250,7 @@ def get_level(perm_level):
12501250

12511251
p_session = PaginatorSession(ctx, *embeds)
12521252
return await p_session.run()
1253-
1253+
12541254
@commands.group(invoke_without_command=True, aliases=['oauth2', 'auth', 'authentication'])
12551255
@checks.has_permissions(PermissionLevel.OWNER)
12561256
async def oauth(self, ctx):
@@ -1273,7 +1273,7 @@ async def oauth_whitelist(self, ctx, target: Union[User, Role]):
12731273
else:
12741274
whitelisted.append(target.id)
12751275
removed = False
1276-
1276+
12771277
await self.bot.config.update()
12781278

12791279
embed = Embed(color=self.bot.main_color)
@@ -1284,7 +1284,7 @@ async def oauth_whitelist(self, ctx, target: Union[User, Role]):
12841284
)
12851285

12861286
await ctx.send(embed=embed)
1287-
1287+
12881288
@oauth.command(name='show', aliases=['get', 'list', 'view'])
12891289
@checks.has_permissions(PermissionLevel.OWNER)
12901290
async def oauth_show(self, ctx):
@@ -1294,21 +1294,21 @@ async def oauth_show(self, ctx):
12941294
users = []
12951295
roles = []
12961296

1297-
for id in whitelisted:
1298-
user = self.bot.get_user(id)
1297+
for id_ in whitelisted:
1298+
user = self.bot.get_user(id_)
12991299
if user:
13001300
users.append(user)
1301-
role = self.bot.modmail_guild.get_role(id)
1301+
role = self.bot.modmail_guild.get_role(id_)
13021302
if role:
13031303
roles.append(role)
13041304

1305-
em = Embed(color=self.bot.main_color)
1306-
em.title = 'Oauth Whitelist'
1305+
embed = Embed(color=self.bot.main_color)
1306+
embed.title = 'Oauth Whitelist'
13071307

1308-
em.add_field(name='Users', value=' '.join(u.mention for u in users) or 'None')
1309-
em.add_field(name='Roles', value=' '.join(r.mention for r in roles) or 'None')
1308+
embed.add_field(name='Users', value=' '.join(u.mention for u in users) or 'None')
1309+
embed.add_field(name='Roles', value=' '.join(r.mention for r in roles) or 'None')
13101310

1311-
await ctx.send(embed=em)
1311+
await ctx.send(embed=embed)
13121312

13131313
@commands.command(hidden=True, name='eval')
13141314
@checks.has_permissions(PermissionLevel.OWNER)

core/config.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ async def clean_data(self, key: str,
147147
val = val[1:]
148148
if len(val) != 6:
149149
raise InvalidConfigError('Invalid color name or hex.')
150-
for v in val:
151-
if v not in {'0', '1', '2', '3', '4', '5', '6', '7',
152-
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}:
150+
for letter in val:
151+
if letter not in {'0', '1', '2', '3', '4', '5', '6', '7',
152+
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}:
153153
raise InvalidConfigError('Invalid color name or hex.')
154154
clean_value = '#' + val
155155
value_text = clean_value

core/utils.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,12 @@ def match_user_id(text: str) -> int:
195195

196196

197197
def get_perm_level(cmd) -> PermissionLevel:
198-
for c in cmd.checks:
199-
perm = getattr(c, 'permission_level', None)
198+
for check in cmd.checks:
199+
perm = getattr(check, 'permission_level', None)
200200
if perm is not None:
201201
return perm
202-
for c in cmd.checks:
203-
if 'is_owner' in str(c):
202+
for check in cmd.checks:
203+
if 'is_owner' in str(check):
204204
return PermissionLevel.OWNER
205205
return PermissionLevel.INVALID
206206

0 commit comments

Comments
 (0)