This repository has been archived on 2023-04-13. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
CloudBot/plugins/slap.py
Luke Rogers aa8ab33ccb Merge branch 'develop' into refresh
Conflicts:
	core/config.py
	plugins/util/color.py
	plugins/util/formatting.py
2013-11-27 16:55:04 +13:00

32 lines
838 B
Python

from util import hook, textgen
import json
def get_generator(_json, variables):
data = json.loads(_json)
return textgen.TextGenerator(data["templates"],
data["parts"], variables=variables)
@hook.command
def slap(inp, action=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("./data/slaps.json") as f:
generator = get_generator(f.read(), variables)
# act out the message
action(generator.generate_string())