Skip to content

Commit

Permalink
[isup, ping, rand, tell, tld, wiktionary] s/willie/bot for 4.0
Browse files Browse the repository at this point in the history
Issue #276
  • Loading branch information
embolalia committed Jun 22, 2013
1 parent d99c07f commit a33903f
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 58 deletions.
12 changes: 6 additions & 6 deletions willie/modules/isup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
12 changes: 6 additions & 6 deletions willie/modules/ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '!')
8 changes: 4 additions & 4 deletions willie/modules/rand.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

@commands('rand')
@example('.rand 1 100')
def rand(willie, trigger):
def rand(bot, trigger):
"""Generates a random integer between <arg1> and <arg2>."""
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)
Expand All @@ -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))
Expand All @@ -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))
70 changes: 35 additions & 35 deletions willie/modules/tell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
6 changes: 3 additions & 3 deletions willie/modules/tld.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)<td><a href="\S+" title="\S+">\.{0}</a></td>\n(<td><a href=".*</a></td>\n)?<td>([A-Za-z0-9].*?)</td>\n<td>(.*)</td>\n<td[^>]*>(.*?)</td>\n<td[^>]*>(.*?)</td>\n'
Expand All @@ -40,7 +40,7 @@ def gettld(willie, trigger):
desc = desc[:400] + "..."
reply = "%s -- %s. IDN: %s, DNSSEC: %s" % (matches[1], desc,
matches[3], matches[4])
willie.reply(reply)
bot.reply(reply)
else:
search = r'<td><a href="\S+" title="\S+">.{0}</a></td>\n<td><span class="flagicon"><img.*?\">(.*?)</a></td>\n<td[^>]*>(.*?)</td>\n<td[^>]*>(.*?)</td>\n<td[^>]*>(.*?)</td>\n<td[^>]*>(.*?)</td>\n<td[^>]*>(.*?)</td>\n'
search = search.format(unicode(trigger.group(2)))
Expand All @@ -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)
8 changes: 4 additions & 4 deletions willie/modules/wiktionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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'))

0 comments on commit a33903f

Please sign in to comment.