diff --git a/plugins/attacks.py b/plugins/attacks.py index 2a24102..7c778b9 100644 --- a/plugins/attacks.py +++ b/plugins/attacks.py @@ -5,14 +5,6 @@ with open("plugins/data/larts.txt") as f: larts = [line.strip() for line in f.readlines() if not line.startswith("//")] -with open("plugins/data/slaps.txt") as f: - slaps = [line.strip() for line in f.readlines() - if not line.startswith("//")] - -with open("plugins/data/slap_items.txt") as f: - items = [line.strip() for line in f.readlines() - if not line.startswith("//")] - with open("plugins/data/kills.txt") as f: kills = [line.strip() for line in f.readlines() if not line.startswith("//")] @@ -25,27 +17,6 @@ with open("plugins/data/flirts.txt") as f: flirts = [line.strip() for line in f.readlines() if not line.startswith("//")] - -@hook.command -def slap(inp, me=None, nick=None, conn=None, notice=None): - """slap -- Makes the bot slap .""" - 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 - - values = {"item": random.choice(items), "user": target} - phrase = random.choice(slaps) - - # act out the message - me(phrase.format(**values)) - - @hook.command def lart(inp, me=None, nick=None, conn=None, notice=None): """lart -- LARTs .""" diff --git a/plugins/data/slap_items.txt b/plugins/data/slap_items.txt deleted file mode 100755 index fdc36e1..0000000 --- a/plugins/data/slap_items.txt +++ /dev/null @@ -1,29 +0,0 @@ -cast iron skillet -large trout -baseball bat -wooden cane -nail -printer -shovel -pair of trousers -CRT monitor -diamond sword -baguette -physics textbook -television -mau5head -five ton truck -roll of duct tape -book -laptop -old television -sack of rocks -rainbow trout -cobblestone block -lava bucket -rubber chicken -spiked bat -gold block -fire extinguisher -heavy rock -chunk of dirt diff --git a/plugins/data/slaps.json b/plugins/data/slaps.json new file mode 100644 index 0000000..3c4e42a --- /dev/null +++ b/plugins/data/slaps.json @@ -0,0 +1,51 @@ +{ + "templates":[ + "slaps {user} with a {item}.", + "slaps {user} around a bit with a {item}.", + "throws a {item} at {user}.", + "chucks a few {item}s at {user}.", + "grabs a {item} and throws it in {user}'s face.", + "launches a {item} in {user}'s general direction.", + "sits on {user}'s face while slamming a {item} into their crotch.", + "starts slapping {user} silly with a {item}.", + "holds {user} down and repeatedly whacks them with a {item}.", + "prods {user} with a flaming {item}.", + "picks up a {item} and whacks {user} with it.", + "ties {user} to a chair and throws a {item} at them.", + "hits {user} on the head with a {item}.", + "ties {user} to a pole and whips them with a {item}." + ], + "parts":{ + "item":[ + "cast iron skillet", + "large trout", + "baseball bat", + "wooden cane", + "nail", + "printer", + "shovel", + "pair of trousers", + "CRT monitor", + "diamond sword", + "baguette", + "physics textbook", + "television", + "mau5head", + "five ton truck", + "roll of duct tape", + "book", + "laptop", + "old television", + "sack of rocks", + "rainbow trout", + "cobblestone block", + "lava bucket", + "rubber chicken", + "spiked bat", + "gold block", + "fire extinguisher", + "heavy rock", + "chunk of dirt" + ] + } +} \ No newline at end of file diff --git a/plugins/data/slaps.txt b/plugins/data/slaps.txt deleted file mode 100755 index 8952952..0000000 --- a/plugins/data/slaps.txt +++ /dev/null @@ -1,14 +0,0 @@ -slaps {user} with a {item}. -slaps {user} around a bit with a {item}. -throws a {item} at {user}. -chucks a few {item}s at {user}. -grabs a {item} and throws it in {user}'s face. -launches a {item} in {user}'s general direction. -sits on {user}'s face while slamming a {item} into their crotch. -starts slapping {user} silly with a {item}. -holds {user} down and repeatedly whacks them with a {item}. -prods {user} with a flaming {item}. -picks up a {item} and whacks {user} with it. -ties {user} to a chair and throws a {item} at them. -hits {user} on the head with a {item}. -ties {user} to a pole and whips them with a {item}. diff --git a/plugins/slap.py b/plugins/slap.py new file mode 100644 index 0000000..b887ab3 --- /dev/null +++ b/plugins/slap.py @@ -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 -- Makes the bot slap .""" + 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()) \ No newline at end of file diff --git a/plugins/util/textgen.py b/plugins/util/textgen.py index 89d7ced..24aff86 100644 --- a/plugins/util/textgen.py +++ b/plugins/util/textgen.py @@ -5,19 +5,26 @@ TEMPLATE_RE = re.compile(r"\{(.+?)\}") class TextGenerator(object): - def __init__(self, name, templates, default_templates, parts, variables=None): - self.name = name + def __init__(self, templates, parts, default_templates=None, variables=None): self.templates = templates self.default_templates = default_templates self.parts = parts self.variables = variables + print self.variables def generate_string(self, template=None): """ Generates one string using the specified templates. If no templates are specified, use a random template from the default_templates list. """ - text = self.templates[template or random.choice(self.default_templates)] + if self.default_templates: + text = self.templates[template or random.choice(self.default_templates)] + else: + text = random.choice(self.templates) + + if self.variables: + for key, value in self.variables.items(): + text = text.replace("{%s}" % key, value) # get a list of all text parts we need required_parts = TEMPLATE_RE.findall(text)