dr.botzo/weather/ircplugin.py

40 lines
979 B
Python

import logging
from ircbot.lib import Plugin
from weather.lib import weather_summary
log = logging.getLogger('weather.ircplugin')
class Weather(Plugin):
"""Have IRC commands to do IRC things (join channels, quit, etc.)."""
def start(self):
"""Set up the handlers."""
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!weather\s+(.*)$',
self.handle_weather, -20)
super(Weather, self).start()
def stop(self):
"""Tear down handlers."""
self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_weather)
super(Weather, self).stop()
def handle_weather(self, connection, event, match):
query = match.group(1)
queryitems = query.split(" ")
if len(queryitems) <= 0:
return
return self.bot.reply(event, weather_summary(queryitems[0]))
plugin = Weather