def cmd_addnews(self, c, e): if not e.payload: self.send_notice(e.nick, message.command_syntax.addnews) return article = News_Article(created_at=datetime.datetime.now(), author=e.nick, body=e.arguments) article.save() self.send_notice(e.nick, message.news.added)
def cmd_delnews(self, c, e): if not e.payload: self.send_notice(e.nick, message.command_syntax.delnews) return articles = News_Article.find({'body': re.compile(".*" + e.arguments + ".*")}) if articles.count() > 1: self.send_notice(e.nick, message.news.multiple_matches) return self.send_notice(e.nick, message.news.removed, body=articles[0].body) articles[0].remove()
def cmd_news(self, c, e): count = 3 if e.payload: if not e.payload.isdigit(): self.send_notice(e.nick, message.command_syntax.news) return count = int(e.payload) articles = News_Article.find().sort('created_at', -1) self.send_notice(e.nick, message.news.header, channel=self.bot.channel) article_count = articles.count() for i in xrange(count): if i > article_count - 1: break article = articles[i] self.send_notice(e.nick, message.news.line, author=article.author, body=article.body, \ date=datetime.datetime.strftime(article.created_at, "%d/%m/%Y"))