made slap use the new TextGenerator class

This commit is contained in:
Luke Rogers 2013-09-12 22:46:43 +12:00
parent 15e7825125
commit 2be0c46b89
6 changed files with 93 additions and 75 deletions

32
plugins/slap.py Normal file
View file

@ -0,0 +1,32 @@
from util import hook, text, textgen
import json, os
def get_generator(_json, variables):
data = json.loads(_json)
return textgen.TextGenerator(data["templates"],
data["parts"], variables=variables)
@hook.command
def slap(inp, me=None, nick=None, conn=None, notice=None):
"""slap <user> -- Makes the bot slap <user>."""
target = inp.strip()
if " " in target:
notice("Invalid username!")
return
# if the user is trying to make the bot slap itself, slap them
if target.lower() == conn.nick.lower() or target.lower() == "itself":
target = nick
variables = {
"user": target
}
with open("plugins/data/slaps.json") as f:
generator = get_generator(f.read(), variables)
# act out the message
me(generator.generate_string())