Merge pull request #973 from GLolol/quote-replace

Quote: add a 'replace' command
This commit is contained in:
Valentin Lorentz 2014-12-27 20:25:46 +01:00
commit b2f84c9e2e
2 changed files with 24 additions and 2 deletions

View File

@ -48,6 +48,21 @@ class Quote(plugins.ChannelIdDatabasePlugin):
irc.error(_('I have no quotes in my database for %s.') % channel) irc.error(_('I have no quotes in my database for %s.') % channel)
random = wrap(random, ['channeldb']) random = wrap(random, ['channeldb'])
def replace(self, irc, msg, args, user, channel, id, text):
"""[<channel>] <id> <text>
Replace quote <id> with <text>. <channel> is only necessary if
the message isn't sent in the channel itself.
"""
try:
record = self.db.get(channel, id)
self.checkChangeAllowed(irc, msg, channel, user, record)
record.text = text
self.db.set(channel, id, record)
irc.replySuccess()
except KeyError:
self.noSuchRecord(irc, channel, id)
replace = wrap(replace, ['user', 'channeldb', 'id', 'text'])
Class = Quote Class = Quote
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -29,8 +29,15 @@
from supybot.test import * from supybot.test import *
class QuoteTestCase(PluginTestCase): class QuoteTestCase(ChannelPluginTestCase):
plugins = ('Quote',) plugins = ('Quote', 'User')
def testReplace(self):
self.feedMsg('register testuser moo', to=self.nick, frm=self.prefix)
_ = self.getMsg(' ')
self.assertNotError("quote add hello")
self.assertNotError("quote replace 1 goodbye")
self.assertRegexp("quote get 1", "goodbye")
self.assertError("quote replace 5 afsdafas") # non-existant
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: