mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 19:19:32 +01:00
* Added a required per-channel news capability
* Fixed tests (syntax error, tabs/spaces) * Updated addnews to use new persistent userids
This commit is contained in:
parent
2682670fc6
commit
b71787b702
@ -94,7 +94,7 @@ class News(callbacks.Privmsg, ChannelDBHandler):
|
|||||||
db.commit()
|
db.commit()
|
||||||
return db
|
return db
|
||||||
|
|
||||||
def addnews(self, irc, msg, args):
|
def addnews(self, irc, msg, args, channel):
|
||||||
"""[<channel>] <expires> <subject>: <text>
|
"""[<channel>] <expires> <subject>: <text>
|
||||||
|
|
||||||
Adds a given news item of <text> to a channel with the given <subject>.
|
Adds a given news item of <text> to a channel with the given <subject>.
|
||||||
@ -102,12 +102,6 @@ class News(callbacks.Privmsg, ChannelDBHandler):
|
|||||||
now. <channel> is only necessary if the message isn't sent in the
|
now. <channel> is only necessary if the message isn't sent in the
|
||||||
channel itself.
|
channel itself.
|
||||||
"""
|
"""
|
||||||
channel = privmsgs.getChannel(msg, args)
|
|
||||||
# Check if they have the appropriate capability.
|
|
||||||
capability = ircdb.makeChannelCapability(channel, 'news')
|
|
||||||
if not ircdb.checkCapability(msg.prefix, capability):
|
|
||||||
irc.error(msg, conf.replyNoCapability % capability)
|
|
||||||
return
|
|
||||||
# Parse out the args
|
# Parse out the args
|
||||||
i = None
|
i = None
|
||||||
for i, arg in enumerate(args):
|
for i, arg in enumerate(args):
|
||||||
@ -123,7 +117,7 @@ class News(callbacks.Privmsg, ChannelDBHandler):
|
|||||||
text = ' '.join(args[i:])
|
text = ' '.join(args[i:])
|
||||||
# Set the other stuff needed for the insert.
|
# Set the other stuff needed for the insert.
|
||||||
if ircdb.users.hasUser(msg.prefix):
|
if ircdb.users.hasUser(msg.prefix):
|
||||||
name = ircdb.users.getUserName(msg.prefix)
|
name = ircdb.users.getUser(msg.prefix).name
|
||||||
else:
|
else:
|
||||||
name = msg.nick
|
name = msg.nick
|
||||||
|
|
||||||
@ -133,6 +127,7 @@ class News(callbacks.Privmsg, ChannelDBHandler):
|
|||||||
subject[:-1], text, added_at, expires, name)
|
subject[:-1], text, added_at, expires, name)
|
||||||
db.commit()
|
db.commit()
|
||||||
irc.reply(msg, conf.replySuccess)
|
irc.reply(msg, conf.replySuccess)
|
||||||
|
addnews = privmsgs.checkChannelCapability(addnews, 'news')
|
||||||
|
|
||||||
def readnews(self, irc, msg, args):
|
def readnews(self, irc, msg, args):
|
||||||
"""[<channel>] <number>
|
"""[<channel>] <number>
|
||||||
|
@ -33,13 +33,20 @@ from test import *
|
|||||||
|
|
||||||
import utils
|
import utils
|
||||||
|
|
||||||
class NewsTestCase(PluginTestCase):
|
class NewsTestCase(ChannelPluginTestCase):
|
||||||
plugins = ('News',)
|
plugins = ('News',)
|
||||||
def testAddNews(self):
|
def testAddNews(self):
|
||||||
self.assertNotError('addnews 0 subject: foo')
|
self.assertNotError('addnews #somechannel 0 subject: foo')
|
||||||
self.assertNotError('addnews #somechannel subject: foo')
|
self.assertNotError('addnews 0 subject2: foo2')
|
||||||
|
|
||||||
def testListNews(self):
|
def testListNews(self):
|
||||||
|
# These should both fail first, as they will have nothing in the DB
|
||||||
|
self.assertError('listnews')
|
||||||
|
self.assertError('listnews #channel')
|
||||||
|
# Now we'll add news and make sure listnews doesn't fail
|
||||||
|
self.assertNotError('addnews #channel 0 subject: foo')
|
||||||
|
self.assertNotError('listnews #channel')
|
||||||
|
self.assertNotError('addnews 0 subject: foo')
|
||||||
self.assertNotError('listnews')
|
self.assertNotError('listnews')
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
Loading…
Reference in New Issue
Block a user