Skip to content

Commit

Permalink
use silent as typing literal, resolve modmail-dev#3179
Browse files Browse the repository at this point in the history
  • Loading branch information
fourjr authored Sep 10, 2022
1 parent 73a3605 commit f6395aa
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions cogs/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
from datetime import datetime
from itertools import zip_longest
from typing import Optional, Union
from typing import Optional, Union, List, Tuple, Literal
from types import SimpleNamespace

import discord
Expand Down Expand Up @@ -1344,9 +1344,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 @@ -1360,16 +1360,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 f6395aa

Please sign in to comment.