示例#1
0
def night():
    """Start the second part of the day.  
    The function assumes all polls have been evaluated, and that looking after attacks can begin.  
    The function returns a Mailbox."""
    threat = db.get_kill()
    answer = Mailbox().log("**Results from daily deaths:**")

    if dy.get_stage() == "Night":
        return Mailbox().respond("Sure, man. Whatever.")

    while threat != None:

        answer = roles.attack(threat[1],threat[2],threat[3],answer)
        threat = db.get_kill()

    for player in db.player_list(True):
        # Give potential night uses
        user_role = db_get(player,'role')
        for i in range(len(roles.night_users)):
            if user_role in roles.night_users[i]:
                # Give one-time users their one-time power
                if i == 0:
                    if dy.day_number() == 0:
                        db_set(player,'uses',1)
                    break

                if user_role in ['White Werewolf'] and dy.day_number() % 2 == 0:
                    i = 1

                db_set(player,'uses',i)
                answer.msg(power.power(user_role),db_get(player,'channel'))
                break

    answer.story(evening.evening(db.get_deadies()))
    db.delete_deadies()

    # Add polls
    for player in db.player_list():
        if db_get(player,'role') in pos.wolf_pack:
            for channel_id in db.get_secret_channels('Werewolf'):
                answer.new_poll(channel_id,'wolf',db.random_wolf(),story_text('wolf'))
            break
    for player in db.player_list():
        if db_get(player,'role') == 'Cult Leader':
            for channel_id in db.get_secret_channels('Cult_Leader'):
                answer.new_poll(channel_id,'cult',db.random_cult(),story_text('cult'))
            break
    for channel_id in db.get_secret_channels('Swamp'):
        answer.new_poll(channel_id,'thing','',story_text('thing'))

    answer.log("```Night {}```".format(dy.day_number()))
    dy.set_stage("Night")

    return answer
示例#2
0
def day():
    """Start the second part of the day.  
    The function assumes all polls have been evaluated, and that looking after attacks can begin.  
    The function returns a Mailbox."""
    threat = db.get_kill()
    answer = Mailbox().log("**Results from night attacks:**")

    if dy.get_stage() == "Day":
        return Mailbox().respond("Sure, man. Whatever.")

    while threat != None:

        answer = roles.attack(threat[1], threat[2], threat[3], answer)
        threat = db.get_kill()

    for player in db.player_list(True):
        # Give potential day uses
        user_role = db_get(player, 'role')
        for i in range(len(roles.day_users)):
            if user_role in roles.day_users[i]:
                # Give one-time users their one-time power
                if i == 0:
                    if dy.day_number() == 0:
                        db_set(player, 'uses', 1)
                    break

                db_set(player, 'uses', i)
                answer.msg(power.power(user_role), db_get(player, 'channel'))
                break

    answer.story(morning.story_time(db.get_deadies()))
    db.delete_deadies()
    db.delete_hookers()

    # Add polls
    if dy.day_number() != 0:
        answer.new_poll(dy.voting_booth(), 'lynch', '', story_text('lynch'))
    if dy.get_mayor() == 0:
        answer.new_poll(dy.voting_booth(), 'Mayor', '', story_text('Mayor'))
    elif dy.get_reporter() == 0:
        answer.new_poll(dy.voting_booth(), 'Reporter', '',
                        story_text('Reporter'))

    dy.next_day()
    dy.set_stage('Day')
    answer.log("```Day {}```".format(dy.day_number()))

    return answer
