From 69775a0cc7dc0477451256e8be5628afb5d32c22 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Mon, 26 Mar 2012 18:11:22 +1300 Subject: [PATCH] More refactoring --- plugins/data/slaps.txt | 2 +- plugins/violence.py | 80 +++++++++++++++++++++++------------------- 2 files changed, 45 insertions(+), 37 deletions(-) diff --git a/plugins/data/slaps.txt b/plugins/data/slaps.txt index ae23e7b..d8ee0b2 100755 --- a/plugins/data/slaps.txt +++ b/plugins/data/slaps.txt @@ -7,6 +7,6 @@ launches a in 's general direction. sits on 's face, while slamming a into their crotch. holds down and repeatedly whacks them with a . prods with a flaming . -picks up a , and whacks with it. +picks up a and whacks with it. ties to a chair and throws a at them. hits on the head with a . diff --git a/plugins/violence.py b/plugins/violence.py index 015491b..1ea9a2e 100644 --- a/plugins/violence.py +++ b/plugins/violence.py @@ -11,13 +11,13 @@ with open("plugins/data/slaps.txt") as f: for line in f.readlines(): if line.startswith("//"): continue - slaps.append(line) + slaps.append(line.strip()) with open("plugins/data/slap_items.txt") as f: for line in f.readlines(): if line.startswith("//"): continue - slap_items.append(line) + slap_items.append(line.strip()) larts = ["swaps 's shampoo with glue.", "installs Windows on 's computer.", @@ -160,55 +160,63 @@ body = ['head', @hook.command -def slap(inp, me=None, nick=None, input=None, notice=None): +def slap(inp, me=None, nick=None, conn=None, notice=None): ".slap -- Makes the bot slap ." - inp = inp.strip() - - if not re.match(nick_re, inp.lower()): + target = inp.lower() + + if not re.match(nick_re, target): notice("Invalid username!") return - if inp == input.conn.nick.lower() or inp == "itself": - target = re.sub ('', nick, random.choice(slaps)) - else: - target = re.sub ('', inp, random.choice(slaps)) - msg = re.sub ('', random.choice(slap_items), target) - me(msg) - - - -@hook.command -def lart(inp, me=None, nick=None, input=None, notice=None): - ".lart -- Makes the bot LART ." - inp = inp.strip() - - if not re.match(nick_re, inp.lower()): - notice("Invalid username!") - return - - if inp == input.conn.nick.lower() or inp == "itself": + # if the user is trying to make the bot slap itself, slap them + if target == conn.nick.lower() or target == "itself": target = nick else: target = inp - msg = re.sub ('', target, random.choice(larts)) - me(msg) - + + out = random.choice(slaps) + out = out.replace('', target) + out = out.replace('', random.choice(slap_items)) + + # act out the message + me(out) @hook.command -def kill(inp, me=None, nick=None, input=None, notice=None): +def lart(inp, me=None, nick=None, conn=None, notice=None): + ".lart -- LARTs ." + target = inp.lower() + + if not re.match(nick_re, target): + notice("Invalid username!") + return + + if target == conn.nick.lower() or target == "itself": + target = nick + else: + target = inp + + out = random.choice(larts) + out = out.replace('', target) + out = out.replace('', random.choice(slap_items)) + me(out) + + +@hook.command +def kill(inp, me=None, nick=None, conn=None, notice=None): ".kill -- Makes the bot kill ." - inp = inp.strip() + target = inp.lower() - if not re.match(nick_re, inp.lower()): + if not re.match(nick_re, target): notice("Invalid username!") return - if inp == input.conn.nick.lower() or inp == "itself": + if target == conn.nick.lower() or target == "itself": target = nick else: target = inp - msg = random.choice(kills) - msg = re.sub ('', target, msg) - msg = re.sub ('', random.choice(body), msg) - me(msg) + + out = random.choice(kills) + out = out.replace('', target) + out = out.replace('', random.choice(body)) + me(out)