Compare commits
4 Commits
ab0d738851
...
2f4156ce26
Author | SHA1 | Date | |
---|---|---|---|
2f4156ce26 | |||
e64af1a0a1 | |||
ca8798453c | |||
dc5f243608 |
@ -22,7 +22,8 @@ class Countdown(Plugin):
|
|||||||
new_reminder_regex = (r'remind\s+(?P<who>[^\s]+)\s+(?P<when_type>at|in|on)\s+(?P<when>.*?)\s+'
|
new_reminder_regex = (r'remind\s+(?P<who>[^\s]+)\s+(?P<when_type>at|in|on)\s+(?P<when>.*?)\s+'
|
||||||
r'(and\s+every\s+(?P<recurring_period>.*?)\s+)?'
|
r'(and\s+every\s+(?P<recurring_period>.*?)\s+)?'
|
||||||
r'(until\s+(?P<recurring_until>.*?)\s+)?'
|
r'(until\s+(?P<recurring_until>.*?)\s+)?'
|
||||||
r'(to|that|about)\s+(?P<text>.*)')
|
r'(to|that|about)\s+(?P<text>.*?)'
|
||||||
|
r'(?=\s+\("(?P<name>.*)"\)|$)')
|
||||||
|
|
||||||
def __init__(self, bot, connection, event):
|
def __init__(self, bot, connection, event):
|
||||||
"""Initialize some stuff."""
|
"""Initialize some stuff."""
|
||||||
@ -42,7 +43,7 @@ class Countdown(Plugin):
|
|||||||
|
|
||||||
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!countdown\s+list$',
|
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!countdown\s+list$',
|
||||||
self.handle_item_list, -20)
|
self.handle_item_list, -20)
|
||||||
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!countdown\s+(\S+)$',
|
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!countdown\s+(.+)$',
|
||||||
self.handle_item_detail, -20)
|
self.handle_item_detail, -20)
|
||||||
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], self.new_reminder_regex,
|
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], self.new_reminder_regex,
|
||||||
self.handle_new_reminder, -50)
|
self.handle_new_reminder, -50)
|
||||||
@ -99,9 +100,16 @@ class Countdown(Plugin):
|
|||||||
recurring_period = match.group('recurring_period')
|
recurring_period = match.group('recurring_period')
|
||||||
recurring_until = match.group('recurring_until')
|
recurring_until = match.group('recurring_until')
|
||||||
text = match.group('text')
|
text = match.group('text')
|
||||||
|
name = match.group('name')
|
||||||
log.debug("%s / %s / %s", who, when, text)
|
log.debug("%s / %s / %s", who, when, text)
|
||||||
|
|
||||||
|
if not name:
|
||||||
item_name = '{0:s}-{1:s}'.format(event.sender_nick, timezone.now().strftime('%s'))
|
item_name = '{0:s}-{1:s}'.format(event.sender_nick, timezone.now().strftime('%s'))
|
||||||
|
else:
|
||||||
|
if CountdownItem.objects.filter(name=name).count() > 0:
|
||||||
|
self.bot.reply(event, "item with name '{0:s}' already exists".format(name))
|
||||||
|
return 'NO MORE'
|
||||||
|
item_name = name
|
||||||
|
|
||||||
# parse when to send the notification
|
# parse when to send the notification
|
||||||
if when_type == 'in':
|
if when_type == 'in':
|
||||||
|
@ -14,11 +14,12 @@ logger = logging.getLogger(__name__)
|
|||||||
class Dice(Plugin):
|
class Dice(Plugin):
|
||||||
"""Roll simple or complex dice strings."""
|
"""Roll simple or complex dice strings."""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, bot, connection, event):
|
||||||
"""Set up the plugin."""
|
"""Set up the plugin."""
|
||||||
super(Dice, self).__init__()
|
|
||||||
self.roller = DiceRoller()
|
self.roller = DiceRoller()
|
||||||
|
|
||||||
|
super(Dice, self).__init__(bot, connection, event)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
"""Set up the handlers."""
|
"""Set up the handlers."""
|
||||||
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!roll\s+(.*)$',
|
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!roll\s+(.*)$',
|
||||||
|
@ -6,6 +6,7 @@ import re
|
|||||||
import irc.client
|
import irc.client
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.db.models import Count, Sum
|
||||||
|
|
||||||
from ircbot.lib import Plugin
|
from ircbot.lib import Plugin
|
||||||
from karma.models import KarmaKey, KarmaLogEntry
|
from karma.models import KarmaKey, KarmaLogEntry
|
||||||
@ -23,6 +24,9 @@ class Karma(Plugin):
|
|||||||
self.connection.add_global_handler('pubmsg', self.handle_chatter, -20)
|
self.connection.add_global_handler('pubmsg', self.handle_chatter, -20)
|
||||||
self.connection.add_global_handler('privmsg', self.handle_chatter, -20)
|
self.connection.add_global_handler('privmsg', self.handle_chatter, -20)
|
||||||
|
|
||||||
|
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'],
|
||||||
|
(r'^!karma\s+keyreport\s+(.*)'),
|
||||||
|
self.handle_keyreport, -20)
|
||||||
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'],
|
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'],
|
||||||
r'^!karma\s+rank\s+(.*)$',
|
r'^!karma\s+rank\s+(.*)$',
|
||||||
self.handle_rank, -20)
|
self.handle_rank, -20)
|
||||||
@ -42,6 +46,7 @@ class Karma(Plugin):
|
|||||||
self.connection.remove_global_handler('pubmsg', self.handle_chatter)
|
self.connection.remove_global_handler('pubmsg', self.handle_chatter)
|
||||||
self.connection.remove_global_handler('privmsg', self.handle_chatter)
|
self.connection.remove_global_handler('privmsg', self.handle_chatter)
|
||||||
|
|
||||||
|
self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_keyreport)
|
||||||
self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_rank)
|
self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_rank)
|
||||||
self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_report)
|
self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_report)
|
||||||
self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_stats)
|
self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_stats)
|
||||||
@ -102,6 +107,19 @@ class Karma(Plugin):
|
|||||||
except KarmaKey.DoesNotExist:
|
except KarmaKey.DoesNotExist:
|
||||||
return self.bot.reply(event, "i have not seen any karma for {0:s}".format(match.group(1)))
|
return self.bot.reply(event, "i have not seen any karma for {0:s}".format(match.group(1)))
|
||||||
|
|
||||||
|
def handle_keyreport(self, connection, event, match):
|
||||||
|
"""Provide report on a karma key."""
|
||||||
|
key = match.group(1).lower().rstrip()
|
||||||
|
try:
|
||||||
|
karma_key = KarmaKey.objects.get(key=key)
|
||||||
|
karmaers = KarmaLogEntry.objects.filter(key=karma_key)
|
||||||
|
karmaers = karmaers.values('nickmask').annotate(Sum('delta')).annotate(Count('delta')).order_by('-delta__count')
|
||||||
|
karmaers_list = [f"{irc.client.NickMask(x['nickmask']).nick} ({x['delta__count']}, {'+' if x['delta__sum'] >= 0 else ''}{x['delta__sum']})" for x in karmaers]
|
||||||
|
karmaers_list_str = ", ".join(karmaers_list[:10])
|
||||||
|
return self.bot.reply(event, f"most opinionated on {key}: {karmaers_list_str}")
|
||||||
|
except KarmaKey.DoesNotExist:
|
||||||
|
return self.bot.reply(event, "i have not seen any karma for {0:s}".format(match.group(1)))
|
||||||
|
|
||||||
def handle_report(self, connection, event, match):
|
def handle_report(self, connection, event, match):
|
||||||
"""Provide some karma reports."""
|
"""Provide some karma reports."""
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ class Weather(Plugin):
|
|||||||
if len(queryitems) <= 0:
|
if len(queryitems) <= 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
weather = weather_summary(queryitems[0])
|
weather = weather_summary(query)
|
||||||
weather_output = (f"Weather in {weather['location']}: {weather['current']['description']}. "
|
weather_output = (f"Weather in {weather['location']}: {weather['current']['description']}. "
|
||||||
f"{weather['current']['temp_F']}/{weather['current']['temp_C']}, "
|
f"{weather['current']['temp_F']}/{weather['current']['temp_C']}, "
|
||||||
f"feels like {weather['current']['feels_like_temp_F']}/"
|
f"feels like {weather['current']['feels_like_temp_F']}/"
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
"""Get results of weather queries."""
|
"""Get results of weather queries."""
|
||||||
import logging
|
import logging
|
||||||
import requests
|
import requests
|
||||||
|
from urllib.parse import quote
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -9,7 +10,7 @@ logger = logging.getLogger(__name__)
|
|||||||
def query_wttr_in(query):
|
def query_wttr_in(query):
|
||||||
"""Hit the wttr.in JSON API with the provided query."""
|
"""Hit the wttr.in JSON API with the provided query."""
|
||||||
logger.info(f"about to query wttr.in with '{query}'")
|
logger.info(f"about to query wttr.in with '{query}'")
|
||||||
response = requests.get(f'http://wttr.in/{query}?format=j1')
|
response = requests.get(f'http://wttr.in/{quote(query)}?format=j1')
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
|
||||||
weather_info = response.json()
|
weather_info = response.json()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user