From 72babfceb26463ff0533c753491d81eedc994852 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Tue, 1 Oct 2013 15:41:54 +1300 Subject: [PATCH 1/2] refactored me() to action() --- core/main.py | 4 ++-- plugins/attacks.py | 12 ++++++------ plugins/coin.py | 8 ++++---- plugins/eightball.py | 4 ++-- plugins/factoids.py | 4 ++-- plugins/kill.py | 4 ++-- plugins/potato.py | 4 ++-- plugins/slap.py | 4 ++-- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/core/main.py b/core/main.py index 9412b6b..c99516c 100755 --- a/core/main.py +++ b/core/main.py @@ -25,7 +25,7 @@ class Input(dict): else: conn.msg(chan, u'(' + nick + u') ' + msg) - def me(msg, chan=chan): + def action(msg, chan=chan): conn.msg(chan, u"\x01{} {}\x01".format("ACTION", msg)) def notice(msg, nick=nick): @@ -35,7 +35,7 @@ class Input(dict): params=params, nick=nick, user=user, host=host, mask=mask, paraml=paraml, msg=msg, server=conn.server, chan=chan, notice=notice, say=say, reply=reply, pm=pm, bot=bot, - me=me, lastparam=paraml[-1]) + action=action, lastparam=paraml[-1]) # make dict keys accessible as attributes def __getattr__(self, key): diff --git a/plugins/attacks.py b/plugins/attacks.py index 7e93ce0..3ba4883 100644 --- a/plugins/attacks.py +++ b/plugins/attacks.py @@ -14,7 +14,7 @@ with open("plugins/data/flirts.txt") as f: if not line.startswith("//")] @hook.command -def lart(inp, me=None, nick=None, conn=None, notice=None): +def lart(inp, action=None, nick=None, conn=None, notice=None): """lart -- LARTs .""" target = inp.strip() @@ -30,11 +30,11 @@ def lart(inp, me=None, nick=None, conn=None, notice=None): phrase = random.choice(larts) # act out the message - me(phrase.format(**values)) + action(phrase.format(**values)) @hook.command -def insult(inp, nick=None, me=None, conn=None, notice=None): +def insult(inp, nick=None, action=None, conn=None, notice=None): """insult -- Makes the bot insult .""" target = inp.strip() @@ -48,11 +48,11 @@ def insult(inp, nick=None, me=None, conn=None, notice=None): target = inp out = 'insults {}... "{}"'.format(target, random.choice(insults)) - me(out) + action(out) @hook.command -def flirt(inp, me=None, conn=None, notice=None): +def flirt(inp, action=None, conn=None, notice=None): """flirt -- Make the bot flirt with .""" target = inp.strip() @@ -66,4 +66,4 @@ def flirt(inp, me=None, conn=None, notice=None): target = inp out = 'flirts with {}... "{}"'.format(target, random.choice(flirts)) - me(out) + action(out) diff --git a/plugins/coin.py b/plugins/coin.py index 78668bb..104b3a7 100755 --- a/plugins/coin.py +++ b/plugins/coin.py @@ -3,7 +3,7 @@ import random @hook.command(autohelp=False) -def coin(inp, me=None): +def coin(inp, action=None): """coin [amount] -- Flips [amount] of coins.""" if inp: @@ -15,10 +15,10 @@ def coin(inp, me=None): amount = 1 if amount == 1: - me("flips a coin and gets {}.".format(random.choice(["heads", "tails"]))) + action("flips a coin and gets {}.".format(random.choice(["heads", "tails"]))) elif amount == 0: - me("makes a coin flipping motion with its hands.") + action("makes a coin flipping motion with its hands.") else: heads = int(random.normalvariate(.5 * amount, (.75 * amount) ** .5)) tails = amount - heads - me("flips {} coins and gets {} heads and {} tails.".format(amount, heads, tails)) + action("flips {} coins and gets {} heads and {} tails.".format(amount, heads, tails)) diff --git a/plugins/eightball.py b/plugins/eightball.py index 141c464..929a890 100755 --- a/plugins/eightball.py +++ b/plugins/eightball.py @@ -13,9 +13,9 @@ with open("plugins/data/8ball_responses.txt") as f: @hook.command('8ball') -def eightball(input, me=None): +def eightball(input, action=None): """8ball -- The all knowing magic eight ball, in electronic form. Ask and it shall be answered!""" magic = text.multiword_replace(random.choice(responses), color_codes) - me("shakes the magic 8 ball... {}".format(magic)) + action("shakes the magic 8 ball... {}".format(magic)) diff --git a/plugins/factoids.py b/plugins/factoids.py index a42ed56..d2b27ec 100755 --- a/plugins/factoids.py +++ b/plugins/factoids.py @@ -105,7 +105,7 @@ def info(inp, notice=None, db=None): @hook.regex(r'^\? ?(.+)') -def factoid(inp, say=None, db=None, bot=None, me=None, conn=None, input=None): +def factoid(inp, say=None, db=None, bot=None, action=None, conn=None, input=None): "? -- Shows what data is associated with ." try: prefix_on = bot.config["plugins"]["factoids"].get("prefix", False) @@ -141,7 +141,7 @@ def factoid(inp, say=None, db=None, bot=None, me=None, conn=None, input=None): if result.startswith(""): result = result[5:].strip() - me(result) + action(result) elif result.startswith(""): url = result[5:].strip() try: diff --git a/plugins/kill.py b/plugins/kill.py index effa609..37be4ba 100644 --- a/plugins/kill.py +++ b/plugins/kill.py @@ -9,7 +9,7 @@ def get_generator(_json, variables): @hook.command -def kill(inp, me=None, nick=None, conn=None, notice=None): +def kill(inp, action=None, nick=None, conn=None, notice=None): """kill -- Makes the bot kill .""" target = inp.strip() @@ -29,4 +29,4 @@ def kill(inp, me=None, nick=None, conn=None, notice=None): generator = get_generator(f.read(), variables) # act out the message - me(generator.generate_string()) \ No newline at end of file + action(generator.generate_string()) \ No newline at end of file diff --git a/plugins/potato.py b/plugins/potato.py index 8d03e2b..4eb2e98 100755 --- a/plugins/potato.py +++ b/plugins/potato.py @@ -37,7 +37,7 @@ potatoes = ['AC Belmont', 'AC Blue Pride', 'AC Brador', 'AC Chaleur', 'AC Domino @hook.command -def potato(inp, me=None, input=None): +def potato(inp, action=None, input=None): """potato - Makes a tasty little potato.""" inp = inp.strip() @@ -50,5 +50,5 @@ def potato(inp, me=None, input=None): method = random.choice(['bakes', 'fries', 'boils', 'roasts']) side_dish = random.choice(['side salad', 'dollop of sour cream', 'piece of chicken', 'bowl of shredded bacon']) - me("{} a {} {} {} potato for {} and serves it with a small {}!".format(method, flavor, size, potato_type, inp, + action("{} a {} {} {} potato for {} and serves it with a small {}!".format(method, flavor, size, potato_type, inp, side_dish)) diff --git a/plugins/slap.py b/plugins/slap.py index 4e21398..89936c3 100644 --- a/plugins/slap.py +++ b/plugins/slap.py @@ -9,7 +9,7 @@ def get_generator(_json, variables): @hook.command -def slap(inp, me=None, nick=None, conn=None, notice=None): +def slap(inp, action=None, nick=None, conn=None, notice=None): """slap -- Makes the bot slap .""" target = inp.strip() @@ -29,4 +29,4 @@ def slap(inp, me=None, nick=None, conn=None, notice=None): generator = get_generator(f.read(), variables) # act out the message - me(generator.generate_string()) \ No newline at end of file + action(generator.generate_string()) \ No newline at end of file From 51c866de6d36484775d56e2c68e3157ebbe104a3 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Tue, 1 Oct 2013 15:48:22 +1300 Subject: [PATCH 2/2] commented core more --- core/main.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/core/main.py b/core/main.py index c99516c..a2b3e78 100755 --- a/core/main.py +++ b/core/main.py @@ -13,28 +13,33 @@ class Input(dict): if chan == conn.nick.lower(): # is a PM chan = nick - def say(msg, chan=chan): + def say(msg): + """sends a message to the current channel/user""" conn.msg(chan, msg) - def pm(msg, nick=nick): + def msg(msg, nick=nick): + """sends a message to a specific channel/user""" conn.msg(nick, msg) def reply(msg, chan=chan): + """sends a message to the current channel/user with a prefix""" if chan == nick: # PMs don't need prefixes conn.msg(chan, msg) else: conn.msg(chan, u'(' + nick + u') ' + msg) def action(msg, chan=chan): + """sends an action to the current channel/user or a specific channel/user""" conn.msg(chan, u"\x01{} {}\x01".format("ACTION", msg)) - def notice(msg, nick=nick): - conn.cmd('NOTICE', [nick, msg]) + def notice(msg, chan=chan): + """sends a notice to the current channel/user or a specific channel/user""" + conn.cmd('NOTICE', [chan, msg]) dict.__init__(self, conn=conn, raw=raw, prefix=prefix, command=command, params=params, nick=nick, user=user, host=host, mask=mask, paraml=paraml, msg=msg, server=conn.server, chan=chan, - notice=notice, say=say, reply=reply, pm=pm, bot=bot, + notice=notice, say=say, reply=reply, msg=msg, bot=bot, action=action, lastparam=paraml[-1]) # make dict keys accessible as attributes