From b72ddba35e584734a651bc1aac5f2a05ea09d323 Mon Sep 17 00:00:00 2001 From: Dan Elkouby Date: Sun, 13 May 2018 13:33:40 +0300 Subject: [PATCH] headpat: rework style --- stdplugins/headpat.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/stdplugins/headpat.py b/stdplugins/headpat.py index 56f7144..2c3e248 100644 --- a/stdplugins/headpat.py +++ b/stdplugins/headpat.py @@ -12,31 +12,30 @@ import urllib.request import urllib.parse pats = [] -user = None -oops = 'OOPSIE WOOPSIE!! Uwu We madea fucky wucky!! A wittle fucko boingo! '\ - 'The code monkeys at our headquarters are working VEWY HAWD to fix this!' +oops = "OOPSIE WOOPSIE!! Uwu We madea fucky wucky!! A wittle fucko boingo! " \ + "The code monkeys at our headquarters are working VEWY HAWD to fix " \ + "this!" @borg.on(events.NewMessage) async def on_pat(event): - global user - if user is None: - user = (await borg.get_me()).username or '' + user = borg.me.username - if not user or not re.match(fr'(?i)/headpat@{user}', event.raw_text): + if not user or not re.match(fr"(?i)/headpat@{user}", event.raw_text): return global pats if not pats: try: pats = json.loads(urllib.request.urlopen(urllib.request.Request( - 'http://headp.at/js/pats.json', - headers={'User-Agent': 'Mozilla/5.0 (X11; U; Linux i686) ' - 'Gecko/20071127 Firefox/2.0.0.11'} - )).read().decode('utf-8')) + "http://headp.at/js/pats.json", + headers={"User-Agent": "Mozilla/5.0 (X11; U; Linux i686) " + "Gecko/20071127 Firefox/2.0.0.11"} + )).read().decode("utf-8")) except Exception as e: print(e) await event.reply(oops) return - await event.reply(f'[Pat!](https://headp.at/pats/{urllib.parse.quote(random.choice(pats))})') + choice = urllib.parse.quote(random.choice(pats)) + await event.reply(f"[Pat!](https://headp.at/pats/{choice})")