More refactoring! Break everything!

This commit is contained in:
Luke Rogers 2013-10-01 16:55:18 +13:00
parent 51c866de6d
commit 42a72f068e
6 changed files with 36 additions and 30 deletions

View File

@ -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]

View File

@ -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):

View File

@ -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']))

View File

@ -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:

View File

@ -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):
"?<word> -- Shows what data is associated with <word>."
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>"):
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)

View File

@ -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 <feed> -- Gets the first three items from the RSS feed <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)