Skip to content

Commit

Permalink
fix broken yelling exemptor (#162)
Browse files Browse the repository at this point in the history
* fix broken yelling exemptor

* black
  • Loading branch information
andrewj-brown authored Sep 4, 2023
1 parent f62c6c0 commit 8de4344
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ exclude = [
"**/working_on.py",
"**/utils/command_utils.py",
"**/utils/snailrace_utils.py",
]
]

8 changes: 8 additions & 0 deletions uqcsbot/cog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from discord.ext import commands

from uqcsbot.bot import UQCSBot


class UQCSBotCog(commands.Cog):
def __init__(self, bot: UQCSBot):
self.bot = bot
25 changes: 14 additions & 11 deletions uqcsbot/yelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from urllib.error import URLError

from uqcsbot.bot import UQCSBot
from uqcsbot.cog import UQCSBotCog
from uqcsbot.models import YellingBans

from datetime import timedelta
Expand All @@ -17,39 +18,41 @@ def yelling_exemptor(input_args: List[str] = ["text"]) -> Callable[..., Any]:
def handler(func: Callable[..., Any]):
@wraps(func)
async def wrapper(
cogself: commands.Cog, *args: List[Any], **kwargs: Dict[str, Any]
cogself: UQCSBotCog, *args: List[Any], **kwargs: Dict[str, Any]
):
bot = cogself.bot # type: ignore
bot = cogself.bot
interaction = None
text = "".join([str(kwargs.get(i, "") or "") for i in input_args])
if text == "":
await func(bot, *args, **kwargs)
await func(cogself, *args, **kwargs)
return
for a in args:
if isinstance(a, discord.interactions.Interaction):
interaction = a
break
if interaction is None:
await func(bot, *args, **kwargs)
await func(cogself, *args, **kwargs)
return
if not hasattr(interaction, "channel"):
await func(bot, *args, **kwargs)
await func(cogself, *args, **kwargs)
return
if interaction.channel is None:
await func(bot, *args, **kwargs)
await func(cogself, *args, **kwargs)
return
if interaction.channel.type != discord.ChannelType.text:
await func(bot, *args, **kwargs)
await func(cogself, *args, **kwargs)
return
if interaction.channel.name != "yelling":
await func(bot, *args, **kwargs)
await func(cogself, *args, **kwargs)
return
if not Yelling.contains_lowercase(text):
await func(bot, *args, **kwargs)
await func(cogself, *args, **kwargs)
return
await interaction.response.send_message(str(discord.utils.get(bot.emojis, name="disapproval") or "")) # type: ignore
await interaction.response.send_message(
str(discord.utils.get(bot.emojis, name="disapproval") or "")
)
if isinstance(interaction.user, discord.Member):
await Yelling.external_handle_bans(bot, interaction.user) # type: ignore
await Yelling.external_handle_bans(bot, interaction.user)

return wrapper

Expand Down

0 comments on commit 8de4344

Please sign in to comment.