Rewrote parts of Webcal for semantic clean-ness, added 'ir' to the moster regex of Bugtracker
This commit is contained in:
parent
d7f48ce648
commit
2cb95524ec
|
@ -159,7 +159,7 @@ class Bugtracker(callbacks.PluginRegexp):
|
||||||
list = wrap(list, [additional('text')])
|
list = wrap(list, [additional('text')])
|
||||||
|
|
||||||
def bugSnarfer(self, irc, msg, match):
|
def bugSnarfer(self, irc, msg, match):
|
||||||
r"""\b(?P<bt>(([a-z]+)?\s+bugs?|[a-z]+))\s+#?(?P<bug>\d+(?!\d*\.\d+)((,|\s*(and|en|et|und))\s*#?\d+(?!\d*\.\d+))*)"""
|
r"""\b(?P<bt>(([a-z]+)?\s+bugs?|[a-z]+))\s+#?(?P<bug>\d+(?!\d*\.\d+)((,|\s*(and|en|et|und|ir))\s*#?\d+(?!\d*\.\d+))*)"""
|
||||||
if not self.registryValue('bugSnarfer', msg.args[0]):
|
if not self.registryValue('bugSnarfer', msg.args[0]):
|
||||||
return
|
return
|
||||||
# Don't double on commands
|
# Don't double on commands
|
||||||
|
|
|
@ -22,6 +22,8 @@ def configure(advanced):
|
||||||
Webcal = conf.registerPlugin('Webcal')
|
Webcal = conf.registerPlugin('Webcal')
|
||||||
conf.registerChannelValue(conf.supybot.plugins.Webcal, 'url',
|
conf.registerChannelValue(conf.supybot.plugins.Webcal, 'url',
|
||||||
registry.String('',"""Webcal URL for the channel"""))
|
registry.String('',"""Webcal URL for the channel"""))
|
||||||
|
conf.registerChannelValue(conf.supybot.plugins.Webcal, 'filter',
|
||||||
|
registry.String('',"""What to filter on in the ical feed"""))
|
||||||
conf.registerChannelValue(conf.supybot.plugins.Webcal, 'topic',
|
conf.registerChannelValue(conf.supybot.plugins.Webcal, 'topic',
|
||||||
registry.String('',"""Topic template"""))
|
registry.String('',"""Topic template"""))
|
||||||
conf.registerGlobalValue(conf.supybot.plugins.Webcal, 'defaultChannel',
|
conf.registerGlobalValue(conf.supybot.plugins.Webcal, 'defaultChannel',
|
||||||
|
|
107
Webcal/plugin.py
107
Webcal/plugin.py
|
@ -66,63 +66,46 @@ class Webcal(callbacks.Plugin):
|
||||||
self.cache.clear()
|
self.cache.clear()
|
||||||
|
|
||||||
def _filter(self, event, channel, now):
|
def _filter(self, event, channel, now):
|
||||||
#channel = '#ubuntu-meeting' # Testing hack
|
fword = self.registryValue('filter', channel)
|
||||||
if channel.lower() not in event.raw_data.lower():
|
if fword.lower() not in event.raw_data.lower():
|
||||||
return False
|
return False
|
||||||
delta = event.endDate - now
|
delta = event.endDate - now
|
||||||
return delta.days >= 0 or (delta.days == -1 and abs(delta).seconds < 30 * 60)
|
return delta.days >= 0 or (delta.days == -1 and abs(delta).seconds < 30 * 60)
|
||||||
|
|
||||||
def _gettopic(self, url, channel, do_update=False, only_update=False, timezone = None, no_topic=False):
|
def _gettopic(self, url, channel, timezone=None, no_topic=False, num_events=6):
|
||||||
if do_update or url not in self.cache.keys():
|
|
||||||
data = utils.web.getUrl(url)
|
|
||||||
parser = ical.ICalReader(data)
|
|
||||||
#parser = ical.ICalReader(ical.sample)
|
|
||||||
self.cache[url] = parser.events
|
|
||||||
if not only_update:
|
|
||||||
now = datetime.datetime.now(pytz.UTC)
|
|
||||||
events = filter(lambda x: self._filter(x,channel,now),self.cache[url])[:6]
|
|
||||||
preamble = ''
|
|
||||||
if len(events):
|
|
||||||
# The standard slack of 30 minutes after the meeting will be an
|
|
||||||
# error if there are 2 conscutive meetings.
|
|
||||||
if len(events) > 1 and events[1].startDate < now:
|
|
||||||
events = events[1:]
|
|
||||||
ev0 = events[0]
|
|
||||||
delta = abs(ev0.startDate - now)
|
|
||||||
if ev0.startDate < now or (delta.days == 0 and delta.seconds < 10 * 60):
|
|
||||||
preamble = 'Current meeting: %s | ' % ev0.summary.replace('Meeting','').strip()
|
|
||||||
events = events[1:]
|
|
||||||
events = map(lambda x: _event_to_string(x,timezone), events)
|
|
||||||
template = self.registryValue('topic', channel)
|
|
||||||
newtopic = ' | '.join(events).replace(' Meeting','')
|
|
||||||
if '%s' in template and not no_topic:
|
|
||||||
newtopic = template % str(newtopic)
|
|
||||||
return preamble + newtopic
|
|
||||||
|
|
||||||
def _nextmeeting(self, url, channel, timezone):
|
|
||||||
if url not in self.cache.keys():
|
if url not in self.cache.keys():
|
||||||
data = utils.web.getUrl(url)
|
self._refresh_cache(url)
|
||||||
parser = ical.ICalReader(data)
|
|
||||||
#parser = ical.ICalReader(ical.sample)
|
|
||||||
self.cache[url] = parser.events
|
|
||||||
now = datetime.datetime.now(pytz.UTC)
|
now = datetime.datetime.now(pytz.UTC)
|
||||||
events = filter(lambda x: self._filter(x,channel,now),self.cache[url])[:6]
|
events = filter(lambda x: self._filter(x,channel,now),self.cache[url])[:num_events]
|
||||||
preamble = ''
|
preamble = ''
|
||||||
if len(events):
|
if len(events):
|
||||||
# The standard slack of 30 minutes after the meeting will be an
|
# The standard slack of 30 minutes after the meeting will be an
|
||||||
# error if there are 2 conscutive meetings.
|
# error if there are 2 conscutive meetings, so remove the first
|
||||||
|
# one in that case
|
||||||
if len(events) > 1 and events[1].startDate < now:
|
if len(events) > 1 and events[1].startDate < now:
|
||||||
events = events[1:]
|
events = events[1:]
|
||||||
ev0 = events[0]
|
ev0 = events[0]
|
||||||
delta = abs(ev0.startDate - now)
|
delta = abs(ev0.startDate - now)
|
||||||
if ev0.startDate < now or (delta.days == 0 and delta.seconds < 10 * 60):
|
if ev0.startDate < now or (delta.days == 0 and delta.seconds < 10 * 60):
|
||||||
return ' - Current meeting: %s ' % ev0.summary.replace('Meeting','').strip()
|
preamble = 'Current meeting: %s' % ev0.summary.replace('Meeting','').strip()
|
||||||
return ' - Next meeting: %s in %s' % (ev0.summary.replace('Meeting',''), diff(delta))
|
if num_events == 1:
|
||||||
return ''
|
return '%s in %s' % (preamble, diff(delta))
|
||||||
|
events = events[1:]
|
||||||
|
preamble += ' | '
|
||||||
|
# n_e = 1 -> next meeting
|
||||||
|
# n_t = T -> n_t
|
||||||
|
if num_events == 1:
|
||||||
|
if not events:
|
||||||
|
return "No meetings scheduled"
|
||||||
|
return 'Next meeting: %s in %s' % (events[0].summary.replace('Meeting','').strip(), diff(delta))
|
||||||
|
events = map(lambda x: _event_to_string(x,timezone), events)
|
||||||
|
newtopic = ' | '.join(events).replace(' Meeting','')
|
||||||
|
template = self.registryValue('topic', channel)
|
||||||
|
if '%s' in template and not no_topic:
|
||||||
|
newtopic = template % str(newtopic)
|
||||||
|
return preamble + newtopic
|
||||||
|
|
||||||
def _autotopics(self):
|
def _autotopics(self):
|
||||||
if not self.irc:
|
|
||||||
return
|
|
||||||
for c in self.irc.state.channels:
|
for c in self.irc.state.channels:
|
||||||
url = self.registryValue('url', c)
|
url = self.registryValue('url', c)
|
||||||
if url:
|
if url:
|
||||||
|
@ -130,19 +113,26 @@ class Webcal(callbacks.Plugin):
|
||||||
if newtopic and not (newtopic.strip() == self.irc.state.getTopic(c).strip()):
|
if newtopic and not (newtopic.strip() == self.irc.state.getTopic(c).strip()):
|
||||||
self.irc.queueMsg(ircmsgs.topic(c, newtopic))
|
self.irc.queueMsg(ircmsgs.topic(c, newtopic))
|
||||||
|
|
||||||
def _refresh_cache(self):
|
def _refresh_cache(self,url=None):
|
||||||
if not self.lastIrc:
|
if url:
|
||||||
return
|
data = utils.web.getUrl(url)
|
||||||
for c in self.lastIrc.state.channels:
|
parser = ical.ICalReader(data)
|
||||||
url = self.registryValue('url', c)
|
self.cache[url] = parser.events
|
||||||
if url:
|
else:
|
||||||
self._gettopic(url, c, True, true)
|
for c in self.irc.state.channels:
|
||||||
|
url = self.registryValue('url', c)
|
||||||
|
if url:
|
||||||
|
data = utils.web.getUrl(url)
|
||||||
|
parser = ical.ICalReader(data)
|
||||||
|
self.cache[url] = parser.events
|
||||||
|
|
||||||
def topic(self, irc, msg, args):
|
def topic(self, irc, msg, args):
|
||||||
url = self.registryValue('url', msg.args[0])
|
url = self.registryValue('url', msg.args[0])
|
||||||
if not url:
|
if not url:
|
||||||
return
|
return
|
||||||
newtopic = self._gettopic(url, msg.args[0], True)
|
self._refresh_cache(url)
|
||||||
|
newtopic = self._gettopic(url, msg.args[0])
|
||||||
|
# Only change topic if it actually is different!
|
||||||
if not (newtopic.strip() == irc.state.getTopic(msg.args[0]).strip()):
|
if not (newtopic.strip() == irc.state.getTopic(msg.args[0]).strip()):
|
||||||
irc.queueMsg(ircmsgs.topic(msg.args[0], newtopic))
|
irc.queueMsg(ircmsgs.topic(msg.args[0], newtopic))
|
||||||
topic = wrap(topic)
|
topic = wrap(topic)
|
||||||
|
@ -182,7 +172,6 @@ class Webcal(callbacks.Plugin):
|
||||||
now = datetime.datetime.now(pytz.UTC)
|
now = datetime.datetime.now(pytz.UTC)
|
||||||
if not tz:
|
if not tz:
|
||||||
tz = 'utc'
|
tz = 'utc'
|
||||||
#irc.reply('Current time in UTC: %s' % now.strftime("%B %d %Y, %H:%M:%S"))
|
|
||||||
tzs = filter(lambda x: self._tzfilter(x.lower(),tz.lower()), pytz.all_timezones)
|
tzs = filter(lambda x: self._tzfilter(x.lower(),tz.lower()), pytz.all_timezones)
|
||||||
if not tzs or 'gmt' in tz.lower():
|
if not tzs or 'gmt' in tz.lower():
|
||||||
irc.error('Unknown timezone: %s - Full list: http://bugbot.ubuntulinux.nl/timezones.html' % tz)
|
irc.error('Unknown timezone: %s - Full list: http://bugbot.ubuntulinux.nl/timezones.html' % tz)
|
||||||
|
@ -193,20 +182,22 @@ class Webcal(callbacks.Plugin):
|
||||||
c = self.registryValue('defaultChannel')
|
c = self.registryValue('defaultChannel')
|
||||||
if not c:
|
if not c:
|
||||||
return
|
return
|
||||||
#c = "#ubuntu-meeting"
|
meeting = ''
|
||||||
url = self.registryValue('url', c)
|
url = self.registryValue('url', c)
|
||||||
if not url:
|
if url:
|
||||||
meeting = ''
|
meeting = self._gettopic(url, c, timezone=tzs[0], no_topic = True, num_events = 1)
|
||||||
else:
|
if meeting:
|
||||||
meeting = self._nextmeeting(url, c, tzs[0])
|
meeting = ' - ' + meeting
|
||||||
irc.reply('Current time in %s: %s%s' % (tzs[0],now.astimezone(pytz.timezone(tzs[0])).strftime("%B %d %Y, %H:%M:%S"),meeting))
|
irc.reply('Current time in %s: %s%s' % (tzs[0],
|
||||||
|
now.astimezone(pytz.timezone(tzs[0])).strftime("%B %d %Y, %H:%M:%S"),meeting))
|
||||||
now = wrap(now, [additional('text')])
|
now = wrap(now, [additional('text')])
|
||||||
time = now
|
time = now
|
||||||
|
|
||||||
|
# Warn people that you manage the topic
|
||||||
def doTopic(self, irc, msg):
|
def doTopic(self, irc, msg):
|
||||||
url = self.registryValue('url', msg.args[0])
|
url = self.registryValue('url', msg.args[0])
|
||||||
if not url:
|
if not url:
|
||||||
return
|
return
|
||||||
irc.queueMsg(ircmsgs.privmsg(msg.nick, "The topic of %s is managed by me and filled with the contents of %s - please don't change manually" % (msg.args[0],url)))
|
irc.reply("The topic of %s is managed by me and filled with the contents of %s - please don't change manually" % (msg.args[0],url), private=True)
|
||||||
|
|
||||||
Class = Webcal
|
Class = Webcal
|
||||||
|
|
Loading…
Reference in New Issue