mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-12 13:12:35 +01:00
News: Use positiveInt converter instead of manual checks.
Closes: Sf#3059239 Signed-off-by: James Vega <jamessan@users.sourceforge.net>
This commit is contained in:
parent
8cc6320768
commit
63244b1e47
@ -147,16 +147,11 @@ class News(callbacks.Plugin):
|
|||||||
irc.reply(format('No news for %s.', channel))
|
irc.reply(format('No news for %s.', channel))
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
if id < 1:
|
|
||||||
raise ValueError
|
|
||||||
record = self.db.get(channel, id)
|
record = self.db.get(channel, id)
|
||||||
irc.reply(str(record))
|
irc.reply(str(record))
|
||||||
except dbi.NoRecordError, id:
|
except dbi.NoRecordError, id:
|
||||||
irc.errorInvalid('news item id', id)
|
irc.errorInvalid('news item id', id)
|
||||||
except ValueError:
|
news = wrap(news, ['channeldb', additional('positiveInt')])
|
||||||
irc.errorInvalid('news item id', id,
|
|
||||||
'<id> must be a positive integer.')
|
|
||||||
news = wrap(news, ['channeldb', additional('int')])
|
|
||||||
|
|
||||||
def remove(self, irc, msg, args, channel, id):
|
def remove(self, irc, msg, args, channel, id):
|
||||||
"""[<channel>] <id>
|
"""[<channel>] <id>
|
||||||
@ -165,16 +160,11 @@ class News(callbacks.Plugin):
|
|||||||
necessary if the message isn't sent in the channel itself.
|
necessary if the message isn't sent in the channel itself.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
if id < 1:
|
|
||||||
raise ValueError
|
|
||||||
self.db.remove(channel, id)
|
self.db.remove(channel, id)
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
except dbi.NoRecordError:
|
except dbi.NoRecordError:
|
||||||
irc.errorInvalid('news item id', id)
|
irc.errorInvalid('news item id', id)
|
||||||
except ValueError:
|
remove = wrap(remove, ['channeldb', 'positiveInt'])
|
||||||
irc.errorInvalid('news item id', id,
|
|
||||||
'<id> must be a positive integer.')
|
|
||||||
remove = wrap(remove, ['channeldb', 'int'])
|
|
||||||
|
|
||||||
def change(self, irc, msg, args, channel, id, replacer):
|
def change(self, irc, msg, args, channel, id, replacer):
|
||||||
"""[<channel>] <id> <regexp>
|
"""[<channel>] <id> <regexp>
|
||||||
@ -185,16 +175,11 @@ class News(callbacks.Plugin):
|
|||||||
isn't sent on the channel itself.
|
isn't sent on the channel itself.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
if id < 1:
|
|
||||||
raise ValueError
|
|
||||||
self.db.change(channel, id, replacer)
|
self.db.change(channel, id, replacer)
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
except dbi.NoRecordError:
|
except dbi.NoRecordError:
|
||||||
irc.errorInvalid('news item id', id)
|
irc.errorInvalid('news item id', id)
|
||||||
except ValueError:
|
change = wrap(change, ['channeldb', 'positiveInt', 'regexpReplacer'])
|
||||||
irc.errorInvalid('news item id', id,
|
|
||||||
'<id> must be a positive integer.')
|
|
||||||
change = wrap(change, ['channeldb', 'int', 'regexpReplacer'])
|
|
||||||
|
|
||||||
def old(self, irc, msg, args, channel, id):
|
def old(self, irc, msg, args, channel, id):
|
||||||
"""[<channel>] [<id>]
|
"""[<channel>] [<id>]
|
||||||
@ -205,15 +190,10 @@ class News(callbacks.Plugin):
|
|||||||
"""
|
"""
|
||||||
if id:
|
if id:
|
||||||
try:
|
try:
|
||||||
if id < 1:
|
|
||||||
raise ValueError
|
|
||||||
record = self.db.getOld(channel, id)
|
record = self.db.getOld(channel, id)
|
||||||
irc.reply(str(record))
|
irc.reply(str(record))
|
||||||
except dbi.NoRecordError, id:
|
except dbi.NoRecordError, id:
|
||||||
irc.errorInvalid('news item id', id)
|
irc.errorInvalid('news item id', id)
|
||||||
except ValueError:
|
|
||||||
irc.errorInvalid('news item id', id,
|
|
||||||
'<id> must be a positive integer.')
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
records = self.db.getOld(channel)
|
records = self.db.getOld(channel)
|
||||||
@ -222,7 +202,7 @@ class News(callbacks.Plugin):
|
|||||||
irc.reply(s)
|
irc.reply(s)
|
||||||
except dbi.NoRecordError:
|
except dbi.NoRecordError:
|
||||||
irc.reply(format('No old news for %s.', channel))
|
irc.reply(format('No old news for %s.', channel))
|
||||||
old = wrap(old, ['channeldb', additional('int')])
|
old = wrap(old, ['channeldb', additional('positiveInt')])
|
||||||
|
|
||||||
|
|
||||||
Class = News
|
Class = News
|
||||||
|
Loading…
Reference in New Issue
Block a user