def _conv_impl(self, executor, respond_target, cmd, arguments, e, nick, all_nicks): nick_match = None tries = 20 lines = queries.get_random_lines_like(executor, nick, e.target, "%:%", tries) if not lines: logger.debug("No directed lines by the user") return for line in lines: nick_match = re.match("([^:]*):", line) logger.debug(nick_match.group(1)) if nick_match.group(1) not in all_nicks: nick_match = None # Didn't really find a nick if nick_match: break if nick_match: next_nick = nick_match.group(1) if random.randint(0, 5) == 0: # 1/6 chance that we end the conversation means average # conversation length is 5 lines firstline = queries.get_random_line(executor, next_nick, e.target) self.connection.privmsg(respond_target, "<{}> {}".format(next_nick, firstline)) else: self._conv_impl(executor, respond_target, cmd, arguments, e, next_nick, all_nicks) else: logger.error( ( """"{}" contains a nick according to the database, """ + """but it really doesn't; aborting here""" ).format(line) ) self.connection.privmsg(respond_target, "<{}> {}".format(nick, line))
def _do_replay(self, executor, respond_target, cmd, arguments, e, nick): logger.debug("_do_replay") line = queries.get_random_line(executor, nick, e.target) if line != None: self.connection.privmsg(respond_target, "<{}> {}".format(nick, line)) else: self.connection.privmsg(respond_target, "{} has no history!".format(nick))
def _do_replay(self, executor, respond_target, cmd, arguments, e, nick): logger.debug("_do_replay") line = queries.get_random_line(executor, nick, e.target) if line is not None: self.connection.privmsg(respond_target, "<{}> {}".format(nick, line)) else: self.connection.privmsg(respond_target, "{} has no history!".format(nick))
def _conv_impl(self, executor, respond_target, cmd, arguments, e, nick, all_nicks): nick_match = None tries = 20 lines = queries.get_random_lines_like(executor, nick, e.target, '%:%', tries) if not lines: logger.debug('No directed lines by the user') return for line in lines: nick_match = re.match('([^:]*):', line) logger.debug(nick_match.group(1)) if nick_match.group(1) not in all_nicks: nick_match = None # Didn't really find a nick if nick_match: break if nick_match: next_nick = nick_match.group(1) if random.randint(0, 5) == 0: # 1/6 chance that we end the conversation means average # conversation length is 5 lines firstline = queries.get_random_line( executor, next_nick,e.target) self.connection.privmsg( respond_target, "<{}> {}".format(next_nick, firstline) ) else: self._conv_impl(executor, respond_target, cmd, arguments, e, next_nick, all_nicks) else: logger.error( ('''"{}" contains a nick according to the database, ''' + '''but it really doesn't; aborting here''').format(line)) self.connection.privmsg(respond_target, "<{}> {}".format(nick, line))
def _conv_impl(self, executor, respond_target, cmd, arguments, e, nick): nick_match = None tries = 20 while not nick_match: line = queries.get_random_line_like(executor, nick, e.target, '%:%') if line is None: # no directed lines by the user logger.debug('No directed lines by the user') return nick_match = re.match('([^:]*):', line) logger.debug(nick_match) tries -= 1 if tries == 0: logger.debug(line) logger.warning( "Something's gone horribly wrong. " + "Giving up on conversation" ) return if nick_match: next_nick = nick_match.group(1) if random.randint(0, 5) == 0: # 1/6 chance that we end the conversation means average # conversation length is 5 lines line = queries.get_random_line(executor, next_nick, e.target) self.connection.privmsg( respond_target, "<{}> {}".format(next_nick, line) ) else: self._conv_impl(executor, respond_target, cmd, arguments, e, next_nick) else: logger.error( ('''"{}" contains a nick according to the database, ''' + '''but it really doesn't''').format(line)) self.connection.privmsg(respond_target, "<{}> {}".format(nick, line))