Skip to content

Commit

Permalink
use silent as typing literal, resolve #3179
Browse files Browse the repository at this point in the history
  • Loading branch information
fourjr committed Sep 6, 2022
1 parent 3ea3cf2 commit ecffec2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ however, insignificant breaking changes do not guarantee a major version bump, s
- Improved error handling for autoupdate. ([PR #3161](https://github.com/kyb3r/modmail/pull/3161))
- Skip loading of already-loaded cog. ([PR #3172](https://github.com/kyb3r/modmail/pull/3172))
- Respect plugin's `cog_command_error`. ([GH #3170](https://github.com/kyb3r/modmail/issues/3170), [PR #3178](https://github.com/kyb3r/modmail/pull/3178))
- Use silent as a typing literal for contacting. ([GH #3179](https://github.com/kyb3r/modmail/issues/3179))

### Internal

Expand Down
26 changes: 16 additions & 10 deletions cogs/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from datetime import datetime, timezone
from itertools import zip_longest
import time
from typing import Optional, Union, List, Tuple
from typing import Optional, Union, List, Tuple, Literal
from types import SimpleNamespace

import discord
Expand Down Expand Up @@ -1500,9 +1500,9 @@ async def selfcontact(self, ctx):
async def contact(
self,
ctx,
users: commands.Greedy[Union[discord.Member, discord.User, discord.Role]],
users: commands.Greedy[Union[Literal["silent", "silently"], discord.Member, discord.User, discord.Role]],
*,
category: Union[SimilarCategoryConverter, str] = None,
category: SimilarCategoryConverter = None,
manual_trigger=True,
):
"""
Expand All @@ -1516,16 +1516,22 @@ async def contact(
A maximum of 5 users are allowed.
`options` can be `silent` or `silently`.
"""
silent = False
silent = any(x in users for x in ("silent", "silently"))
if silent:
try:
users.remove("silent")
except ValueError:
pass

try:
users.remove("silently")
except ValueError:
pass

print(users, silent)
if isinstance(category, str):
category = category.split()

# just check the last element in the list
if category[-1].lower() in ("silent", "silently"):
silent = True
# remove the last element as we no longer need it
category.pop()

category = " ".join(category)
if category:
try:
Expand Down

0 comments on commit ecffec2

Please sign in to comment.