def test_bot_survivor(self, irc_msg): user = User("uzi") user.save() User("uzibot").save() User.register_bot("uzibot", "don.cannon") irc_response = irc_msg("uzi", "!hatebot uzibot") result = CommandRouter(irc_response, logger).build_response() BotVote.count() == 1 assert result == "Thank you for your vote @uzi"
def test_tribal_council(self): User.register_bot("uzibot", "don.cannon") User.register_bot("enobot", "eno") BotVote("beginbotbot", "uzibot").save() BotVote("future", "uzibot").save() BotVote("carti", "enobot").save() assert BotVote.count() == 3 result = BotSurvivorRouter("beginbotbot", "tribal_council", []).route() assert result == "@uzibot has been kicked out of BeginWorld"
def test_changing_your_vote(self): User.register_bot("uzibot", "don.cannon") User.register_bot("enobot", "eno") result = BotSurvivorRouter("beginbotbot", "hatebot", ["uzibot"]).route() assert BotVote.count() == 1 assert result == "Thank you for your vote @beginbotbot" result = BotSurvivorRouter("beginbotbot", "hatebot", ["enobot"]).route() assert BotVote.count() == 1 assert result == "Thank you for your vote @beginbotbot"
def test_voting_for_a_bot(self): User("uzibot", 1) result = User.register_bot("uzibot", "don.cannon") result = BotSurvivorRouter("beginbotbot", "hatebot", ["uzibot"]).route() assert BotVote.count() == 1 assert result == "Thank you for your vote @beginbotbot"
def route(self): if self.command in ["hatebot", "votebotout"]: if self.parser.target_user: potential_bot = User(self.parser.target_user) if potential_bot.is_bot(): # We need to update vote for that user result = BotVote(self.user, potential_bot.name).create_or_update() return f"Thank you for your vote @{self.user}" else: return f"@{self.user} @{self.parser.target_user} is NOT A BOT!" if self.command == "tribal_council" and self.user == "beginbotbot": print("TRIBAL COUNCIL TIME!!!") # result = TribalCouncil.go_to_tribal() loser = BotVote.count_by_group("bot")[0][0] return f"@{loser} has been kicked out of BeginWorld"
def go_to_tribal(cls): votes = {} votes_ids = [] for vote in BotVote.db().all(): bot_name = vote["bot"] votes_ids.append(vote.doc_id) votes[bot_name] = votes.get(bot_name, []) + [vote["user"]] council_numbers = [ council["council_number"] for council in TribalCouncil.db().all() ] if council_numbers: last_council_number = max(council_numbers) + 1 else: last_council_number = 1 TribalCouncil(votes, last_council_number).save() BotVote.db().remove(doc_ids=votes_ids)
async def generate_bots_page(winner): bots = User.bots() bot_votes = BotVote.count_by_group("bot") context = { "base_url": DEPLOY_URL, "bots": bots, "bot_votes": bot_votes, "winner": winner, } await _render_and_save_html("bots.html", context, "bots.html")
def test_bot_vote(self): TribalCouncil.count() == 0 uzi = User("uzi") bot = User("uzibot") BotVote(user=uzi.name, bot=bot.name).save() assert BotVote.count() == 1 vote = BotVote.last() vote["bot"] == "uzibot" vote["user"] == "uzi" TribalCouncil.go_to_tribal() assert TribalCouncil.count() == 1 vote = TribalCouncil.last() assert vote == {"council_number": 1, "votes": {"uzibot": ["uzi"]}} BotVote(user=uzi.name, bot="pattymartinobot").save() TribalCouncil.go_to_tribal() assert TribalCouncil.count() == 2 vote = TribalCouncil.last() assert vote == {"council_number": 2, "votes": {"pattymartinobot": ["uzi"]}}
def test_try_to_vote_for_non_bot(self): User("uzibot_notbot").save() result = BotSurvivorRouter("beginbotbot", "hatebot", ["uzibot_notbot"]).route() assert BotVote.count() == 0 assert result == "@beginbotbot @uzibot_notbot is NOT A BOT!"