diff --git a/build_carddb_keyforge.py b/build_carddb_keyforge.py index ca6a66dc..80332a32 100755 --- a/build_carddb_keyforge.py +++ b/build_carddb_keyforge.py @@ -91,7 +91,7 @@ def main(): processed_cards.add(filteredname) conn.commit() -re_429_detail = re.compile("This endpoint is currently disabled due to too many requests\\. Please, try again in (\d+) seconds\\.") +re_429_detail = re.compile(r"This endpoint is currently disabled due to too many requests\. Please, try again in (\d+) seconds\.") def getpage(page): fn = f"{CACHE_DIR}/{page}.json" if os.path.exists(fn): diff --git a/common/time.py b/common/time.py index 8f7e8da7..a9c6444d 100644 --- a/common/time.py +++ b/common/time.py @@ -44,8 +44,8 @@ def get_timezone(tz): else: raise -re_timefmt1 = re.compile("^\s*(?:\s*(\d*)\s*d)?(?:\s*(\d*)\s*h)?(?:\s*(\d*)\s*m)?(?:\s*(\d*)\s*s?)?\s*$") -re_timefmt2 = re.compile("^(?:(?:(?:\s*(\d*)\s*:)?\s*(\d*)\s*:)?\s*(\d*)\s*:)?\s*(\d*)\s*$") +re_timefmt1 = re.compile(r"^\s*(?:\s*(\d*)\s*d)?(?:\s*(\d*)\s*h)?(?:\s*(\d*)\s*m)?(?:\s*(\d*)\s*s?)?\s*$") +re_timefmt2 = re.compile(r"^(?:(?:(?:\s*(\d*)\s*:)?\s*(\d*)\s*:)?\s*(\d*)\s*:)?\s*(\d*)\s*$") def parsetime(s): """ Parse user-supplied times in one of two formats: diff --git a/common/url.py b/common/url.py index 507deae5..e173da8f 100644 --- a/common/url.py +++ b/common/url.py @@ -47,8 +47,8 @@ async def url_regex(): # For example: if 'co' is before 'com', 'example.com/path' is matched as 'example.co'. tlds = sorted((await get_tlds()), key=lambda e: len(e), reverse=True) re_tld = "(?:" + "|".join(map(re.escape, tlds)) + ")" - re_hostname = "(?:(?:(?:[\w-]+\.)+" + re_tld + "\.?)|(?:\d{,3}(?:\.\d{,3}){3})|(?:\[[0-9a-fA-F:.]+\]))" - re_url = "((?:https?://)?" + re_hostname + "(?::\d+)?(?:/[\x5E\s\u200b]*)?)" + re_hostname = r"(?:(?:(?:[\w-]+\.)+%s\.?)|(?:\d{,3}(?:\.\d{,3}){3})|(?:\[[0-9a-fA-F:.]+\]))" % re_tld + re_url = r"((?:https?://)?%s(?::\d+)?(?:/[\x5E\s\u200b]*)?)" % re_hostname re_url = re_url + "|" + "|".join(map(lambda parens: re.escape(parens[0]) + re_url + re.escape(parens[1]), parens)) return re.compile(re_url, re.IGNORECASE) diff --git a/lrrbot/chatlog.py b/lrrbot/chatlog.py index 9b71fd5b..45bb7e77 100644 --- a/lrrbot/chatlog.py +++ b/lrrbot/chatlog.py @@ -307,7 +307,7 @@ async def get_display_name(nick): except Exception: return nick -re_just_words = re.compile("^\w+$") +re_just_words = re.compile(r"^\w+$") @utils.cache(CACHE_EXPIRY) async def get_twitch_emotes(): """ diff --git a/lrrbot/commands/card.py b/lrrbot/commands/card.py index ff4326c3..1af5192a 100644 --- a/lrrbot/commands/card.py +++ b/lrrbot/commands/card.py @@ -8,7 +8,7 @@ blueprint = Blueprint() -@blueprint.command("cardview (yt )?(on|off)") +@blueprint.command(r"cardview (yt )?(on|off)") @lrrbot.decorators.mod_only def set_cardview(bot, conn, event, respond_to, youtube, setting): """ @@ -26,7 +26,7 @@ def set_cardview(bot, conn, event, respond_to, youtube, setting): conn.privmsg(respond_to, "Card viewer %s" % ("enabled" if bot.cardview else "disabled")) -@blueprint.command("(?:card|mtg) (.+)") +@blueprint.command(r"(?:card|mtg) (.+)") @lrrbot.decorators.throttle(60, count=3) def mtg_card_lookup(bot, conn, event, respond_to, search): """ @@ -38,7 +38,7 @@ def mtg_card_lookup(bot, conn, event, respond_to, search): """ real_card_lookup(bot, conn, event, respond_to, search, game=CARD_GAME_MTG) -@blueprint.command("(?:kf|keyforge) (.+)") +@blueprint.command(r"(?:kf|keyforge) (.+)") @lrrbot.decorators.throttle(60, count=3) def keyforge_card_lookup(lrrbot, conn, event, respond_to, search): """ @@ -50,7 +50,7 @@ def keyforge_card_lookup(lrrbot, conn, event, respond_to, search): """ real_card_lookup(lrrbot, conn, event, respond_to, search, game=CARD_GAME_KEYFORGE) -@blueprint.command("(?:pok[eé]mon|pok[eé]|pkmn|ptcg) (.+)") +@blueprint.command(r"(?:pok[eé]mon|pok[eé]|pkmn|ptcg) (.+)") @lrrbot.decorators.throttle(60, count=3) def pokemon_card_lookup(lrrbot, conn, event, respond_to, search): """ @@ -62,7 +62,7 @@ def pokemon_card_lookup(lrrbot, conn, event, respond_to, search): """ real_card_lookup(lrrbot, conn, event, respond_to, search, game=CARD_GAME_PTCG) -@blueprint.command("(?:lorcana) (.+)") +@blueprint.command(r"(?:lorcana) (.+)") @lrrbot.decorators.throttle(60, count=3) def lorcana_card_lookup(bot, conn, event, respond_to, search): """ diff --git a/lrrbot/commands/game.py b/lrrbot/commands/game.py index ed9ef7d4..585312b3 100644 --- a/lrrbot/commands/game.py +++ b/lrrbot/commands/game.py @@ -7,7 +7,7 @@ blueprint = Blueprint() -@blueprint.command("game") +@blueprint.command(r"game") @lrrbot.decorators.throttle() async def current_game(bot, conn, event, respond_to): """ @@ -39,7 +39,7 @@ async def current_game(bot, conn, event, respond_to): " (overridden)" if bot.game_override is not None else "" )) -@blueprint.command("game display (.*?)") +@blueprint.command(r"game display (.*?)") @lrrbot.decorators.mod_only async def set_game_name(bot, conn, event, respond_to, name): """ @@ -78,7 +78,7 @@ async def set_game_name(bot, conn, event, respond_to, name): conn.privmsg(respond_to, "OK, I'll start calling %s \"%s\"" % (real_name, name)) -@blueprint.command("game override (.*?)") +@blueprint.command(r"game override (.*?)") @lrrbot.decorators.mod_only async def override_game(bot, conn, event, respond_to, game): """ @@ -123,7 +123,7 @@ async def override_game(bot, conn, event, respond_to, game): message += "Currently playing: %s" % name conn.privmsg(respond_to, message) -@blueprint.command("game refresh") +@blueprint.command(r"game refresh") @lrrbot.decorators.mod_only async def refresh(bot, conn, event, respond_to): """ diff --git a/lrrbot/commands/live.py b/lrrbot/commands/live.py index adbdfbdb..18176516 100644 --- a/lrrbot/commands/live.py +++ b/lrrbot/commands/live.py @@ -5,7 +5,7 @@ blueprint = Blueprint() -@blueprint.command("live") +@blueprint.command(r"live") @lrrbot.decorators.throttle() @lrrbot.decorators.private_reply_when_live async def live(bot, conn, event, respond_to): @@ -55,7 +55,7 @@ async def live(bot, conn, event, respond_to): ]) return conn.privmsg(respond_to, utils.trim_length(message)) -@blueprint.command("live register") +@blueprint.command(r"live register") async def register_self(bot, conn, event, respond_to): """ Command: !live register @@ -64,7 +64,7 @@ async def register_self(bot, conn, event, respond_to): """ conn.privmsg(respond_to, "Currently the fanlist cannot be edited. Contact mrphlip if you want to be added.") -@blueprint.command("live unregister") +@blueprint.command(r"live unregister") async def unregister_self(bot, conn, event, respond_to): """ Command: !live unregister @@ -73,7 +73,7 @@ async def unregister_self(bot, conn, event, respond_to): """ conn.privmsg(respond_to, "Currently the fanlist cannot be edited. Contact mrphlip if you want to be removed.") -@blueprint.command("live register (.*)") +@blueprint.command(r"live register (.*)") @lrrbot.decorators.mod_only async def register(bot, conn, event, respond_to, channel): """ @@ -83,7 +83,7 @@ async def register(bot, conn, event, respond_to, channel): """ conn.privmsg(respond_to, "Currently the fanlist cannot be edited.") -@blueprint.command("live unregister (.*)") +@blueprint.command(r"live unregister (.*)") @lrrbot.decorators.mod_only async def unregister(bot, conn, event, respond_to, channel): """ diff --git a/lrrbot/commands/lockdown.py b/lrrbot/commands/lockdown.py index b0fea21a..8e106e1a 100644 --- a/lrrbot/commands/lockdown.py +++ b/lrrbot/commands/lockdown.py @@ -3,7 +3,7 @@ blueprint = Blueprint() -@blueprint.command("(mod|sub)only") +@blueprint.command(r"(mod|sub)only") @lrrbot.decorators.mod_only def mod_only(bot, conn, event, respond_to, level): """ @@ -16,7 +16,7 @@ def mod_only(bot, conn, event, respond_to, level): bot.access = level conn.privmsg(respond_to, "Commands from non-%ss are now ignored." % level) -@blueprint.command("(?:mod|sub)only off") +@blueprint.command(r"(?:mod|sub)only off") @lrrbot.decorators.mod_only def mod_only_off(bot, conn, event, respond_to): """ diff --git a/lrrbot/commands/misc.py b/lrrbot/commands/misc.py index 010da469..b7344dce 100644 --- a/lrrbot/commands/misc.py +++ b/lrrbot/commands/misc.py @@ -24,12 +24,12 @@ blueprint = Blueprint() log = logging.getLogger('misc') -@blueprint.command("test") +@blueprint.command(r"test") @lrrbot.decorators.mod_only def test(bot, conn, event, respond_to): conn.privmsg(respond_to, "Test") -@blueprint.command("storm(?:counts?)?") +@blueprint.command(r"storm(?:counts?)?") @lrrbot.decorators.throttle() def stormcount(bot, conn, event, respond_to): """ @@ -62,7 +62,7 @@ def stormcount(bot, conn, event, respond_to): youtube_super_sticker, )) -@blueprint.command("spam(?:count)?") +@blueprint.command(r"spam(?:count)?") @lrrbot.decorators.throttle() def spamcount(bot, conn, event, respond_to): """ @@ -87,7 +87,7 @@ def spamcount(bot, conn, event, respond_to): # When !desertbus should stop claiming the run is still active DESERTBUS_END = DESERTBUS_START + datetime.timedelta(days=6) # Six days of plugs should be long enough -@blueprint.command("next( .*)?") +@blueprint.command(r"next( .*)?") @lrrbot.decorators.throttle() async def next(bot, conn, event, respond_to, timezone): """ @@ -107,7 +107,7 @@ async def next(bot, conn, event, respond_to, timezone): else: conn.privmsg(respond_to, message) -@blueprint.command("(?:db ?count(?: |-)?down|db ?next|next ?db)( .*)?") +@blueprint.command(r"(?:db ?count(?: |-)?down|db ?next|next ?db)( .*)?") @lrrbot.decorators.throttle() def desertbus(bot, conn, event, respond_to, timezone): """ @@ -138,7 +138,7 @@ def desertbus(bot, conn, event, respond_to, timezone): else: conn.privmsg(respond_to, "Desert Bus for Hope will return next year, start saving your donation money now!") -@blueprint.command("nextfan( .*)?") +@blueprint.command(r"nextfan( .*)?") @lrrbot.decorators.throttle() @lrrbot.decorators.private_reply_when_live async def nextfan(bot, conn, event, respond_to, timezone): @@ -151,7 +151,7 @@ async def nextfan(bot, conn, event, respond_to, timezone): message, _ = await googlecalendar.get_next_event_text(googlecalendar.CALENDAR_FAN, tz=timezone, include_current=True) conn.privmsg(respond_to, message) -@blueprint.command("time") +@blueprint.command(r"time") @lrrbot.decorators.throttle() def time(bot, conn, event, respond_to): """ @@ -163,7 +163,7 @@ def time(bot, conn, event, respond_to): now = datetime.datetime.now(config["timezone"]) conn.privmsg(respond_to, "Current moonbase time: %s" % now.strftime("%l:%M %p")) -@blueprint.command("time 24") +@blueprint.command(r"time 24") @lrrbot.decorators.throttle() def time24(bot, conn, event, respond_to): """ @@ -175,7 +175,7 @@ def time24(bot, conn, event, respond_to): now = datetime.datetime.now(config["timezone"]) conn.privmsg(respond_to, "Current moonbase time: %s" % now.strftime("%H:%M")) -@blueprint.command("viewers") +@blueprint.command(r"viewers") @lrrbot.decorators.throttle() async def viewers(bot, conn, event, respond_to): """ @@ -220,7 +220,7 @@ async def uptime_msg(stream_info=None, factor=1): else: return "The stream is not live." -@blueprint.command("uptime") +@blueprint.command(r"uptime") @lrrbot.decorators.throttle() async def uptime(bot, conn, event, respond_to): """ @@ -231,7 +231,7 @@ async def uptime(bot, conn, event, respond_to): """ conn.privmsg(respond_to, await uptime_msg()) -@blueprint.command("updog") +@blueprint.command(r"updog") @lrrbot.decorators.throttle() async def updog(bot, conn, event, respond_to): # intentionally not in help @@ -284,7 +284,7 @@ async def get_status_msg(bot): async def send_status(bot, conn, target): conn.privmsg(target, await get_status_msg(bot)) -@blueprint.command("status") +@blueprint.command(r"status") async def status(bot, conn, event, respond_to): """ Command: !status @@ -297,7 +297,7 @@ async def status(bot, conn, event, respond_to): source = irc.client.NickMask(event.source) await send_status(bot, conn, source.nick) -@blueprint.command("auto(?: |-)?status") +@blueprint.command(r"auto(?: |-)?status") def autostatus_check(bot, conn, event, respond_to): """ Command: !autostatus @@ -318,7 +318,7 @@ def autostatus_check(bot, conn, event, respond_to): else: conn.privmsg(source.nick, "Auto-status is disabled. Enable it with: !autostatus on") -@blueprint.command("auto(?: |-)?status (on|off)") +@blueprint.command(r"auto(?: |-)?status (on|off)") def autostatus_set(bot, conn, event, respond_to, enable): """ Command: !autostatus on diff --git a/lrrbot/commands/quote.py b/lrrbot/commands/quote.py index ae7cf59e..01bacc03 100644 --- a/lrrbot/commands/quote.py +++ b/lrrbot/commands/quote.py @@ -40,7 +40,7 @@ def format_quote(tag, qid, quote, name, date, context): quote_msg += " [{date!s}]".format(date=date) return quote_msg -@blueprint.command("quote(?: (?:(game|show) (.+)|(?:(\d+)|(.+))))?") +@blueprint.command(r"quote(?: (?:(game|show) (.+)|(?:(\d+)|(.+))))?") @lrrbot.decorators.sub_only @lrrbot.decorators.throttle(60, count=2) def quote(bot, conn, event, respond_to, meta_param, meta_value, qid, attrib): @@ -84,7 +84,7 @@ def quote(bot, conn, event, respond_to, meta_param, meta_value, qid, attrib): qid, quote, name, date, context = row conn.privmsg(respond_to, format_quote("Quote", qid, quote, name, date, context)) -@blueprint.command("addquote(?: \((.+?)\))?(?: \[(.+?)\])? ([^\|]+?)(?: ?\| ?([^\|]*))?") +@blueprint.command(r"addquote(?: \((.+?)\))?(?: \[(.+?)\])? ([^\|]+?)(?: ?\| ?([^\|]*))?") @lrrbot.decorators.mod_only async def addquote(bot, conn, event, respond_to, name, date, quote, context): """ @@ -118,7 +118,7 @@ async def addquote(bot, conn, event, respond_to, name, date, quote, context): conn.privmsg(respond_to, format_quote("New quote", qid, quote, name, date, context)) -@blueprint.command("modquote (\d+)(?: \((.+?)\))?(?: \[(.+?)\])? ([^\|]+?)(?: ?\| ?([^\|]*))?") +@blueprint.command(r"modquote (\d+)(?: \((.+?)\))?(?: \[(.+?)\])? ([^\|]+?)(?: ?\| ?([^\|]*))?") @lrrbot.decorators.mod_only def modquote(bot, conn, event, respond_to, qid, name, date, quote, context): """ @@ -151,7 +151,7 @@ def modquote(bot, conn, event, respond_to, qid, name, date, quote, context): else: conn.privmsg(respond_to, "Could not modify quote.") -@blueprint.command("delquote (\d+)") +@blueprint.command(r"delquote (\d+)") @lrrbot.decorators.mod_only def delquote(bot, conn, event, respond_to, qid): """ @@ -170,7 +170,7 @@ def delquote(bot, conn, event, respond_to, qid): else: conn.privmsg(respond_to, "Could not find quote #{qid}.".format(qid=qid)) -@blueprint.command("findquote (.*)") +@blueprint.command(r"findquote (.*)") @lrrbot.decorators.sub_only @lrrbot.decorators.throttle(60, count=2) def findquote(bot, conn, event, respond_to, query): diff --git a/lrrbot/commands/show.py b/lrrbot/commands/show.py index c620a0e9..d5365f9f 100644 --- a/lrrbot/commands/show.py +++ b/lrrbot/commands/show.py @@ -9,7 +9,7 @@ def set_show(bot, show): bot.set_show(show.lower()) bot.get_game_id.reset_throttle() -@blueprint.command("show") +@blueprint.command(r"show") @lrrbot.decorators.throttle() def get_show(bot, conn, event, respond_to): """ @@ -32,7 +32,7 @@ def print_show(bot, conn, respond_to): conn.privmsg(respond_to, "Currently live: %s%s" % (name, " (overriden)" if bot.show_override is not None else "")) -@blueprint.command("show override (.*?)") +@blueprint.command(r"show override (.*?)") @lrrbot.decorators.mod_only def show_override(bot, conn, event, respond_to, show): """ diff --git a/www/spam.py b/www/spam.py index e25b5c42..33fc163b 100644 --- a/www/spam.py +++ b/www/spam.py @@ -110,8 +110,8 @@ async def test(session): check = do_check_links if link_spam else do_check - re_twitchchat = re.compile("^\w*:\s*(.*)$") - re_irc = re.compile("<[^<>]*>\s*(.*)$") + re_twitchchat = re.compile(r"^\w*:\s*(.*)$") + re_irc = re.compile(r"<[^<>]*>\s*(.*)$") lines = message.split('\n') for line in lines: res = await check(line, rules)