mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Someone forgot to convert the testsuite when FunDB.num was switched to
FunDB.stats. Took care of that and updated to use the registry.
This commit is contained in:
parent
75b6da806e
commit
7336a4c9ad
@ -45,6 +45,8 @@ import string
|
|||||||
import os.path
|
import os.path
|
||||||
from itertools import imap
|
from itertools import imap
|
||||||
|
|
||||||
|
import registry
|
||||||
|
|
||||||
import conf
|
import conf
|
||||||
import ircdb
|
import ircdb
|
||||||
import utils
|
import utils
|
||||||
@ -53,7 +55,6 @@ import ircmsgs
|
|||||||
import ircutils
|
import ircutils
|
||||||
import privmsgs
|
import privmsgs
|
||||||
import callbacks
|
import callbacks
|
||||||
import configurable
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import sqlite
|
import sqlite
|
||||||
@ -84,26 +85,24 @@ tableCreateStatements = {
|
|||||||
)""",),
|
)""",),
|
||||||
}
|
}
|
||||||
|
|
||||||
class FunDB(callbacks.Privmsg, configurable.Mixin, plugins.ChannelDBHandler):
|
conf.registerPlugin('FunDB')
|
||||||
|
conf.registerChannelValue(conf.supybot.plugins.FunDB, 'showIds',
|
||||||
|
registry.Boolean(True, """Determine whether the bot will show the id of an
|
||||||
|
excuse/insult/praise/lart."""))
|
||||||
|
|
||||||
|
class FunDB(callbacks.Privmsg, plugins.ChannelDBHandler):
|
||||||
"""
|
"""
|
||||||
Contains the 'fun' commands that require a database. Currently includes
|
Contains the 'fun' commands that require a database. Currently includes
|
||||||
database-backed commands for crossword puzzle solving, anagram searching,
|
database-backed commands for crossword puzzle solving, anagram searching,
|
||||||
larting, praising, excusing, and insulting.
|
larting, praising, excusing, and insulting.
|
||||||
"""
|
"""
|
||||||
configurables = configurable.Dictionary(
|
|
||||||
[('show-ids', configurable.BoolType, False,
|
|
||||||
"""Determines whether the bot will show the id of an
|
|
||||||
excuse/insult/praise/lart.""")]
|
|
||||||
)
|
|
||||||
_tables = sets.Set(['lart', 'insult', 'excuse', 'praise'])
|
_tables = sets.Set(['lart', 'insult', 'excuse', 'praise'])
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
callbacks.Privmsg.__init__(self)
|
callbacks.Privmsg.__init__(self)
|
||||||
configurable.Mixin.__init__(self)
|
|
||||||
plugins.ChannelDBHandler.__init__(self)
|
plugins.ChannelDBHandler.__init__(self)
|
||||||
|
|
||||||
def die(self):
|
def die(self):
|
||||||
callbacks.Privmsg.die(self)
|
callbacks.Privmsg.die(self)
|
||||||
configurable.Mixin.die(self)
|
|
||||||
plugins.ChannelDBHandler.die(self)
|
plugins.ChannelDBHandler.die(self)
|
||||||
|
|
||||||
def makeDb(self, dbfilename, replace=False):
|
def makeDb(self, dbfilename, replace=False):
|
||||||
@ -346,7 +345,7 @@ class FunDB(callbacks.Privmsg, configurable.Mixin, plugins.ChannelDBHandler):
|
|||||||
nick = re.sub(r'\bme\b', msg.nick, nick)
|
nick = re.sub(r'\bme\b', msg.nick, nick)
|
||||||
nick = re.sub(r'\bmy\b', '%s\'s' % msg.nick, nick)
|
nick = re.sub(r'\bmy\b', '%s\'s' % msg.nick, nick)
|
||||||
insult = insult.replace('$who', nick)
|
insult = insult.replace('$who', nick)
|
||||||
showid = self.configurables.get('show-ids', channel)
|
showid = self.registryValue('showIds', channel)
|
||||||
irc.reply(self._formatResponse(insult, id, showid), to=nick)
|
irc.reply(self._formatResponse(insult, id, showid), to=nick)
|
||||||
|
|
||||||
def excuse(self, irc, msg, args):
|
def excuse(self, irc, msg, args):
|
||||||
@ -380,7 +379,7 @@ class FunDB(callbacks.Privmsg, configurable.Mixin, plugins.ChannelDBHandler):
|
|||||||
irc.error('There are currently no available excuses.')
|
irc.error('There are currently no available excuses.')
|
||||||
else:
|
else:
|
||||||
(id, excuse) = cursor.fetchone()
|
(id, excuse) = cursor.fetchone()
|
||||||
showid = self.configurables.get('show-ids', channel)
|
showid = self.registryValue('showIds', channel)
|
||||||
irc.reply(self._formatResponse(excuse, id, showid))
|
irc.reply(self._formatResponse(excuse, id, showid))
|
||||||
|
|
||||||
def lart(self, irc, msg, args):
|
def lart(self, irc, msg, args):
|
||||||
@ -435,7 +434,7 @@ class FunDB(callbacks.Privmsg, configurable.Mixin, plugins.ChannelDBHandler):
|
|||||||
if reason:
|
if reason:
|
||||||
s = '%s for %s' % (s, reason)
|
s = '%s for %s' % (s, reason)
|
||||||
s = s.rstrip('.')
|
s = s.rstrip('.')
|
||||||
showid = self.configurables.get('show-ids', channel)
|
showid = self.registryValue('showIds', channel)
|
||||||
irc.reply(self._formatResponse(s, id, showid), action=True)
|
irc.reply(self._formatResponse(s, id, showid), action=True)
|
||||||
|
|
||||||
def praise(self, irc, msg, args):
|
def praise(self, irc, msg, args):
|
||||||
@ -489,7 +488,7 @@ class FunDB(callbacks.Privmsg, configurable.Mixin, plugins.ChannelDBHandler):
|
|||||||
if reason:
|
if reason:
|
||||||
s = '%s for %s' % (s, reason)
|
s = '%s for %s' % (s, reason)
|
||||||
s = s.rstrip('.')
|
s = s.rstrip('.')
|
||||||
showid = self.configurables.get('show-ids', channel)
|
showid = self.registryValue('showIds', channel)
|
||||||
irc.reply(self._formatResponse(s, id, showid), action=True)
|
irc.reply(self._formatResponse(s, id, showid), action=True)
|
||||||
|
|
||||||
Class = FunDB
|
Class = FunDB
|
||||||
|
@ -51,7 +51,7 @@ if sqlite is not None:
|
|||||||
_ = self.irc.takeMsg()
|
_ = self.irc.takeMsg()
|
||||||
#ircdb.users.getUser('t3st').addCapability('admin')
|
#ircdb.users.getUser('t3st').addCapability('admin')
|
||||||
ircdb.users.getUser('t3st').addCapability('#test.op')
|
ircdb.users.getUser('t3st').addCapability('#test.op')
|
||||||
self.assertNotError('fundb config #test show-ids on')
|
conf.supybot.plugins.FunDB.showIds.setValue(True)
|
||||||
|
|
||||||
def testAdd(self):
|
def testAdd(self):
|
||||||
self.assertError('add l4rt foo')
|
self.assertError('add l4rt foo')
|
||||||
@ -69,7 +69,7 @@ if sqlite is not None:
|
|||||||
'(#1)\x01')
|
'(#1)\x01')
|
||||||
self.assertResponse('lart jemfinch',
|
self.assertResponse('lart jemfinch',
|
||||||
'\x01ACTION jabs jemfinch (#1)\x01')
|
'\x01ACTION jabs jemfinch (#1)\x01')
|
||||||
self.assertRegexp('num lart', 'currently 1 lart')
|
self.assertRegexp('stats lart', 'currently 1 lart')
|
||||||
self.assertNotError('add lart shoots $who')
|
self.assertNotError('add lart shoots $who')
|
||||||
self.assertHelp('lart 1')
|
self.assertHelp('lart 1')
|
||||||
self.assertResponse('lart 1 jemfinch',
|
self.assertResponse('lart 1 jemfinch',
|
||||||
@ -79,11 +79,11 @@ if sqlite is not None:
|
|||||||
'(#2)\x01')
|
'(#2)\x01')
|
||||||
self.assertNotRegexp('lart %s' % self.irc.nick, self.irc.nick)
|
self.assertNotRegexp('lart %s' % self.irc.nick, self.irc.nick)
|
||||||
self.assertNotError('remove lart 1')
|
self.assertNotError('remove lart 1')
|
||||||
self.assertRegexp('num lart', 'currently 1 lart')
|
self.assertRegexp('stats lart', 'currently 1 lart')
|
||||||
self.assertResponse('lart jemfinch',
|
self.assertResponse('lart jemfinch',
|
||||||
'\x01ACTION shoots jemfinch (#2)\x01')
|
'\x01ACTION shoots jemfinch (#2)\x01')
|
||||||
self.assertNotError('remove lart 2')
|
self.assertNotError('remove lart 2')
|
||||||
self.assertRegexp('num lart', 'currently 0')
|
self.assertRegexp('stats lart', 'currently 0')
|
||||||
self.assertError('lart jemfinch')
|
self.assertError('lart jemfinch')
|
||||||
|
|
||||||
def testLartAndPraiseRemoveTrailingPeriods(self):
|
def testLartAndPraiseRemoveTrailingPeriods(self):
|
||||||
@ -126,23 +126,23 @@ if sqlite is not None:
|
|||||||
self.assertNotError('add excuse Power failure')
|
self.assertNotError('add excuse Power failure')
|
||||||
self.assertResponse('excuse', 'Power failure (#1)')
|
self.assertResponse('excuse', 'Power failure (#1)')
|
||||||
self.assertError('excuse a few random words')
|
self.assertError('excuse a few random words')
|
||||||
self.assertRegexp('num excuse', r'currently 1 excuse')
|
self.assertRegexp('stats excuse', r'currently 1 excuse')
|
||||||
self.assertNotError('add excuse /pub/lunch')
|
self.assertNotError('add excuse /pub/lunch')
|
||||||
self.assertResponse('excuse 1', 'Power failure (#1)')
|
self.assertResponse('excuse 1', 'Power failure (#1)')
|
||||||
self.assertNotError('remove excuse 1')
|
self.assertNotError('remove excuse 1')
|
||||||
self.assertRegexp('num excuse', r'currently 1 excuse')
|
self.assertRegexp('stats excuse', r'currently 1 excuse')
|
||||||
self.assertResponse('excuse', '/pub/lunch (#2)')
|
self.assertResponse('excuse', '/pub/lunch (#2)')
|
||||||
self.assertNotError('remove excuse 2')
|
self.assertNotError('remove excuse 2')
|
||||||
self.assertRegexp('num excuse', r'currently 0')
|
self.assertRegexp('stats excuse', r'currently 0')
|
||||||
self.assertError('excuse')
|
self.assertError('excuse')
|
||||||
|
|
||||||
def testInsult(self):
|
def testInsult(self):
|
||||||
self.assertNotError('add insult Fatty McFatty')
|
self.assertNotError('add insult Fatty McFatty')
|
||||||
self.assertResponse('insult jemfinch',
|
self.assertResponse('insult jemfinch',
|
||||||
'jemfinch: Fatty McFatty (#1)')
|
'jemfinch: Fatty McFatty (#1)')
|
||||||
self.assertRegexp('num insult', r'currently 1')
|
self.assertRegexp('stats insult', r'currently 1')
|
||||||
self.assertNotError('remove insult 1')
|
self.assertNotError('remove insult 1')
|
||||||
self.assertRegexp('num insult', 'currently 0')
|
self.assertRegexp('stats insult', 'currently 0')
|
||||||
self.assertError('insult jemfinch')
|
self.assertError('insult jemfinch')
|
||||||
|
|
||||||
def testPraise(self):
|
def testPraise(self):
|
||||||
@ -153,7 +153,7 @@ if sqlite is not None:
|
|||||||
'(#1)\x01')
|
'(#1)\x01')
|
||||||
self.assertResponse('praise jemfinch',
|
self.assertResponse('praise jemfinch',
|
||||||
'\x01ACTION pets jemfinch (#1)\x01')
|
'\x01ACTION pets jemfinch (#1)\x01')
|
||||||
self.assertRegexp('num praise', r'currently 1')
|
self.assertRegexp('stats praise', r'currently 1')
|
||||||
self.assertNotError('add praise gives $who a cookie')
|
self.assertNotError('add praise gives $who a cookie')
|
||||||
self.assertHelp('praise 1')
|
self.assertHelp('praise 1')
|
||||||
self.assertResponse('praise 1 jemfinch',
|
self.assertResponse('praise 1 jemfinch',
|
||||||
@ -162,11 +162,11 @@ if sqlite is not None:
|
|||||||
'\x01ACTION gives jemfinch a cookie for being '
|
'\x01ACTION gives jemfinch a cookie for being '
|
||||||
'him (#2)\x01')
|
'him (#2)\x01')
|
||||||
self.assertNotError('remove praise 1')
|
self.assertNotError('remove praise 1')
|
||||||
self.assertRegexp('num praise', r'currently 1')
|
self.assertRegexp('stats praise', r'currently 1')
|
||||||
self.assertResponse('praise jemfinch',
|
self.assertResponse('praise jemfinch',
|
||||||
'\x01ACTION gives jemfinch a cookie (#2)\x01')
|
'\x01ACTION gives jemfinch a cookie (#2)\x01')
|
||||||
self.assertNotError('remove praise 2')
|
self.assertNotError('remove praise 2')
|
||||||
self.assertRegexp('num praise', r'currently 0')
|
self.assertRegexp('stats praise', r'currently 0')
|
||||||
self.assertError('praise jemfinch')
|
self.assertError('praise jemfinch')
|
||||||
|
|
||||||
def testInfo(self):
|
def testInfo(self):
|
||||||
@ -176,20 +176,20 @@ if sqlite is not None:
|
|||||||
self.assertError('info fake 1')
|
self.assertError('info fake 1')
|
||||||
|
|
||||||
def testGet(self):
|
def testGet(self):
|
||||||
self.assertError('get fake 1')
|
self.assertError('fundb get fake 1')
|
||||||
self.assertError('get lart foo')
|
self.assertError('fundb get lart foo')
|
||||||
self.assertNotError('add praise pets $who')
|
self.assertNotError('add praise pets $who')
|
||||||
self.assertResponse('get praise 1', 'pets $who')
|
self.assertResponse('fundb get praise 1', 'pets $who')
|
||||||
self.assertNotError('remove praise 1')
|
self.assertNotError('remove praise 1')
|
||||||
self.assertError('get praise 1')
|
self.assertError('fundb get praise 1')
|
||||||
|
|
||||||
def testNum(self):
|
def testStats(self):
|
||||||
self.assertError('num fake')
|
self.assertError('stats fake')
|
||||||
self.assertError('num 1')
|
self.assertError('stats 1')
|
||||||
self.assertRegexp('num praise', r'currently 0')
|
self.assertRegexp('stats praise', r'currently 0')
|
||||||
self.assertRegexp('num lart', r'currently 0')
|
self.assertRegexp('stats lart', r'currently 0')
|
||||||
self.assertRegexp('num excuse', r'currently 0')
|
self.assertRegexp('stats excuse', r'currently 0')
|
||||||
self.assertRegexp('num insult', r'currently 0')
|
self.assertRegexp('stats insult', r'currently 0')
|
||||||
|
|
||||||
def testChange(self):
|
def testChange(self):
|
||||||
self.assertNotError('add praise teaches $who perl')
|
self.assertNotError('add praise teaches $who perl')
|
||||||
@ -201,7 +201,7 @@ if sqlite is not None:
|
|||||||
def testConfig(self):
|
def testConfig(self):
|
||||||
self.assertNotError('add praise teaches $who perl')
|
self.assertNotError('add praise teaches $who perl')
|
||||||
self.assertRegexp('praise jemfinch', r'\(#1\)')
|
self.assertRegexp('praise jemfinch', r'\(#1\)')
|
||||||
self.assertNotError('fundb config show-ids off')
|
conf.supybot.plugins.FunDB.showIds.setValue(False)
|
||||||
self.assertNotRegexp('praise jemfinch', r'\(#1\)')
|
self.assertNotRegexp('praise jemfinch', r'\(#1\)')
|
||||||
|
|
||||||
def testLartPraiseReasonPeriod(self):
|
def testLartPraiseReasonPeriod(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user