report on karma keys
This commit is contained in:
parent
ca8798453c
commit
e64af1a0a1
@ -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."""
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user