forked from uniborg/uniborg
headpat: rework style
This commit is contained in:
parent
dbf561880e
commit
b72ddba35e
|
@ -12,31 +12,30 @@ import urllib.request
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
pats = []
|
pats = []
|
||||||
user = None
|
oops = "OOPSIE WOOPSIE!! Uwu We madea fucky wucky!! A wittle fucko boingo! " \
|
||||||
oops = 'OOPSIE WOOPSIE!! Uwu We madea fucky wucky!! A wittle fucko boingo! '\
|
"The code monkeys at our headquarters are working VEWY HAWD to fix " \
|
||||||
'The code monkeys at our headquarters are working VEWY HAWD to fix this!'
|
"this!"
|
||||||
|
|
||||||
|
|
||||||
@borg.on(events.NewMessage)
|
@borg.on(events.NewMessage)
|
||||||
async def on_pat(event):
|
async def on_pat(event):
|
||||||
global user
|
user = borg.me.username
|
||||||
if user is None:
|
|
||||||
user = (await borg.get_me()).username or ''
|
|
||||||
|
|
||||||
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
|
return
|
||||||
|
|
||||||
global pats
|
global pats
|
||||||
if not pats:
|
if not pats:
|
||||||
try:
|
try:
|
||||||
pats = json.loads(urllib.request.urlopen(urllib.request.Request(
|
pats = json.loads(urllib.request.urlopen(urllib.request.Request(
|
||||||
'http://headp.at/js/pats.json',
|
"http://headp.at/js/pats.json",
|
||||||
headers={'User-Agent': 'Mozilla/5.0 (X11; U; Linux i686) '
|
headers={"User-Agent": "Mozilla/5.0 (X11; U; Linux i686) "
|
||||||
'Gecko/20071127 Firefox/2.0.0.11'}
|
"Gecko/20071127 Firefox/2.0.0.11"}
|
||||||
)).read().decode('utf-8'))
|
)).read().decode("utf-8"))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
await event.reply(oops)
|
await event.reply(oops)
|
||||||
return
|
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})")
|
||||||
|
|
Loading…
Reference in New Issue