diff --git a/core/irc.py b/core/irc.py index e075d4b..39c93ed 100755 --- a/core/irc.py +++ b/core/irc.py @@ -208,6 +208,12 @@ class IRC(object): """ makes the bot send a message to a user """ self.cmd("PRIVMSG", [target, text]) + def ctcp(self, target, ctcp_type, text): + """ makes the bot send a message to a user """ + text = u"\x01{} {}\x01".format(ctcp_type, target) + self.cmd("PRIVMSG", [target, text]) + + def cmd(self, command, params=None): if params: params[-1] = ':' + params[-1] diff --git a/core/main.py b/core/main.py index a2b3e78..dac6112 100755 --- a/core/main.py +++ b/core/main.py @@ -13,34 +13,34 @@ class Input(dict): if chan == conn.nick.lower(): # is a PM chan = nick - def say(msg): - """sends a message to the current channel/user""" - conn.msg(chan, msg) + def message(message, target=chan): + """sends a message to a specific or current channel/user""" + conn.msg(target, message) - def msg(msg, nick=nick): - """sends a message to a specific channel/user""" - conn.msg(nick, msg) - - def reply(msg, chan=chan): + def reply(message, target=chan): """sends a message to the current channel/user with a prefix""" - if chan == nick: # PMs don't need prefixes - conn.msg(chan, msg) + if target == nick: + conn.msg(target, message) else: - conn.msg(chan, u'(' + nick + u') ' + msg) + conn.msg(target, "({}) {}".format(nick, message)) - def action(msg, chan=chan): + def action(message, target=chan): """sends an action to the current channel/user or a specific channel/user""" - conn.msg(chan, u"\x01{} {}\x01".format("ACTION", msg)) + conn.ctcp(target, "ACTION", message) - def notice(msg, chan=chan): + def ctcp(message, ctcp_type, target=chan): + """sends an ctcp to the current channel/user or a specific channel/user""" + conn.ctcp(target, ctcp_type, message) + + def notice(message, target=chan): """sends a notice to the current channel/user or a specific channel/user""" - conn.cmd('NOTICE', [chan, msg]) + conn.cmd('NOTICE', [target, message]) 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, msg=msg, bot=bot, - action=action, lastparam=paraml[-1]) + notice=notice, message=message, reply=reply, bot=bot, + action=action, ctcp=ctcp, lastparam=paraml[-1]) # make dict keys accessible as attributes def __getattr__(self, key): diff --git a/plugins/bitcoin.py b/plugins/bitcoin.py index a644407..21290de 100755 --- a/plugins/bitcoin.py +++ b/plugins/bitcoin.py @@ -2,7 +2,7 @@ from util import http, hook @hook.command(autohelp=False) -def bitcoin(inp, say=None): +def bitcoin(inp, message=None): """bitcoin -- gets current exchange rate for bitcoins from mtgox""" data = http.get_json("https://data.mtgox.com/api/2/BTCUSD/money/ticker") data = data['data'] @@ -12,5 +12,5 @@ def bitcoin(inp, say=None): 'low': data['low']['display_short'].encode('ascii','ignore'), 'vol': data['vol']['display_short'].encode('ascii','ignore'), } - say("Current: \x0307{!s}\x0f - High: \x0307{!s}\x0f" + message("Current: \x0307{!s}\x0f - High: \x0307{!s}\x0f" " - Low: \x0307{!s}\x0f - Volume: {!s}".format(ticker['buy'],ticker['high'],ticker['low'],ticker['vol'])) diff --git a/plugins/correction.py b/plugins/correction.py index 0536eeb..e5b277e 100644 --- a/plugins/correction.py +++ b/plugins/correction.py @@ -2,7 +2,7 @@ from util import hook @hook.regex(r'^(s|S)/.*/.*/\S*$') -def correction(inp, say=None, input=None, notice=None, db=None): +def correction(inp, message=None, input=None, notice=None, db=None): splitinput = input.msg.split("/") if splitinput[3]: nick = splitinput[3] @@ -20,7 +20,7 @@ def correction(inp, say=None, input=None, notice=None, db=None): message = last_message[1].replace("\x01ACTION ", "/me ").replace("\x01", "") else: message = last_message[1] - say("{} meant to say: {}".format(nick, message.replace(find, "\x02" + replace + "\x02"))) + message("{} meant to say: {}".format(nick, message.replace(find, "\x02" + replace + "\x02"))) else: notice("{} can't be found in your last message".format(find)) else: diff --git a/plugins/factoids.py b/plugins/factoids.py index d2b27ec..a6610b2 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, action=None, conn=None, input=None): +def factoid(inp, message=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) @@ -145,11 +145,11 @@ def factoid(inp, say=None, db=None, bot=None, action=None, conn=None, input=None elif result.startswith(""): url = result[5:].strip() try: - say(http.get(url)) + message(http.get(url)) except http.HttpError: - say("Could not fetch URL.") + message("Could not fetch URL.") else: if prefix_on: - say("\x02[{}]:\x02 {}".format(factoid_id, result)) + message("\x02[{}]:\x02 {}".format(factoid_id, result)) else: - say(result) + message(result) diff --git a/plugins/rss.py b/plugins/rss.py index 734db0f..f7ed1c4 100644 --- a/plugins/rss.py +++ b/plugins/rss.py @@ -3,7 +3,7 @@ from util import hook, http, web, text @hook.command("feed") @hook.command -def rss(inp, say=None): +def rss(inp, message=None): """rss -- Gets the first three items from the RSS feed .""" limit = 3 @@ -31,10 +31,10 @@ def rss(inp, say=None): link = web.isgd(row["link"]) except (web.ShortenError, http.HTTPError, http.URLError): link = row["link"] - say(u"{} - {}".format(title, link)) + message(u"{} - {}".format(title, link)) @hook.command(autohelp=False) -def rb(inp, say=None): +def rb(inp, message=None): """rb -- Shows the latest Craftbukkit recommended build""" - rss("bukkit", say) + rss("bukkit", message)