示例#3
0
def pay():
    """This function takes care of all properties that need to happen in the first wave of the end of the night.
    The function returns a Mailbox."""

    if dy.get_stage() == "Day":
        return [
            Mailbox().respond(
                "Whaddaya mean, `{}pay`? It already **is** day, bud.".format(
                    config.universal_prefix))
        ]

    # Add all listeners
    if int(dy.day_number()) == 0:
        for spy_channel in db.get_secret_channels("Flute_Player"):
            for innocent_channel in db.get_secret_channels("Flute_Victims"):
                db.add_listener(spy_channel, innocent_channel)

    answer = Mailbox()
    answer_table = [Mailbox(True)]

    for user_id in db.player_list():
        user_role = db_get(user_id, 'role')

        # Remove potential night uses
        for i in range(len(roles.night_users)):
            if user_role in [
                    "White Werewolf"
            ] and (dy.day_number() % 2 == 0) and dy.day_number() > 0:
                db_set(user_id, 'uses', 1)
                break
            elif user_role in roles.night_users[i]:
                if i > 0:
                    db_set(user_id, 'uses', 0)
                break

        # Force Cupid to fall in love
        if user_role == "Cupid" and db_get(user_id, 'uses') > 0:
            chosen = False
            attempts = 0

            while not chosen and attempts < 1000:
                forced_victim = random.choice(db.player_list(True, True))
                chosen = cupid_kiss(user_id, forced_victim, False)

            answer_table.append(chosen)

        # Force Dog to become Innocent
        if user_role == "Dog" and db_get(user_id, 'uses') > 0:
            db_set(user_id, 'role', "Innocent")
            answer.msg(
                "You haven't chosen a role! That's why you have now become and **Innocent**!",
                db_get(user_id, 'channel'))
            answer.log(
                "The **Dog** <@{}> didn't choose a role last night and turned into an **Innocent**!"
                .format(user_id))

        # Remove hooker effects
        db_set(user_id, 'sleepingover', 0)
        for standoff in db.get_standoff(user_id):
            if standoff[2] == 'Hooker':
                db.delete_standoff(standoff[0])

        # Force Look-Alike to become Innocent
        if user_role == "Look-Alike":
            db_set(user_id, 'role', "Innocent")
            answer.msg(
                "You haven't chosen a role! That's why you have now become an **Innocent**!",
                db_get(user_id, 'channel'))
            answer.log(
                "The **Dog** <@{}> didn't choose a role last night and turned into an **Innocent**!"
                .format(user_id))

        # Remove tanner disguises
        db_set(user_id, 'fakerole', user_role)

        # Remove zombie tag
        db_set(user_id, 'bitten', 0)

    answer_table.append(answer)
    answer_table.append(Mailbox().spam(config.universal_prefix + "day"))
    return answer_table
