Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix yelling types and remove arbitrary web request #177

Merged
merged 5 commits into from
Nov 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions uqcsbot/yelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from discord.ext import commands
from random import choice, random
import re
from urllib.request import urlopen
from urllib.error import URLError

from uqcsbot.bot import UQCSBot
from uqcsbot.cog import UQCSBotCog
Expand Down Expand Up @@ -48,7 +46,8 @@ async def wrapper(
if not Yelling.contains_lowercase(text):
await func(cogself, *args, **kwargs)
return
await interaction.response.send_message(

await interaction.response.send_message( # type: ignore
str(discord.utils.get(bot.emojis, name="disapproval") or "")
)
if isinstance(interaction.user, discord.Member):
Expand Down Expand Up @@ -167,12 +166,6 @@ def clean_text(self, message: str) -> str:

# slightly more permissive version of discord's url regex, matches absolutely anything between http(s):// and whitespace
for url in re.findall(r"https?:\/\/[^\s]+", text, flags=re.UNICODE):
try:
resp = urlopen(url)
except (ValueError, URLError):
continue
if 400 <= resp.code <= 499:
continue
text = text.replace(url, url.upper())

text = text.replace("&gt;", ">").replace("&lt;", "<").replace("&amp;", "&")
Expand Down