Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/upstream/master' into config-set
Browse files Browse the repository at this point in the history
  • Loading branch information
ari-koivula committed Jun 9, 2013
2 parents b788e7e + 6eb85cf commit 30b27ad
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 313 deletions.
27 changes: 14 additions & 13 deletions bugzilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from lxml import etree
import re
from willie import web
from willie.module import rule
import urllib
import urllib2

Expand All @@ -28,27 +29,30 @@ def configure(config):
'Domain:')


def setup(willie):
def setup(bot):
regexes = []
if not (willie.config.has_option('bugzilla', 'domains')
and willie.config.bugzilla.get_list('domains')):
if not (bot.config.has_option('bugzilla', 'domains')
and bot.config.bugzilla.get_list('domains')):
return
if not willie.memory.contains('url_callbacks'):
willie.memory['url_callbacks'] = {}
if not bot.memory.contains('url_callbacks'):
bot.memory['url_callbacks'] = {}

domains = '|'.join(willie.config.bugzilla.get_list('domains'))
domains = '|'.join(bot.config.bugzilla.get_list('domains'))
regex = re.compile((r'https?://(%s)'
'(/show_bug.cgi\?\S*?)'
'(id=\d+)')
% domains)
willie.memory['url_callbacks'][regex] = show_bug
bot.memory['url_callbacks'][regex] = show_bug


def show_bug(willie, trigger, match=None):
@rule(r'.*https?://(\S+?)'
'(/show_bug.cgi\?\S*?)'
'(id=\d+).*')
def show_bug(bot, trigger, match=None):
"""Show information about a Bugzilla bug."""
match = match or trigger
domain = match.group(1)
if domain not in willie.config.bugzilla.get_list('domains'):
if domain not in bot.config.bugzilla.get_list('domains'):
return
url = 'https://%s%sctype=xml&%s' % match.groups()
data = web.get(url)
Expand All @@ -70,7 +74,4 @@ def show_bug(willie, trigger, match=None):
(bug.find('priority').text + ' ' + bug.find('bug_severity').text),
status, bug.find('assigned_to').text, bug.find('creation_ts').text,
bug.find('delta_ts').text)
willie.say(message)
show_bug.rule = (r'.*https?://(\S+?)'
'(/show_bug.cgi\?\S*?)'
'(id=\d+).*')
bot.say(message)
43 changes: 20 additions & 23 deletions calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"""

import re
import willie.web as web
from willie import web
from willie.module import command, commands, example
from socket import timeout
import string
import HTMLParser
Expand All @@ -35,39 +36,41 @@ def calculate(q):
return 'Sorry, no result.'


def c(willie, trigger):
@commands('c', 'calc')
@example('.c 5 + 3')
def c(bot, trigger):
"""Google calculator."""
if not trigger.group(2):
return willie.reply("Nothing to calculate.")
return bot.reply("Nothing to calculate.")
result = calculate(trigger.group(2))
willie.reply(result)
c.commands = ['c', 'calc']
c.example = '.c 5 + 3'
bot.reply(result)


def py(willie, trigger):
@command('py')
@example('.py len([1,2,3])')
def py(bot, trigger):
"""Evaluate a Python expression."""
query = trigger.group(2)
uri = 'http://tumbolia.appspot.com/py/'
answer = web.get(uri + web.quote(query))
if answer:
willie.say(answer)
bot.say(answer)
else:
willie.reply('Sorry, no result.')
py.commands = ['py']
py.example = '.py len([1,2,3])'
bot.reply('Sorry, no result.')


def wa(willie, trigger):
@commands('wa', 'wolfram')
@example('.wa circumference of the sun * pi')
def wa(bot, trigger):
"""Wolfram Alpha calculator"""
if not trigger.group(2):
return willie.reply("No search term.")
return bot.reply("No search term.")
query = trigger.group(2)
uri = 'http://tumbolia.appspot.com/wa/'
try:
answer = web.get(uri + web.quote(query.replace('+', '%2B')), 45)
except timeout as e:
return willie.say('[WOLFRAM ERROR] Request timed out')
return bot.say('[WOLFRAM ERROR] Request timed out')
if answer:
answer = answer.decode('string_escape')
answer = HTMLParser.HTMLParser().unescape(answer)
Expand All @@ -81,17 +84,11 @@ def wa(willie, trigger):
answer = answer.replace('\:' + char_code, char)
waOutputArray = string.split(answer, ";")
if(len(waOutputArray) < 2):
willie.say('[WOLFRAM ERROR]' + answer)
bot.say('[WOLFRAM ERROR]' + answer)
else:

willie.say('[WOLFRAM] ' + waOutputArray[0] + " = "
bot.say('[WOLFRAM] ' + waOutputArray[0] + " = "
+ waOutputArray[1])
waOutputArray = []
else:
willie.reply('Sorry, no result.')
wa.commands = ['wa', 'wolfram']
wa.example = '.wa circumference of the sun * pi'
wa.commands = ['wa']

if __name__ == '__main__':
print __doc__.strip()
bot.reply('Sorry, no result.')
119 changes: 0 additions & 119 deletions oblique.py

This file was deleted.

Loading

0 comments on commit 30b27ad

Please sign in to comment.