async def fstop(self, ctx):
        """Fstop command"""

        from botc.gameloops import nomination_loop, base_day_loop, debate_timer

        # Stop the nomination loop if it is running
        if nomination_loop.is_running():
            nomination_loop.cancel()

        # Stop the base day loop if it is running
        if base_day_loop.is_running():
            base_day_loop.cancel()

        # Stop the debate timer loop if it is running
        if debate_timer.is_running():
            debate_timer.cancel()

        # Stop the gameplay loop if it is running
        import globvars
        if globvars.master_state.game.gameloop.is_running():
            globvars.master_state.game.gameloop.cancel()
            feedback = documentation["doc"]["fstop"]["feedback"]
            await ctx.send(feedback.format(botutils.BotEmoji.check))
        else:
            feedback = documentation["cmd_warnings"]["no_game_running"]
            await ctx.send(
                feedback.format(ctx.author.mention, botutils.BotEmoji.cross))
Beispiel #2
0
    async def fnight(self, ctx):
        """Fnight command"""

        import globvars
        if globvars.master_state.game.current_phase == Phase.day:

            from botc.gameloops import (base_day_loop, debate_timer,
                                        nomination_loop)

            # Stop the nomination loop if it is running
            if nomination_loop.is_running():
                nomination_loop.cancel()

            # Stop the base day loop if it is running
            if base_day_loop.is_running():
                base_day_loop.cancel()

            # Stop the debate timer loop if it is running
            if debate_timer.is_running():
                debate_timer.cancel()

            import botc.switches
            botc.switches.master_proceed_to_night = True
            msg = game_text["doc"]["fnight"]["feedback"].format(
                botutils.BotEmoji.success)

            await ctx.send(msg)
Beispiel #3
0
    async def votestop(self, ctx):
        """Votestop command"""

        import globvars

        if ctx.author.id in globvars.votestop_votes:
            return

        globvars.votestop_votes.append(ctx.author.id)

        votes_needed = math.ceil(len(globvars.master_state.game.player_obj_list) / 2)

        if not votestop_votes_timer.is_running():
            votestop_votes_timer.start()

        await send_lobby(votestop_vote.format(ctx.author.mention, votes_needed - len(globvars.votestop_votes), "" if votes_needed - len(globvars.votestop_votes) == 1 else "s"))

        if len(globvars.votestop_votes) >= votes_needed:
            votestop_votes_timer.cancel()

            from botc.gameloops import (base_day_loop, debate_timer,
                                        nomination_loop)

            # Stop the nomination loop if it is running
            if nomination_loop.is_running():
                nomination_loop.cancel()

            # Stop the base day loop if it is running
            if base_day_loop.is_running():
                base_day_loop.cancel()

            # Stop the debate timer loop if it is running
            if debate_timer.is_running():
                debate_timer.cancel()

            # Stop the gameplay loop if it is running
            import globvars
            if globvars.master_state.game.gameloop.is_running():
                globvars.master_state.game.gameloop.cancel()
Beispiel #4
0
    async def time(self, ctx):
        """Time command
        usage: time
        can be used by all players or in DM
        """
        import globvars

        # Day phase
        if globvars.master_state.game.current_phase == Phase.day:

            # Day phase: pre-nomination (base day phase)
            if base_day_loop.is_running():

                start_time = base_day_loop.next_iteration
                total_duration = calculate_base_day_duration(
                    globvars.master_state.game)
                __time_elapsed = (
                    datetime.datetime.now(datetime.timezone.utc) -
                    start_time).seconds
                time_left = total_duration - __time_elapsed

                msg = time_day_base.format(
                    display_time(total_duration), "is" if time_left == 1 or
                    (time_left >= 60 and time_left < 120) else "are",
                    display_time(time_left))

                await ctx.send(msg)

            # Day phase: nomination loop is running
            elif nomination_loop.is_running():

                # We are in the debate phase
                if debate_timer.is_running():
                    end_time = debate_timer.next_iteration
                    total_duration = DEBATE_TIME
                    time_left = (
                        end_time -
                        datetime.datetime.now(datetime.timezone.utc)).seconds
                    msg = time_debate.format(display_time(total_duration),
                                             display_time(time_left))
                    await ctx.send(msg)

                # We are in the active voting phase
                else:
                    msg = time_voting
                    await ctx.send(msg)

            # Day phase: waiting for a nomination
            else:
                start_time = globvars.master_state.game.nomination_iteration_date[
                    0]
                duration = globvars.master_state.game.nomination_iteration_date[
                    1]
                time_left = duration - (datetime.datetime.now() -
                                        start_time).seconds
                msg = time_nomination.format(display_time(duration),
                                             display_time(time_left))
                await ctx.send(msg)

        # Night phase
        elif globvars.master_state.game.current_phase == Phase.night:

            min_night_duration = BASE_NIGHT
            max_night_duration = BASE_NIGHT + NIGHT_MULTIPLER * INCREMENT
            __time_elapsed = (
                datetime.datetime.now() -
                globvars.master_state.game.night_start_time).seconds
            time_left = max_night_duration - __time_elapsed

            msg = time_night.format(
                display_time(min_night_duration),
                display_time(max_night_duration), "is" if time_left == 1 or
                (time_left >= 60 and time_left < 120) else "are",
                display_time(time_left))

            await ctx.send(msg)

        # Dawn phase
        elif globvars.master_state.game.current_phase == Phase.dawn:

            min_dawn_duration = BASE_DAWN
            max_dawn_duration = BASE_DAWN + DAWN_MULTIPLIER * INCREMENT
            __time_elapsed = (
                datetime.datetime.now() -
                globvars.master_state.game.dawn_start_time).seconds
            time_left = max_dawn_duration - __time_elapsed

            msg = time_dawn.format(
                display_time(min_dawn_duration),
                display_time(max_dawn_duration), "is" if time_left == 1 or
                (time_left >= 60 and time_left < 120) else "are",
                display_time(time_left))

            await ctx.send(msg)