Skip to content

Commit

Permalink
fix yelling types and remove arbitrary web request
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewj-brown committed Nov 8, 2023
1 parent c304268 commit 58262ad
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions uqcsbot/yelling.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import discord
from typing import List, Dict, Callable, Any
from typing import List, Dict, Callable, Any, Generic
from discord.ext import commands
from discord._types import ClientT
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 All @@ -13,6 +12,8 @@
from datetime import timedelta
from functools import wraps

class DodgyType(discord.interactions.Interaction[ClientT]):
pass

def yelling_exemptor(input_args: List[str] = ["text"]) -> Callable[..., Any]:
def handler(func: Callable[..., Any]):
Expand All @@ -27,7 +28,7 @@ async def wrapper(
await func(cogself, *args, **kwargs)
return
for a in args:
if isinstance(a, discord.interactions.Interaction):
if isinstance(a, DodgyType):
interaction = a
break
if interaction is None:
Expand Down Expand Up @@ -167,12 +168,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

0 comments on commit 58262ad

Please sign in to comment.