Add the flaky last_tilde plugin

This commit adds the aftermentioned to be flaky last_tilde_answer
command and the lte alias.
master
jmjl 2023-09-02 19:54:38 +00:00
parent 1d3622d0cb
commit 4f631e96fe
1 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,29 @@
#!/usr/bin/python3
import pinhook.plugin
import util.tilde
import inspect
def err(msg): return pinhook.plugin.message(msg)
@pinhook.plugin.command('&lte', 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):
data = inspect.getclosurevars(data).nonlocals
if len(data) == 0:
data = inspect.getsource(data)
if answer is None:
data = str(data)
answer = f"{pnick}'s last tilde's answer was supposed to be `{data}`."
return pinhook.plugin.message(answer)