示例#4
0
def count_votes(voting_table, purpose='lynch', mayor=0):
    """Count votes based on reactions given to """
    user_table = []
    blacklist = []
    blacklist2 = []
    emoji_table = []

    for vote in voting_table:
        # Add new emoji
        if vote[1] not in emoji_table:
            emoji_table.append(vote[1])

        # Filter self-votes and double votes
        if vote[0] in blacklist or vote[0] in blacklist2:
            pass
        elif vote[0] == emoji_to_player(
                vote[1]) and purpose not in ['Mayor', 'Reporter']:
            blacklist2.append(vote[0])
            if vote[0] in user_table:
                user_table.remove(vote[0])
        elif vote[0] in user_table:
            blacklist.append(vote[0])
            user_table.remove(vote[0])
        else:
            user_table.append(vote[0])

    # Evaluate table, filter double votes and continue
    if purpose == 'lynch':
        voting_table = [
            Vote(vote[0], vote[1], int(db_get(vote[0], 'votes')))
            for vote in voting_table if vote[0] in user_table
        ]
    else:
        voting_table = [
            Vote(vote[0], vote[1]) for vote in voting_table
            if vote[0] in user_table
        ]
    blacklist = [Disqualified(user) for user in blacklist]
    blacklist2 = [Disqualified(user, 1) for user in blacklist2]
    blacklist.extend(blacklist2)

    # Add extra (secret) outside lynches, may some special events happen.
    if purpose == 'lynch':
        for user in player_list():
            if int(db_get(user, 'threatened')) > 0:
                voting_table.append(
                    Vote("RAVEN THREAT", db_get(user, 'emoji'),
                         int(db_get(user, 'threatened'))))

                # Add emoji to table
                if db_get(user, 'emoji') not in emoji_table:
                    emoji_table.append(db_get(user, 'emoji'))

    # print([[vote.user,vote.emoji,vote.votes] for vote in voting_table])

    # Create the evaluation messages
    answer = "**__Poll results "
    log = "**__Poll results "

    if purpose == 'wolf':
        answer += "from wolf attack:__**\n\n"
        log += "from wolf attack:__**\n\n"
    elif purpose == 'cult':
        answer += "from cult attack:__**\n\n"
        log += "from cult attack:__**\n\n"
    elif purpose == 'thing':
        answer += "from the swamp:__**\n\n"
        log += "from the swamp:__**\n\n"
    elif purpose == 'lynch':
        answer += "from public execution on day {}:__**\n\n".format(
            day_number())
        log += "from public execution on day {}:__**\n\n".format(day_number())
    elif purpose == 'Mayor':
        answer += "from Mayor election:__**\n\n"
        log += "from Mayor election:__**\n\n"
    elif purpose == 'Reporter':
        answer += "from Reporter election:__**\n\n"
        log += "from Reporter election:__**\n\n"

    max_i = 0
    chosen_emoji = ''

    for emoji in emoji_table:
        emoji_votes = [vote for vote in voting_table if vote.emoji == emoji]

        if emoji_votes != []:
            for vote in emoji_votes:
                if vote.type == 'user':
                    answer += "**{} - VOTES FOR <@{}>:**\n".format(
                        emoji, emoji_to_player(emoji))
                    break
            log += "**{} - VOTES FOR <@{}>:**\n".format(
                emoji, emoji_to_player(emoji))
        i = 0

        for vote in emoji_votes:
            # vote.user
            # vote.type
            # vote.emoji
            # vote.votes
            if vote.type == 'user':
                answer += "<@{}> ".format(vote.user)
                log += "<@{}> ".format(vote.user)
                if vote.user == mayor:
                    vote.votes += 1
                    answer += "- @Mayor "
                    log += "- @Mayor "
                if vote.votes != 1:
                    log += "*({}x)* ".format(vote.votes)
                i += vote.votes
                log += '\n'
                answer += '\n'
            elif vote.type == 'generic':
                log += "{} ".format(vote.user)
                if vote.votes > 1:
                    log += "*({}x)* ".format(vote.votes)
                i += vote.votes
                log += '\n'
            else:
                answer += "*Oops! An error occured on this line!*\n"
                log += "*Oops! An error occured on this line! Looks like we\'ve got an undefined voting type!*\n"

        if i > 0:
            log += "**TOTAL: {} votes**\n\n".format(i)
        else:
            log += '\n\n'

        if i == max_i:
            chosen_emoji = ''
        if i > max_i:
            chosen_emoji = emoji
            max_i = i

    answer += "\n"
    log += "\n"

    for cheater in blacklist:
        if cheater.reason == 0:
            answer += "<@{}>, you have been disqualified for double voting.\n".format(
                cheater.user)
            log += "<@{}> has been disqualified for double voting.\n".format(
                cheater.user)
        if cheater.reason == 1:
            answer += "<@{}>, your vote has been disqualified for you may not vote for yourself on this poll.\n".format(
                cheater.user)
            log += "<@{}> has been disqualified for voting on themselves.\n".format(
                cheater.user)

    if chosen_emoji != '':
        answer += "\nThe emoji {} has the most votes, making <@{}> the winner of this poll!".format(
            chosen_emoji, emoji_to_player(chosen_emoji))
        log += "\nThe emoji {} has the most votes, effectively making <@{}> the winner of this poll.".format(
            chosen_emoji, emoji_to_player(chosen_emoji))
    elif emoji_table != []:
        answer += "\nIt seems like we\'ve reached a tie! No-one will win this poll, I\'m sorry!"
        log += "\nThe poll has reached a tie and will not choose a winner."
    else:
        answer += "\nIt seems like no-one has voted! Well, in that case, there won\'t be a winner either."
        log += "\nNo votes have been registered."

    return log, answer, chosen_emoji