mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 12:42:34 +01:00
Slight formatting changes and whatnot.
This commit is contained in:
parent
c32a207791
commit
6107000658
@ -134,7 +134,7 @@ class News(plugins.ChannelDBHandler, callbacks.Privmsg):
|
|||||||
irc.reply(msg, conf.replySuccess)
|
irc.reply(msg, conf.replySuccess)
|
||||||
addnews = privmsgs.checkChannelCapability(addnews, 'news')
|
addnews = privmsgs.checkChannelCapability(addnews, 'news')
|
||||||
|
|
||||||
def readnews(self, irc, msg, args):
|
def _readnews(self, irc, msg, args):
|
||||||
"""[<channel>] <number>
|
"""[<channel>] <number>
|
||||||
|
|
||||||
Display the text for news item with id <number> from <channel>.
|
Display the text for news item with id <number> from <channel>.
|
||||||
@ -147,52 +147,49 @@ class News(plugins.ChannelDBHandler, callbacks.Privmsg):
|
|||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute("""SELECT news.item, news.subject, news.added_at,
|
cursor.execute("""SELECT news.item, news.subject, news.added_at,
|
||||||
news.expires_at, news.added_by FROM news
|
news.expires_at, news.added_by FROM news
|
||||||
WHERE news.id = %s""", id)
|
WHERE news.id=%s""", id)
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
irc.error(msg, 'No news item matches that id.')
|
irc.error(msg, 'No news item matches that id.')
|
||||||
else:
|
else:
|
||||||
item, subject, added_at, expires_at, added_by = cursor.fetchone()
|
item, subject, added_at, expires_at, added_by = cursor.fetchone()
|
||||||
s = '%s (Subject: "%s", added by %s on %s' % \
|
if int(expires_at) == 0:
|
||||||
(item, subject, added_by,
|
s = '%s (Subject: "%s", added by %s on %s)' % \
|
||||||
time.strftime(conf.humanTimestampFormat,
|
(item, subject, added_by,
|
||||||
time.localtime(int(added_at))))
|
|
||||||
if int(expires_at) > 0:
|
|
||||||
s += ', expires at %s)' % \
|
|
||||||
time.strftime(conf.humanTimestampFormat,
|
time.strftime(conf.humanTimestampFormat,
|
||||||
time.localtime(int(expires_at)))
|
time.localtime(int(added_at))))
|
||||||
else:
|
else:
|
||||||
s += ')'
|
s = '%s (Subject: "%s", added by %s on %s, expires at %s)' % \
|
||||||
|
(item, subject, added_by,
|
||||||
|
time.strftime(conf.humanTimestampFormat,
|
||||||
|
time.localtime(int(added_at))),
|
||||||
|
time.strftime(conf.humanTimestampFormat,
|
||||||
|
time.localtime(int(expires_at))))
|
||||||
irc.reply(msg, s)
|
irc.reply(msg, s)
|
||||||
|
|
||||||
def listnews(self, irc, msg, args):
|
def news(self, irc, msg, args):
|
||||||
"""[<channel>]
|
"""[<channel>] [<number>]
|
||||||
|
|
||||||
Display the news items for <channel> in the format of "id) subject".
|
Display the news items for <channel> in the format of '(#id) subject'.
|
||||||
<channel> is only necessary if the message isn't sent in the channel
|
If <number> is given, retrieve only that news item; otherwise retrieve
|
||||||
itself.
|
all news items. <channel> is only necessary if the message isn't sent
|
||||||
|
in the channel itself.
|
||||||
"""
|
"""
|
||||||
channel = privmsgs.getChannel(msg, args)
|
channel = privmsgs.getChannel(msg, args)
|
||||||
|
number = privmsgs.getArgs(args, needed=0, optional=1)
|
||||||
|
if number:
|
||||||
|
self._readnews(irc, msg, [channel, number])
|
||||||
|
return
|
||||||
db = self.getDb(channel)
|
db = self.getDb(channel)
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute("""SELECT news.id, news.subject FROM news
|
cursor.execute("""SELECT news.id, news.subject FROM news
|
||||||
WHERE (news.expires_at > %s)
|
WHERE news.expires_at > %s
|
||||||
OR (news.expires_at = 0)""",
|
OR news.expires_at=0""", int(time.time()))
|
||||||
int(time.time()))
|
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
irc.error(msg, 'No news items for channel: %s' % channel)
|
irc.reply(msg, 'No news for %s' % channel)
|
||||||
else:
|
else:
|
||||||
items = []
|
items = ['(#%s) %s' % (id, s) for (id, s) in cursor.fetchall()]
|
||||||
for (id, subject) in cursor.fetchall():
|
s = 'News for %s: %s' % (channel, '; '.join(items))
|
||||||
items.append('(#%s) %s' % (id, subject))
|
|
||||||
totalResults = len(items)
|
|
||||||
if ircutils.shrinkList(items, '; ', 400):
|
|
||||||
s = 'News for %s (%s of %s shown): %s' % \
|
|
||||||
(channel, len(items), totalResults, '; '.join(items))
|
|
||||||
else:
|
|
||||||
s = 'News for %s: %s' % (channel, '; '.join(items))
|
|
||||||
irc.reply(msg, s)
|
irc.reply(msg, s)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def removenews(self, irc, msg, args):
|
def removenews(self, irc, msg, args):
|
||||||
"""[<channel>] <number>
|
"""[<channel>] <number>
|
||||||
|
@ -48,13 +48,13 @@ if sqlite is not None:
|
|||||||
|
|
||||||
def testListNews(self):
|
def testListNews(self):
|
||||||
# These should both fail first, as they will have nothing in the DB
|
# These should both fail first, as they will have nothing in the DB
|
||||||
self.assertError('listnews')
|
self.assertRegexp('news', 'no news')
|
||||||
self.assertError('listnews #channel')
|
self.assertRegexp('news #channel', 'no news')
|
||||||
# Now we'll add news and make sure listnews doesn't fail
|
# Now we'll add news and make sure listnews doesn't fail
|
||||||
self.assertNotError('addnews #channel 0 subject: foo')
|
self.assertNotError('addnews #channel 0 subject: foo')
|
||||||
self.assertNotError('listnews #channel')
|
self.assertNotError('news #channel')
|
||||||
self.assertNotError('addnews 0 subject: foo')
|
self.assertNotError('addnews 0 subject: foo')
|
||||||
self.assertNotError('listnews')
|
self.assertNotError('news')
|
||||||
|
|
||||||
# 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