Added configurables for smileys and frowns.

This commit is contained in:
Jeremy Fincher 2004-01-06 03:58:48 +00:00
parent 85e0783cb9
commit 0d25243fb0

View File

@ -63,12 +63,13 @@ except ImportError:
raise callbacks.Error, 'You need to have PySQLite installed to use this ' \ raise callbacks.Error, 'You need to have PySQLite installed to use this ' \
'plugin. Download it at <http://pysqlite.sf.net/>' 'plugin. Download it at <http://pysqlite.sf.net/>'
def SmileyType(s):
smileys = (':)', ';)', ':]', ':-)', ':-D', ':D', ':P', ':p', '(=', '=)') try:
frowns = (':|', ':-/', ':-\\', ':\\', ':/', ':(', ':-(', ':\'(') L = configurable.SpaceSeparatedStrListType(s)
return re.compile('|'.join(imap(re.escape, L)))
smileyre = re.compile('|'.join(imap(re.escape, smileys))) except configurable.Error:
frownre = re.compile('|'.join(imap(re.escape, frowns))) raise configurable.Error, 'Value must be a space-separated list of ' \
'smileys or frowns.'
class ChannelDB(plugins.ChannelDBHandler, class ChannelDB(plugins.ChannelDBHandler,
configurable.Mixin, configurable.Mixin,
@ -81,7 +82,15 @@ class ChannelDB(plugins.ChannelDBHandler,
relaying between channels on a network."""), relaying between channels on a network."""),
('wordstats-top-n', configurable.IntType, 3, ('wordstats-top-n', configurable.IntType, 3,
"""Determines the maximum number of top users to show for a given """Determines the maximum number of top users to show for a given
wordstat when you request the wordstats for a particular word.""")] wordstat when you request the wordstats for a particular word."""),
('smileys', SmileyType, SmileyType(':) ;) ;] :-) :-D :D :P :p (= =)'),
"""Determines what words count as smileys for the purpose of keeping
statistics on the number of smileys each user has sent to the
channel."""),
('frowns', SmileyType, SmileyType(':| :-/ :-\\ :\\ :/ :( :-( :\'('),
"""Determines what words count as frowns for the purpose of keeping
statistics on the number of frowns each user has sent ot the
channel."""),]
) )
def __init__(self): def __init__(self):
callbacks.Privmsg.__init__(self) callbacks.Privmsg.__init__(self)
@ -213,8 +222,8 @@ class ChannelDB(plugins.ChannelDBHandler,
chars = len(s) chars = len(s)
words = len(s.split()) words = len(s.split())
isAction = ircmsgs.isAction(msg) isAction = ircmsgs.isAction(msg)
frowns = len(frownre.findall(s)) frowns = len(self.configurables.get('frowns', channel).findall(s))
smileys = len(smileyre.findall(s)) smileys = len(self.configurables.get('smileys', channel).findall(s))
s = ircmsgs.prettyPrint(msg) s = ircmsgs.prettyPrint(msg)
cursor.execute("""UPDATE channel_stats cursor.execute("""UPDATE channel_stats
SET smileys=smileys+%s, SET smileys=smileys+%s,