Skip to content

Commit

Permalink
Fixed compat with MissingRequiredArgument requiring additional param
Browse files Browse the repository at this point in the history
  • Loading branch information
Taaku18 committed Nov 20, 2023
1 parent 27a16fe commit 9464c5d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
7 changes: 4 additions & 3 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1746,9 +1746,10 @@ def format_channel_name(self, author, exclude_channel=None, force_null=False):
if force_null:
name = "null"

name = new_name = (
"".join(l for l in name if l not in string.punctuation and l.isprintable()) or "null"
) + f"-{author.discriminator}"
name = "".join(l for l in name if l not in string.punctuation and l.isprintable()) or "null"
if author.discriminator != "0":
name += f"-{author.discriminator}"
new_name = name

counter = 1
existed = set(c.name for c in guild.text_channels if c != exclude_channel)
Expand Down
7 changes: 3 additions & 4 deletions cogs/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from datetime import datetime, timezone
from itertools import zip_longest
from typing import Optional, Union, List, Tuple, Literal
from types import SimpleNamespace

import discord
from discord.ext import commands
Expand Down Expand Up @@ -1164,7 +1163,7 @@ async def logs(self, ctx, *, user: User = None):
if not user:
thread = ctx.thread
if not thread:
raise commands.MissingRequiredArgument(SimpleNamespace(name="member"))
raise commands.MissingRequiredArgument(DummyParam("user"))
user = thread.recipient or await self.bot.get_or_fetch_user(thread.id)

default_avatar = "https://cdn.discordapp.com/embed/avatars/0.png"
Expand Down Expand Up @@ -1839,7 +1838,7 @@ async def block(
if thread:
user_or_role = thread.recipient
elif after is None:
raise commands.MissingRequiredArgument(SimpleNamespace(name="user or role"))
raise commands.MissingRequiredArgument(DummyParam("user or role"))
else:
raise commands.BadArgument(f'User or role "{after.arg}" not found.')

Expand Down Expand Up @@ -1919,7 +1918,7 @@ async def unblock(self, ctx, *, user_or_role: Union[User, Role] = None):
if thread:
user_or_role = thread.recipient
else:
raise commands.MissingRequiredArgument(SimpleNamespace(name="user"))
raise commands.MissingRequiredArgument(DummyParam("user or role"))

mention = getattr(user_or_role, "mention", f"`{user_or_role.id}`")
name = getattr(user_or_role, "name", f"`{user_or_role.id}`")
Expand Down
9 changes: 4 additions & 5 deletions cogs/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from json import JSONDecodeError, loads
from subprocess import PIPE
from textwrap import indent
from types import SimpleNamespace
from typing import Union

import discord
Expand All @@ -30,7 +29,7 @@
UnseenFormatter,
getLogger,
)
from core.utils import trigger_typing, truncate
from core.utils import trigger_typing, truncate, DummyParam
from core.paginator import EmbedPaginatorSession, MessagePaginatorSession


Expand Down Expand Up @@ -522,12 +521,12 @@ async def activity(self, ctx, activity_type: str.lower, *, message: str = ""):
return await ctx.send(embed=embed)

if not message:
raise commands.MissingRequiredArgument(SimpleNamespace(name="message"))
raise commands.MissingRequiredArgument(DummyParam("message"))

try:
activity_type = ActivityType[activity_type]
except KeyError:
raise commands.MissingRequiredArgument(SimpleNamespace(name="activity"))
raise commands.MissingRequiredArgument(DummyParam("activity"))

activity, _ = await self.set_presence(activity_type=activity_type, activity_message=message)

Expand Down Expand Up @@ -572,7 +571,7 @@ async def status(self, ctx, *, status_type: str.lower):
try:
status = Status[status_type]
except KeyError:
raise commands.MissingRequiredArgument(SimpleNamespace(name="status"))
raise commands.MissingRequiredArgument(DummyParam("status"))

_, status = await self.set_presence(status=status)

Expand Down
5 changes: 3 additions & 2 deletions core/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
AcceptButton,
DenyButton,
ConfirmThreadCreationView,
DummyParam,
)

logger = getLogger(__name__)
Expand Down Expand Up @@ -800,7 +801,7 @@ async def note(
self, message: discord.Message, persistent=False, thread_creation=False
) -> discord.Message:
if not message.content and not message.attachments:
raise MissingRequiredArgument(SimpleNamespace(name="msg"))
raise MissingRequiredArgument(DummyParam("msg"))

msg = await self.send(
message,
Expand All @@ -821,7 +822,7 @@ async def reply(
) -> typing.Tuple[typing.List[discord.Message], discord.Message]:
"""Returns List[user_dm_msg] and thread_channel_msg"""
if not message.content and not message.attachments:
raise MissingRequiredArgument(SimpleNamespace(name="msg"))
raise MissingRequiredArgument(DummyParam("msg"))
if not any(g.get_member(self.id) for g in self.bot.guilds):
return await message.channel.send(
embed=discord.Embed(
Expand Down
10 changes: 10 additions & 0 deletions core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"AcceptButton",
"DenyButton",
"ConfirmThreadCreationView",
"DummyParam",
]


Expand Down Expand Up @@ -588,3 +589,12 @@ class ConfirmThreadCreationView(discord.ui.View):
def __init__(self):
super().__init__(timeout=20)
self.value = None


class DummyParam:
"""
A dummy parameter that can be used for MissingRequiredArgument.
"""
def __init__(self, name):
self.name = name
self.displayed_name = name

0 comments on commit 9464c5d

Please sign in to comment.