juju/plugins/lasttilde.py

31 lines
1.3 KiB
Python
Raw Permalink Normal View History

#!/usr/bin/python3
import pinhook.plugin
import util.tilde
import inspect
def err(msg): return pinhook.plugin.message(msg)
@pinhook.plugin.command('&lta', help_text='Alias -- &last_tilde_answer')
@pinhook.plugin.command('&last_tilde_answer', help_text='See the last_tilde\'s answer', ops=False, ops_msg='This command is admin-only as it\'s flaky, and a bit broken.')
def last_tilde(msg):
nick = msg.nick
pnick = msg.nick
if nick not in msg.ops:
retmsg = None
if not msg.arg: return err("This command is a bit flaky, if you accept that run this command again with a parameter called flaky, so run `&last_tilde flaky`")
if msg.arg and msg.arg != 'flaky': return err("This command maybe won't return what you expect, if you want to run it anyways pass a argument called `flaky`")
elif msg.arg: nick = msg.arg.split(' ')[0]
answer = None
try: data = util.tilde.old_challenges[nick][0]
except KeyError: return err("User hasn't played &tilde from the last boot.")
if callable(data):
datax = inspect.getclosurevars(data).nonlocals
if len(datax) == 0:
data = ' '.join(inspect.getsource(data).rsplit())
else: data = datax
if answer is None:
data = str(data)
answer = f"{nick}'s last tilde's answer was supposed to be `{data}`."
return pinhook.plugin.message(answer)