From a33903f0207dd7b7f25df01bb7813761a51d7bf8 Mon Sep 17 00:00:00 2001 From: Edward Powell Date: Sat, 22 Jun 2013 16:49:54 -0400 Subject: [PATCH] [isup, ping, rand, tell, tld, wiktionary] s/willie/bot for 4.0 Issue #276 --- willie/modules/isup.py | 12 +++---- willie/modules/ping.py | 12 +++---- willie/modules/rand.py | 8 ++--- willie/modules/tell.py | 70 ++++++++++++++++++------------------ willie/modules/tld.py | 6 ++-- willie/modules/wiktionary.py | 8 ++--- 6 files changed, 58 insertions(+), 58 deletions(-) diff --git a/willie/modules/isup.py b/willie/modules/isup.py index 0d51378bee..9d5e74be33 100644 --- a/willie/modules/isup.py +++ b/willie/modules/isup.py @@ -12,25 +12,25 @@ @commands('isup') -def isup(willie, trigger): +def isup(bot, trigger): """isup.me website status checker""" site = trigger.group(2) if not site: - return willie.reply("What site do you want to check?") + return bot.reply("What site do you want to check?") if site[:6] != 'http://' and site[:7] != 'https://': if '://' in site: protocol = site.split('://')[0] + '://' - return willie.reply("Try it again without the %s" % protocol) + return bot.reply("Try it again without the %s" % protocol) else: site = 'http://' + site try: response = web.get(site) except Exception as e: - willie.say(site + ' looks down from here.') + bot.say(site + ' looks down from here.') return if response: - willie.say(site + ' looks fine to me.') + bot.say(site + ' looks fine to me.') else: - willie.say(site + ' is down from here.') + bot.say(site + ' is down from here.') diff --git a/willie/modules/ping.py b/willie/modules/ping.py index 20c1a71702..f142ede194 100644 --- a/willie/modules/ping.py +++ b/willie/modules/ping.py @@ -9,22 +9,22 @@ @rule(r'(?i)(hi|hello|hey) $nickname[ \t]*$') -def hello(willie, trigger): +def hello(bot, trigger): if trigger.owner: greeting = random.choice(('Fuck off,', 'Screw you,', 'Go away')) else: greeting = random.choice(('Hi', 'Hey', 'Hello')) punctuation = random.choice(('', '!')) - willie.say(greeting + ' ' + trigger.nick + punctuation) + bot.say(greeting + ' ' + trigger.nick + punctuation) @rule(r'(?i)(Fuck|Screw) you, $nickname[ \t]*$') -def rude(willie, trigger): - willie.say('Watch your mouth, ' + trigger.nick + ', or I\'ll tell your mother!') +def rude(bot, trigger): + bot.say('Watch your mouth, ' + trigger.nick + ', or I\'ll tell your mother!') @rule('$nickname!') @priority('high') @thread(False) -def interjection(willie, trigger): - willie.say(trigger.nick + '!') +def interjection(bot, trigger): + bot.say(trigger.nick + '!') diff --git a/willie/modules/rand.py b/willie/modules/rand.py index 10a0a4c0d1..409ac0e264 100644 --- a/willie/modules/rand.py +++ b/willie/modules/rand.py @@ -13,10 +13,10 @@ @commands('rand') @example('.rand 1 100') -def rand(willie, trigger): +def rand(bot, trigger): """Generates a random integer between and .""" if not trigger.group(2): - willie.say("I'm sorry, " + str(trigger.nick) + ", but you must enter at least one number.") + bot.say("I'm sorry, " + str(trigger.nick) + ", but you must enter at least one number.") else: random.seed() li_integers = trigger.group(2) @@ -31,7 +31,7 @@ def rand(willie, trigger): a = li_integers_str a = int(a) randinte = random.randint(0, a) - willie.say(str(trigger.nick) + ": your random integer is: " + str(randinte)) + bot.say(str(trigger.nick) + ": your random integer is: " + str(randinte)) else: a, b = li_integers.split() a = re.sub(r'\D', '', str(a)) @@ -42,4 +42,4 @@ def rand(willie, trigger): randinte = random.randint(a, b) else: randinte = random.randint(b, a) - willie.say(str(trigger.nick) + ": your random integer is: " + str(randinte)) + bot.say(str(trigger.nick) + ": your random integer is: " + str(randinte)) diff --git a/willie/modules/tell.py b/willie/modules/tell.py index eb758e49ac..8df054d161 100644 --- a/willie/modules/tell.py +++ b/willie/modules/tell.py @@ -73,12 +73,12 @@ def setup(self): self.memory['reminders'] = loadReminders(self.tell_filename, self.memory['tell_lock']) -def get_user_time(willie, nick): +def get_user_time(bot, nick): tz = 'UTC' tformat = None - if willie.db and nick in willie.db.preferences: - tz = willie.db.preferences.get(nick, 'tz') or 'UTC' - tformat = willie.db.preferences.get(nick, 'time_format') + if bot.db and nick in bot.db.preferences: + tz = bot.db.preferences.get(nick, 'tz') or 'UTC' + tformat = bot.db.preferences.get(nick, 'time_format') if tz not in pytz.all_timezones_set: tz = 'UTC' return (pytz.timezone(tz.strip()), tformat or '%Y-%m-%d %H:%M:%S %Z') @@ -97,86 +97,86 @@ def f_remind(willie, trigger): tellee = Nick(tellee.rstrip('.,:;')) - if not os.path.exists(willie.tell_filename): + if not os.path.exists(bot.tell_filename): return if len(tellee) > 20: - return willie.reply('That nickname is too long.') - if tellee == willie.nick: - return willie.reply("I'm here now, you can tell me whatever you want!") + return bot.reply('That nickname is too long.') + if tellee == bot.nick: + return bot.reply("I'm here now, you can tell me whatever you want!") - tz, tformat = get_user_time(willie, tellee) + tz, tformat = get_user_time(bot, tellee) print tellee, tz, tformat timenow = datetime.datetime.now(tz).strftime(tformat) - if not tellee in (Nick(teller), willie.nick, 'me'): - willie.memory['tell_lock'].acquire() + if not tellee in (Nick(teller), bot.nick, 'me'): + bot.memory['tell_lock'].acquire() try: - if not tellee in willie.memory['reminders']: - willie.memory['reminders'][tellee] = [(teller, verb, timenow, msg)] + if not tellee in bot.memory['reminders']: + bot.memory['reminders'][tellee] = [(teller, verb, timenow, msg)] else: - willie.memory['reminders'][tellee].append((teller, verb, timenow, msg)) + bot.memory['reminders'][tellee].append((teller, verb, timenow, msg)) finally: - willie.memory['tell_lock'].release() + bot.memory['tell_lock'].release() response = "I'll pass that on when %s is around." % tellee - willie.reply(response) + bot.reply(response) elif Nick(teller) == tellee: - willie.say('You can %s yourself that.' % verb) + bot.say('You can %s yourself that.' % verb) else: - willie.say("Hey, I'm not as stupid as Monty you know!") + bot.say("Hey, I'm not as stupid as Monty you know!") - dumpReminders(willie.tell_filename, willie.memory['reminders'], willie.memory['tell_lock']) # @@ tell + dumpReminders(bot.tell_filename, bot.memory['reminders'], bot.memory['tell_lock']) # @@ tell -def getReminders(willie, channel, key, tellee): +def getReminders(bot, channel, key, tellee): lines = [] template = "%s: %s <%s> %s %s %s" today = time.strftime('%d %b', time.gmtime()) - willie.memory['tell_lock'].acquire() + bot.memory['tell_lock'].acquire() try: - for (teller, verb, datetime, msg) in willie.memory['reminders'][key]: + for (teller, verb, datetime, msg) in bot.memory['reminders'][key]: if datetime.startswith(today): datetime = datetime[len(today) + 1:] lines.append(template % (tellee, datetime, teller, verb, tellee, msg)) try: - del willie.memory['reminders'][key] + del bot.memory['reminders'][key] except KeyError: - willie.msg(channel, 'Er...') + bot.msg(channel, 'Er...') finally: - willie.memory['tell_lock'].release() + bot.memory['tell_lock'].release() return lines @rule('(.*)') @priority('low') -def message(willie, trigger): +def message(bot, trigger): tellee = trigger.nick channel = trigger.sender - if not os.path.exists(willie.tell_filename): + if not os.path.exists(bot.tell_filename): return reminders = [] - remkeys = list(reversed(sorted(willie.memory['reminders'].keys()))) + remkeys = list(reversed(sorted(bot.memory['reminders'].keys()))) for remkey in remkeys: if not remkey.endswith('*') or remkey.endswith(':'): if tellee == remkey: - reminders.extend(getReminders(willie, channel, remkey, tellee)) + reminders.extend(getReminders(bot, channel, remkey, tellee)) elif tellee.startswith(remkey.rstrip('*:')): - reminders.extend(getReminders(willie, channel, remkey, tellee)) + reminders.extend(getReminders(bot, channel, remkey, tellee)) for line in reminders[:maximum]: - willie.say(line) + bot.say(line) if reminders[maximum:]: - willie.say('Further messages sent privately') + bot.say('Further messages sent privately') for line in reminders[maximum:]: - willie.msg(tellee, line) + bot.msg(tellee, line) - if len(willie.memory['reminders'].keys()) != remkeys: - dumpReminders(willie.tell_filename, willie.memory['reminders'], willie.memory['tell_lock']) # @@ tell + if len(bot.memory['reminders'].keys()) != remkeys: + dumpReminders(bot.tell_filename, bot.memory['reminders'], bot.memory['tell_lock']) # @@ tell diff --git a/willie/modules/tld.py b/willie/modules/tld.py index e13134f1de..eb3f22d72d 100644 --- a/willie/modules/tld.py +++ b/willie/modules/tld.py @@ -17,7 +17,7 @@ @commands('tld') @example('.tld ru') -def gettld(willie, trigger): +def gettld(bot, trigger): """Show information about the given Top Level Domain.""" page = web.get(uri) search = r'(?i)\.{0}\n(.{0}\n(.*?)\n]*>(.*?)\n]*>(.*?)\n]*>(.*?)\n]*>(.*?)\n]*>(.*?)\n' search = search.format(unicode(trigger.group(2))) @@ -59,4 +59,4 @@ def gettld(willie, trigger): reply = "%s (%s, %s). IDN: %s, DNSSEC: %s, SLD: %s" % (dict_val["country"], dict_val["expl"], dict_val["notes"], dict_val["idn"], dict_val["dnssec"], dict_val["sld"]) else: reply = "No matches found for TLD: {0}".format(unicode(trigger.group(2))) - willie.reply(reply) + bot.reply(reply) diff --git a/willie/modules/wiktionary.py b/willie/modules/wiktionary.py index 24fbd485a1..a5aa3d2a9e 100644 --- a/willie/modules/wiktionary.py +++ b/willie/modules/wiktionary.py @@ -77,16 +77,16 @@ def format(word, definitions, number=2): @commands('wt', 'define', 'dict') @example('.wt bailiwick') -def wiktionary(willie, trigger): +def wiktionary(bot, trigger): """Look up a word on Wiktionary.""" word = trigger.group(2) if word is None: - willie.reply('You must tell me what to look up!') + bot.reply('You must tell me what to look up!') return etymology, definitions = wikt(word) if not definitions: - willie.say("Couldn't get any definitions for %s." % word) + bot.say("Couldn't get any definitions for %s." % word) return result = format(word, definitions) @@ -97,4 +97,4 @@ def wiktionary(willie, trigger): if len(result) > 300: result = result[:295] + '[...]' - willie.say(result.decode('utf8')) + bot.say(result.decode('utf8'))