From 2d06a1fc4a0010740cd3a45700bebf3ca74b865b Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Wed, 11 Sep 2013 22:59:13 +1200 Subject: [PATCH 01/18] patched! --- plugins/dictionary.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/dictionary.py b/plugins/dictionary.py index 478f77f..ca74c36 100755 --- a/plugins/dictionary.py +++ b/plugins/dictionary.py @@ -40,7 +40,7 @@ def define(inp): for article in sections: result += article[0] if len(article) > 2: - result += ' '.join('{}. {}'.format(n + 1, section) + result += u' '.join(u'{}. {}'.format(n + 1, section) for n, section in enumerate(article[1:])) else: result += article[1] + ' ' From 9a296d4076668edb8fe9f6d1edd372d674274123 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Thu, 12 Sep 2013 00:10:42 +1200 Subject: [PATCH 02/18] karma update --- plugins/karma.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/karma.py b/plugins/karma.py index fd700a6..66d2248 100644 --- a/plugins/karma.py +++ b/plugins/karma.py @@ -90,7 +90,7 @@ def karma_add(match, nick='', chan='', db=None, notice=None): down_karma, total_karma) values(?,?,?,?)""", (nick_vote.lower(),0,0,0)) up(db, nick_vote) - notice("Gave {} +1 karma!".format(nick_vote)) + notice("Gave {} 1 karma!".format(nick_vote)) if match.group(2) == '--': db.execute("""INSERT or IGNORE INTO karma( nick_vote, @@ -126,6 +126,6 @@ def karma(inp, nick='', chan='', db=None): return "That user has no karma." else: out = out[0] - return "%s has \x02%s\x02 karma." % (nick_vote, out[1]-out[2]) + return "%s has %s karma points." % (nick_vote, out[1]-out[2]) return From ea39a6fbb96906769cd10d820231724edc9d9dbf Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Thu, 12 Sep 2013 00:12:50 +1200 Subject: [PATCH 03/18] no --- plugins/karma.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/karma.py b/plugins/karma.py index 66d2248..1a8941f 100644 --- a/plugins/karma.py +++ b/plugins/karma.py @@ -126,6 +126,6 @@ def karma(inp, nick='', chan='', db=None): return "That user has no karma." else: out = out[0] - return "%s has %s karma points." % (nick_vote, out[1]-out[2]) + return "{} has {} karma points.".format(nick_vote, out[1]-out[2]) return From 8e545b3a3155d42b196d66b32eb29b7604c1721d Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Thu, 12 Sep 2013 11:58:00 +1200 Subject: [PATCH 04/18] Fixed namegen --- plugins/namegen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/namegen.py b/plugins/namegen.py index ff9a2f0..5aa53ec 100755 --- a/plugins/namegen.py +++ b/plugins/namegen.py @@ -36,7 +36,7 @@ class NameGenerator(object): for name_part in name_parts: part = random.choice(self.parts[name_part]) - name = name.replace("\{{}\}".format(name_part), part) + name = name.replace("{" + name_part + "}", part) return name From 15e7825125bb6b060ce52f0c7e8d115834ddb03f Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Thu, 12 Sep 2013 20:47:39 +1200 Subject: [PATCH 05/18] Moved generation logic out of namegen.py --- plugins/namegen.py | 56 +++++++---------------------------------- plugins/util/textgen.py | 38 ++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 47 deletions(-) create mode 100644 plugins/util/textgen.py diff --git a/plugins/namegen.py b/plugins/namegen.py index 5aa53ec..410620d 100755 --- a/plugins/namegen.py +++ b/plugins/namegen.py @@ -1,59 +1,21 @@ # Plugin by Lukeroge -import json -import random -import re -import os -from util import hook -from util.text import get_text_list +from util import hook, text, textgen +import json, os -TEMPLATE_RE = re.compile(r"\{(.+?)\}") GEN_DIR = "./plugins/data/name_files/" def get_generator(_json): data = json.loads(_json) - return NameGenerator(data["name"], data["templates"], - data["default_templates"], data["parts"]) - - -class NameGenerator(object): - def __init__(self, name, templates, default_templates, parts): - self.name = name - self.templates = templates - self.default_templates = default_templates - self.parts = parts - - def generate_name(self, template=None): - """ - Generates one name using the specified templates. - If no templates are specified, use a random template from the default_templates list. - """ - name = self.templates[template or random.choice(self.default_templates)] - - # get a list of all name parts we need - name_parts = TEMPLATE_RE.findall(name) - - for name_part in name_parts: - part = random.choice(self.parts[name_part]) - name = name.replace("{" + name_part + "}", part) - - return name - - def generate_names(self, amount): - names = [] - for i in xrange(amount): - names.append(self.generate_name()) - return names - - def get_template(self, template): - return self.templates[template] + return textgen.TextGenerator(data["name"], data["templates"], + data["default_templates"], data["parts"]) @hook.command(autohelp=False) def namegen(inp, notice=None): - """namegen [generator] -- Generates some names using the chosen generator. - 'namegen list' will display a list of all generators.""" + "namegen [generator] -- Generates some names using the chosen generator. " \ + "'namegen list' will display a list of all generators." # clean up the input inp = inp.strip().lower() @@ -69,7 +31,7 @@ def namegen(inp, notice=None): # command to return a list of all available generators if inp == "list": message = "Available generators: " - message += get_text_list(all_modules, 'and') + message += text.get_text_list(all_modules, 'and') notice(message) return @@ -91,7 +53,7 @@ def namegen(inp, notice=None): return "Unable to read name file: {}".format(error) # time to generate some names - name_list = generator.generate_names(10) + name_list = generator.generate_strings(10) # and finally return the final message :D - return "Some names to ponder: {}.".format(get_text_list(name_list, 'and')) + return "Some names to ponder: {}.".format(text.get_text_list(name_list, 'and')) diff --git a/plugins/util/textgen.py b/plugins/util/textgen.py new file mode 100644 index 0000000..89d7ced --- /dev/null +++ b/plugins/util/textgen.py @@ -0,0 +1,38 @@ +import re +import random + +TEMPLATE_RE = re.compile(r"\{(.+?)\}") + + +class TextGenerator(object): + def __init__(self, name, templates, default_templates, parts, variables=None): + self.name = name + self.templates = templates + self.default_templates = default_templates + self.parts = parts + self.variables = 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)] + + # get a list of all text parts we need + required_parts = TEMPLATE_RE.findall(text) + + for required_part in required_parts: + part = random.choice(self.parts[required_part]) + text = text.replace("{%s}" % required_part, part) + + return text + + def generate_strings(self, amount, template=None): + strings = [] + for i in xrange(amount): + strings.append(self.generate_string()) + return strings + + def get_template(self, template): + return self.templates[template] \ No newline at end of file From 2be0c46b8910384a6d499cbca4d6495b001cd236 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Thu, 12 Sep 2013 22:46:43 +1200 Subject: [PATCH 06/18] made slap use the new TextGenerator class --- plugins/attacks.py | 29 --------------------- plugins/data/slap_items.txt | 29 --------------------- plugins/data/slaps.json | 51 +++++++++++++++++++++++++++++++++++++ plugins/data/slaps.txt | 14 ---------- plugins/slap.py | 32 +++++++++++++++++++++++ plugins/util/textgen.py | 13 +++++++--- 6 files changed, 93 insertions(+), 75 deletions(-) delete mode 100755 plugins/data/slap_items.txt create mode 100644 plugins/data/slaps.json delete mode 100755 plugins/data/slaps.txt create mode 100644 plugins/slap.py 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) From cbcf1dc4b53b3e0f4b31a26acd964be91228f91b Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Thu, 12 Sep 2013 23:05:15 +1200 Subject: [PATCH 07/18] more stuff @cybojenix --- plugins/data/slaps.json | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/plugins/data/slaps.json b/plugins/data/slaps.json index 3c4e42a..d446cef 100644 --- a/plugins/data/slaps.json +++ b/plugins/data/slaps.json @@ -1,21 +1,21 @@ { "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.", + "{hits} {user} with a {item}.", + "{hits} {user} around a bit with a {item}.", + "{throws} a {item} at {user}.", + "{throws} 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}.", + "holds {user} down and repeatedly {hits} them with a {item}.", + "prods {user} with a {mod} {item}.", + "picks up a {item} and {hits} {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":{ + "parts": { "item":[ "cast iron skillet", "large trout", @@ -46,6 +46,22 @@ "fire extinguisher", "heavy rock", "chunk of dirt" + ], + "throws": [ + "throws", + "flings", + "chucks" + ], + "hits": [ + "hits", + "whacks", + "slaps", + "smacks" + ], + "mod": [ + "flaming", + "sticky", + "dripping" ] } } \ No newline at end of file From ecab6076ea1e85c743078f218b6ed6126233129b Mon Sep 17 00:00:00 2001 From: CafogenMod Date: Thu, 12 Sep 2013 15:49:00 +0400 Subject: [PATCH 08/18] update restart command --- plugins/admin.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/plugins/admin.py b/plugins/admin.py index c660615..17a0169 100755 --- a/plugins/admin.py +++ b/plugins/admin.py @@ -1,5 +1,5 @@ from util import hook -import os +import os, sys import re import json import time @@ -114,15 +114,18 @@ def stop(inp, nick=None, conn=None): @hook.command(autohelp=False, permissions=["botcontrol"]) -def restart(inp, nick=None, conn=None): +def restart(inp, nick=None, conn=None, bot=None): """restart [reason] -- Restarts the bot with [reason] as its quit message.""" - if inp: - conn.cmd("QUIT", ["Restarted by {} ({})".format(nick, inp)]) - else: - conn.cmd("QUIT", ["Restarted by {}.".format(nick)]) + for botcon in bot.conns: + if inp: + bot.conns[botcon].cmd("QUIT", ["Restarted by {} ({})".format(nick, inp)]) + else: + bot.conns[botcon].cmd("QUIT", ["Restarted by {}.".format(nick)]) time.sleep(5) - os.execl("./cloudbot", "cloudbot", "restart") - + #os.execl("./cloudbot", "cloudbot", "restart") + args = sys.argv[:] + args.insert(0, sys.executable) + os.execv(sys.executable, args) @hook.command(autohelp=False, permissions=["botcontrol"]) def clearlogs(inp, input=None): From cb7f9b736f54ed78f28b2c26cad2db8a457bf05c Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Fri, 13 Sep 2013 00:33:45 +1200 Subject: [PATCH 09/18] fix? --- plugins/namegen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/namegen.py b/plugins/namegen.py index 410620d..6b928e8 100755 --- a/plugins/namegen.py +++ b/plugins/namegen.py @@ -9,7 +9,7 @@ GEN_DIR = "./plugins/data/name_files/" def get_generator(_json): data = json.loads(_json) return textgen.TextGenerator(data["name"], data["templates"], - data["default_templates"], data["parts"]) + data["parts"], data["default_templates"]) @hook.command(autohelp=False) From d9f613f6f4b8710d055d096c495b8d089a7ac490 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Fri, 13 Sep 2013 10:32:09 +1200 Subject: [PATCH 10/18] Update slaps.json --- plugins/data/slaps.json | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/plugins/data/slaps.json b/plugins/data/slaps.json index d446cef..1e43a55 100644 --- a/plugins/data/slaps.json +++ b/plugins/data/slaps.json @@ -9,7 +9,7 @@ "sits on {user}'s face while slamming a {item} into their crotch.", "starts slapping {user} silly with a {item}.", "holds {user} down and repeatedly {hits} them with a {item}.", - "prods {user} with a {mod} {item}.", + "prods {user} with a {item}.", "picks up a {item} and {hits} {user} with it.", "ties {user} to a chair and {throws} a {item} at them.", "{hits} {user} on the head with a {item}.", @@ -57,11 +57,6 @@ "whacks", "slaps", "smacks" - ], - "mod": [ - "flaming", - "sticky", - "dripping" ] } -} \ No newline at end of file +} From 1bba6262bcfe7b6fe6d2ac87d091e9334dd5a023 Mon Sep 17 00:00:00 2001 From: Steven Smith Date: Fri, 13 Sep 2013 17:17:15 +0800 Subject: [PATCH 11/18] Updated site search function, fixing associated plugin --- plugins/valuesounds.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/valuesounds.py b/plugins/valuesounds.py index 572a545..4eb60ec 100644 --- a/plugins/valuesounds.py +++ b/plugins/valuesounds.py @@ -10,7 +10,7 @@ def get_sound_info(game, search): except HTTPError as e: return "Error: " + json.loads(e.read())["error"] items = [] - for item in data: + for item in data["items"]: if "music" in game: textsplit = item["text"].split('"') text = "" From 59d615aa8842f7154af3d545363874eddb1e94c7 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Fri, 13 Sep 2013 21:18:45 +1200 Subject: [PATCH 12/18] rename! --- plugins/{valuesounds.py => valvesounds.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename plugins/{valuesounds.py => valvesounds.py} (100%) diff --git a/plugins/valuesounds.py b/plugins/valvesounds.py similarity index 100% rename from plugins/valuesounds.py rename to plugins/valvesounds.py From ae258e6c37c9d58df9581d130f23d0a4e7e719ec Mon Sep 17 00:00:00 2001 From: Steven Smith Date: Fri, 13 Sep 2013 17:27:18 +0800 Subject: [PATCH 13/18] Update valvesounds.py --- plugins/valvesounds.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/plugins/valvesounds.py b/plugins/valvesounds.py index 4eb60ec..7c4b93e 100644 --- a/plugins/valvesounds.py +++ b/plugins/valvesounds.py @@ -1,13 +1,20 @@ from util import hook, http, web import json -from urllib2 import HTTPError +import urllib2 def get_sound_info(game, search): + # Currently, http.get_json doesn't support adding headers. + def get_json(url, headers): + request = urllib2.Request(url) + request.add_header('User-Agent', http.ua_cloudbot) + opener = urllib2.build_opener() + return json.loads(opener.open(request)) + search = search.replace(" ", "+") try: - data = http.get_json("http://p2sounds.blha303.com.au/search/%s/%s" % (game, search)) - except HTTPError as e: + data = get_json("http://p2sounds.blha303.com.au/search/%s/%s" % (game, search)) + except urllib2.HTTPError as e: return "Error: " + json.loads(e.read())["error"] items = [] for item in data["items"]: From e8947a603b2c3876da30de6f09fbfd1e3857ce3a Mon Sep 17 00:00:00 2001 From: Steven Smith Date: Fri, 13 Sep 2013 17:28:51 +0800 Subject: [PATCH 14/18] Update valvesounds.py --- plugins/valvesounds.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/valvesounds.py b/plugins/valvesounds.py index 7c4b93e..b5178bc 100644 --- a/plugins/valvesounds.py +++ b/plugins/valvesounds.py @@ -5,7 +5,7 @@ import urllib2 def get_sound_info(game, search): # Currently, http.get_json doesn't support adding headers. - def get_json(url, headers): + def get_json(url): request = urllib2.Request(url) request.add_header('User-Agent', http.ua_cloudbot) opener = urllib2.build_opener() From b460fb2fd2dfed0fa71e85494ee5980bace68c91 Mon Sep 17 00:00:00 2001 From: Steven Smith Date: Fri, 13 Sep 2013 17:30:01 +0800 Subject: [PATCH 15/18] Update valvesounds.py --- plugins/valvesounds.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/valvesounds.py b/plugins/valvesounds.py index b5178bc..a8bd9a3 100644 --- a/plugins/valvesounds.py +++ b/plugins/valvesounds.py @@ -9,7 +9,7 @@ def get_sound_info(game, search): request = urllib2.Request(url) request.add_header('User-Agent', http.ua_cloudbot) opener = urllib2.build_opener() - return json.loads(opener.open(request)) + return json.loads(opener.open(request).read()) search = search.replace(" ", "+") try: From a69c4eceb3d3bf35e3b6a4cb58f092ba454517d0 Mon Sep 17 00:00:00 2001 From: Steven Smith Date: Fri, 13 Sep 2013 17:45:13 +0800 Subject: [PATCH 16/18] Update valvesounds.py --- plugins/valvesounds.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/plugins/valvesounds.py b/plugins/valvesounds.py index a8bd9a3..5535877 100644 --- a/plugins/valvesounds.py +++ b/plugins/valvesounds.py @@ -4,16 +4,9 @@ import urllib2 def get_sound_info(game, search): - # Currently, http.get_json doesn't support adding headers. - def get_json(url): - request = urllib2.Request(url) - request.add_header('User-Agent', http.ua_cloudbot) - opener = urllib2.build_opener() - return json.loads(opener.open(request).read()) - search = search.replace(" ", "+") try: - data = get_json("http://p2sounds.blha303.com.au/search/%s/%s" % (game, search)) + data = http.get_json("http://p2sounds.blha303.com.au/search/%s/%s?format=json" % (game, search)) except urllib2.HTTPError as e: return "Error: " + json.loads(e.read())["error"] items = [] From 00f7e35a2498cc9a26e39e297007c29c8171d6ed Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Sat, 14 Sep 2013 01:15:36 +1200 Subject: [PATCH 17/18] Thanks cracks --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 906ead3..f318288 100755 --- a/README.md +++ b/README.md @@ -20,6 +20,9 @@ Before you can run the bot, you need to install a few Python dependencies. LXML These can be installed with `pip` (The Python package manager): [sudo] pip install -r requirements.txt + +If you use `pip`, you will also need the following packages on linux or `pip` will fail to install the requirements. + ```python, python-dev, libenchant-dev, libenchant1c2a, libxslt-dev, libxml2-dev.``` #### How to install `pip` From d5163a846a5c51a028379062873593fe4dc4e400 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Sun, 15 Sep 2013 23:00:53 +1200 Subject: [PATCH 18/18] Updated .kill to use TextGenerator! :) --- plugins/attacks.py | 24 ------------- plugins/data/kills.json | 79 +++++++++++++++++++++++++++++++++++++++++ plugins/slap.py | 4 +-- 3 files changed, 81 insertions(+), 26 deletions(-) create mode 100644 plugins/data/kills.json diff --git a/plugins/attacks.py b/plugins/attacks.py index 7c778b9..7e93ce0 100644 --- a/plugins/attacks.py +++ b/plugins/attacks.py @@ -5,10 +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/kills.txt") as f: - kills = [line.strip() for line in f.readlines() - if not line.startswith("//")] - with open("plugins/data/insults.txt") as f: insults = [line.strip() for line in f.readlines() if not line.startswith("//")] @@ -37,26 +33,6 @@ def lart(inp, me=None, nick=None, conn=None, notice=None): me(phrase.format(**values)) -@hook.command -def kill(inp, me=None, nick=None, conn=None, notice=None): - """kill -- Makes the bot kill .""" - 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 = {"user": target} - phrase = random.choice(kills) - - # act out the message - me(phrase.format(**values)) - - @hook.command def insult(inp, nick=None, me=None, conn=None, notice=None): """insult -- Makes the bot insult .""" diff --git a/plugins/data/kills.json b/plugins/data/kills.json new file mode 100644 index 0000000..b657209 --- /dev/null +++ b/plugins/data/kills.json @@ -0,0 +1,79 @@ +{ + "templates":[ + "rips off {user}'s {limbs} and leaves them to die.", + "grabs {user}'s head and rips it clean off their body.", + "grabs a {gun} and riddles {user}'s body with bullets.", + "gags and ties {user} then throws them off a {tall_thing}.", + "crushes {user} with a huge spiked {spiked_thing}.", + "glares at {user} until they die of boredom.", + "stabs {user} in the heart a few times with a {weapon_stab}.", + "rams a {weapon_explosive} up {user}'s ass and lets off a few rounds.", + "crushes {user}'s skull in with a {weapon_crush}.", + "unleashes the armies of Isengard on {user}.", + "gags and ties {user} then throws them off a {tall_thing} to their death.", + "reaches out and punches right through {user}'s chest.", + "slices {user}'s limbs off with a {weapon_slice}.", + "throws {user} to Cthulu and watches them get ripped to shreds.", + "feeds {user} to an owlbear who then proceeds to maul them violently.", + "turns {user} into a snail and covers then in salt.", + "snacks on {user}'s dismembered body.", + "stuffs {bomb} up {user}'s ass and waits for it to go off.", + "puts {user} into a sack, throws the sack in the river, and hurls the river into space.", + "goes bowling with {user}'s bloody disembodied head.", + "sends {user} to /dev/null!", + "feeds {user} coke and mentos till they violently explode." + ], + "parts": { + "gun":[ + "AK47", + "machine gun", + "automatic pistol", + "Uzi" + ], + "limbs": [ + "legs", + "arms", + "limbs" + ], + "weapon_stab": [ + "knife", + "shard of glass", + "sword blade", + "butchers knife", + "corkscrew" + ], + "weapon_slice": [ + "sharpened katana", + "chainsaw", + "polished axe" + ], + "weapon_crush": [ + "spiked mace", + "baseball bat", + "wooden club", + "massive steel ball", + "heavy iron rod" + ], + "weapon_explosive": [ + "rocket launcher", + "grenade launcher", + "napalm launcher" + ], + "tall_thing": [ + "bridge", + "tall building", + "cliff", + "mountain" + ], + "spiked_thing": [ + "boulder", + "rock", + "barrel of rocks" + ], + "bomb": [ + "a bomb", + "some TNT", + "a bunch of C4" + ] + } +} diff --git a/plugins/slap.py b/plugins/slap.py index b887ab3..4e21398 100644 --- a/plugins/slap.py +++ b/plugins/slap.py @@ -1,5 +1,5 @@ -from util import hook, text, textgen -import json, os +from util import hook, textgen +import json def get_generator(_json, variables):