def process_post_for_battle(self, post, battle, sess): p = sess.query(Processed).filter_by(battle=battle).all() seen = [entry.id36 for entry in p] replaced = post.replace_more_comments(limit=None, threshold=0) if replaced: logging.info("Comments that went un-replaced: %s" % replaced) flat_comments = praw.helpers.flatten_tree( post.comments) for comment in flat_comments: if comment.name in seen: continue if not comment.author: # Deleted comments don't have an author continue if comment.author.name.lower() == self.config.username.lower(): continue cmds = extract_command(comment.body) if cmds: player = self.find_player(comment, sess) if player: context = Context(player, self.config, sess, comment, self.reddit) for cmd in cmds: self.command(cmd, context) sess.add(Processed(id36=comment.name, battle=battle)) sess.commit()
def process_post_for_battle(self, post, battle, sess): p = sess.query(Processed).filter_by(battle=battle).all() seen = [entry.id36 for entry in p] replaced = post.replace_more_comments(limit=None, threshold=0) if replaced: logging.info("Comments that went un-replaced: %s" % replaced) flat_comments = praw.helpers.flatten_tree(post.comments) for comment in flat_comments: if comment.name in seen: continue if not comment.author: # Deleted comments don't have an author continue if comment.author.name.lower() == self.config.username.lower(): continue cmds = extract_command(comment.body) if cmds: player = self.find_player(comment, sess) if player: context = Context(player, self.config, sess, comment, self.reddit) for cmd in cmds: self.command(cmd, context) sess.add(Processed(id36=comment.name, battle=battle)) sess.commit()
def action(self, message, serv, event): msg = message.lower() if message.startswith(self.nick): command = extract_command(message) if command == "cassos": self.queue.stop() sleep(.7) # ensure the stop was read self.speak("ok je comprends") self.inputthread.stop() ttclient.trigger() sleep(.2) serv.disconnect("Au revoir, comme aurait dit VGE") sleep(2) syslog.syslog("quit on cassos irc message") sys.exit(0) elif command == "asv": self.asv() elif command == "onair": self.onair() elif command == "on air": self.onair() elif command == "like": self.like(irclib.nm_to_n(event.source())) elif command == "je kiffe": self.like(irclib.nm_to_n(event.source())) elif command == "love": self.like(irclib.nm_to_n(event.source())) elif command == "j'aime": self.like(irclib.nm_to_n(event.source())) elif command == "hate": self.hate(irclib.nm_to_n(event.source())) elif command == "caca": self.hate(irclib.nm_to_n(event.source())) elif command == "beurk": self.hate(irclib.nm_to_n(event.source())) elif command == "pouah": self.hate(irclib.nm_to_n(event.source())) elif command == "dislike": self.hate(irclib.nm_to_n(event.source())) elif command == "help": self.help() else: for plp in self.pl_prefix: if command == plp: self.addpl(message)
def check_messages(self): unread = reddit.get_unread(True, True) session = self.session for comment in unread: # Only PMs, we deal with comment replies in process_post_for_battle if not comment.was_comment: seen = session.query(Processed).filter_by(id36=comment.name).count() if seen: continue player = self.find_player(comment, session) if player: cmd = extract_command(comment.body) if not cmd: cmd = comment.body context = Context(player, self.config, session, comment, self.reddit) self.command(cmd, context) session.add(Processed(id36=comment.name)) session.commit() comment.mark_as_read()
def check_messages(self): unread = reddit.get_unread(True, True) session = self.session for comment in unread: # Only PMs, we deal with comment replies in process_post_for_battle if not comment.was_comment: seen = (session.query(Processed).filter_by( id36=comment.name).count()) if seen: continue player = self.find_player(comment, session) if player: cmds = extract_command(comment.body) if not cmds: cmds = [comment.body] context = Context(player, self.config, session, comment, self.reddit) for cmd in cmds: self.command(cmd, context) session.add(Processed(id36=comment.name)) session.commit() comment.mark_as_read()
def test_extract_command(self): """ Extract command """ result = utils.extract_command('toto: foo') self.assertEqual(result, 'foo') result = utils.extract_command('toto: foo') self.assertEqual(result, 'foo') result = utils.extract_command('toto:foo') self.assertEqual(result, 'foo') result = utils.extract_command('toto:foo ') self.assertEqual(result, 'foo') result = utils.extract_command('toto: foo ') self.assertEqual(result, 'foo') result = utils.extract_command('toto: foo toto ') self.assertNotEqual(result, 'foo')
def execute(self, serv, canal, handle, message): message = message.lower() cmd = utils.extract_command(message) if message == "h" or message == "help" or message.strip() == "": serv.notice(handle,"Command : !vote <action>") serv.notice(handle,"actions :") serv.notice(handle," new <poll_name>") serv.notice(handle," y") serv.notice(handle," n") serv.notice(handle," results") serv.notice(handle," clear") serv.notice(handle," DESACTIVATED (ask win and Aste ..) log (aliases : history, logs, list)") elif self.current_poll == "" and "new" in message: if utils.extract_message(message, "").strip() == "": serv.privmsg(canal,"You have to give a name ! You stupid winw") else: self.current_poll = utils.extract_message(message, "") serv.privmsg(canal,"New poll created : " + self.current_poll) self.insert_database() elif self.current_poll != "" and "new" in message: serv.privmsg(canal,"You can't create a new poll, because poll " + self.current_poll + " is not cleared") elif self.current_poll == "" and cmd not in self.no_poll_cmds: serv.privmsg(canal,"No poll currently running. !vote new <poll> or !vote history") elif message == "y" or message == "n": if handle not in self.nicks: self.nicks.append(handle) if message == "y": self.countY += 1 serv.privmsg(canal,"Y - " + str(self.countY) + "/" + str(self.countN) + " - N") elif message == "n": self.countN += 1 serv.privmsg(canal,"Y - " + str(self.countY) + "/" + str(self.countN) + " - N") else: serv.privmsg(canal,"<" + handle + "> : You've already voted for poll " + str(self.poll_id)) # elif elif message == "clear": self.poll_list.append({"poll_id": self.poll_id, "name": self.current_poll, "y": str(self.countY), "n": str(self.countN), "nicks": self.nicks}) self.update_database() self.poll_id += 1 self.current_poll = "" self.countY = 0 self.nicks = [] self.countN = 0 serv.privmsg(canal, "Poll Nb " + str(self.poll_id - 1) + " saved and cleared.") elif message == "results": serv.privmsg(canal, "Results for poll " + self.current_poll) serv.privmsg(canal, "Yes : " + str(self.countY)) serv.privmsg(canal, "No : " + str(self.countN)) elif message in ["logs", "log", "list", "history"] and 1==0: if len(self.poll_list) == 0: serv.privmsg(canal, "Empty history.") else: serv.privmsg(canal, "History of " + str(len(self.poll_list)) + " polls in notice") for poll in self.poll_list: serv.notice(handle, "Poll " + str(poll["poll_id"]) + " : " + poll["name"]) serv.notice(handle, "Y - " + str(poll["y"]) + "/" + str(poll["n"]) + " - N") else: serv.notice(handle,"Command : !vote <action>") serv.notice(handle,"actions :") serv.notice(handle," new <poll_name>") serv.notice(handle," y") serv.notice(handle," n") serv.notice(handle," results") serv.notice(handle," clear") serv.notice(handle," DESACTIVATED (ask win and Aste ..) log (aliases : history, logs, list)") if self.current_poll != "": self.update_database()
def badparse(self, text): cmd = utils.extract_command(text) self.assertEqual(None, cmd)
def goodparse(self, text): cmd = utils.extract_command(text) self.assertEqual("status", cmd)