From 610700065814c8a5573f6490030db0600929190b Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Sun, 5 Oct 2003 20:33:01 +0000 Subject: [PATCH] Slight formatting changes and whatnot. --- plugins/News.py | 57 ++++++++++++++++++++++------------------------- test/test_News.py | 8 +++---- 2 files changed, 31 insertions(+), 34 deletions(-) diff --git a/plugins/News.py b/plugins/News.py index 33f037ab3..8bd41c917 100644 --- a/plugins/News.py +++ b/plugins/News.py @@ -134,7 +134,7 @@ class News(plugins.ChannelDBHandler, callbacks.Privmsg): irc.reply(msg, conf.replySuccess) addnews = privmsgs.checkChannelCapability(addnews, 'news') - def readnews(self, irc, msg, args): + def _readnews(self, irc, msg, args): """[] Display the text for news item with id from . @@ -147,52 +147,49 @@ class News(plugins.ChannelDBHandler, callbacks.Privmsg): cursor = db.cursor() cursor.execute("""SELECT news.item, news.subject, news.added_at, news.expires_at, news.added_by FROM news - WHERE news.id = %s""", id) + WHERE news.id=%s""", id) if cursor.rowcount == 0: irc.error(msg, 'No news item matches that id.') else: item, subject, added_at, expires_at, added_by = cursor.fetchone() - s = '%s (Subject: "%s", added by %s on %s' % \ - (item, subject, added_by, - time.strftime(conf.humanTimestampFormat, - time.localtime(int(added_at)))) - if int(expires_at) > 0: - s += ', expires at %s)' % \ + if int(expires_at) == 0: + s = '%s (Subject: "%s", added by %s on %s)' % \ + (item, subject, added_by, time.strftime(conf.humanTimestampFormat, - time.localtime(int(expires_at))) + time.localtime(int(added_at)))) 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) - def listnews(self, irc, msg, args): - """[] + def news(self, irc, msg, args): + """[] [] - Display the news items for in the format of "id) subject". - is only necessary if the message isn't sent in the channel - itself. + Display the news items for in the format of '(#id) subject'. + If is given, retrieve only that news item; otherwise retrieve + all news items. is only necessary if the message isn't sent + in the channel itself. """ 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) cursor = db.cursor() cursor.execute("""SELECT news.id, news.subject FROM news - WHERE (news.expires_at > %s) - OR (news.expires_at = 0)""", - int(time.time())) + WHERE news.expires_at > %s + OR news.expires_at=0""", int(time.time())) if cursor.rowcount == 0: - irc.error(msg, 'No news items for channel: %s' % channel) + irc.reply(msg, 'No news for %s' % channel) else: - items = [] - for (id, subject) in cursor.fetchall(): - 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)) + items = ['(#%s) %s' % (id, s) for (id, s) in cursor.fetchall()] + s = 'News for %s: %s' % (channel, '; '.join(items)) irc.reply(msg, s) - - def removenews(self, irc, msg, args): """[] diff --git a/test/test_News.py b/test/test_News.py index 92aec83dd..64d9f223c 100644 --- a/test/test_News.py +++ b/test/test_News.py @@ -48,13 +48,13 @@ if sqlite is not None: def testListNews(self): # These should both fail first, as they will have nothing in the DB - self.assertError('listnews') - self.assertError('listnews #channel') + self.assertRegexp('news', 'no news') + self.assertRegexp('news #channel', 'no news') # 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('news #channel') self.assertNotError('addnews 0 subject: foo') - self.assertNotError('listnews') + self.assertNotError('news') # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: