def crazy_phrases(bot_input, bot_output): phrase = random.choice(phrases) # storage.set_hash_value(list_name, bot_input.nick, phrase) bot_output.say("you're in {0}".format(bot_input.nick)) user_phrases[bot_input.nick] = textutils.sanitize_message(phrase) user_points[bot_input.nick] = storage.get_hash_value(list_name, bot_input.nick) or 0 user = bot_output.get_user_by_name(bot_input.nick) bot_output.private_message(str(user["id"]), "Your phrase is: %s" % phrase)
def check_phrases(bot_input, bot_output): for user, phrase in user_phrases.items(): if phrase == textutils.sanitize_message(bot_input.message): if user == bot_input.nick: user_points[user] += 1 storage.set_hash_value(list_name, bot_input.nick, user_points[user]) user_info = bot_output.get_user_by_name(user) bot_output.private_message( str(user_info["id"]), "You got a point. Current score for you is: %s" % user_points[user] ) else: bot_output.say("Woot! Phrase that pays!") bot_output.say("%s had the phrase: %s" % (user, phrase)) bot_output.say("Good job " + bot_input.nick) user_points[user] = user_points[bot_input.nick] + 1 storage.set_hash_value(list_name, bot_input.nick, user_points[user])
def check_trivia(bot_input, bot_output): if current_trivia['question']: guess = textutils.sanitize_message(bot_input.input_string) current_answer = current_trivia['answer'] if compare_values(guess, current_answer): bot_output.say("That's correct, {0}. The answer to {1} is {2}".format(bot_input.nick, current_trivia['question'], current_trivia['answer'])) if current_trivia['guess'] == 0: bot_output.say('2 points for guessing on the first try.') add_point(bot_input.nick, 2) else: bot_output.say('1 point.') add_point(bot_input.nick, 1) new_question() bot_output.say('Next question\nCategory: %(category)s\n%(question)s?' % current_trivia) else: current_trivia['guess'] += 1 bot_output.say("WRONG {0}! Minus 1 point!".format(bot_input.nick).upper()) add_point(bot_input.nick, -1)
def log(self, bot_input, bot_output): sender = bot_input.nick[:10].lower() message = bot_input.input_string.replace(bot_output.nick.lower(), '') self.word_table.setdefault(sender, {}) if message.startswith('/') or message.startswith('.'): return try: say_something = (not self.is_ping(message, bot_output) and sender != bot_output.nick.lower()) and random.random() < bot_output.chattiness except AttributeError: say_something = False messages = [] seed_key = None if self.is_ping(message, bot_output): message = self.fix_ping(message, bot_output) for words in self.split_message(textutils.sanitize_message(message)): key = tuple(words[:-1]) if key in self.word_table: self.word_table[sender][key].append(words[-1]) else: self.word_table[sender][key] = [words[-1]] if self.stop_word not in key and say_something: for person in self.word_table: if person == sender: continue if key in self.word_table[person[:10]]: generated = self.generate_message(person[:10], seed_key=key) if generated: messages.append((person, generated)) self.activities += 1 if self._should_update(): self._save_data() if len(messages): self.last, message = random.choice(messages) return message