示例#1
0
    async def quit(self, ctx):
        """Quit command"""

        import globvars

        if globvars.master_state.game:
            # This check is to ensure a player doesn't quit right after !start
            # before the game is fully set up and end up breaking the game.
            return
        
        # The command user has joined; make them quit
        if globvars.master_state.pregame.is_joined(ctx.author.id):
            globvars.master_state.pregame.safe_remove_player(ctx.author.id)
            botutils.update_state_machine()
            await ctx.send(quit_str.format(ctx.author.name, len(globvars.master_state.pregame)))
            # If you are the last player to leave, then cancel the lobby timeout loop
            if len(globvars.master_state.pregame) == 0:
                lobby_timeout.cancel()
            # If the player has voted to start, then remove the start vote
            if ctx.author.id in globvars.start_votes:
                globvars.start_votes.remove(ctx.author.id)
            # Cancel the start clear timer if no one has voted to start
            if len(globvars.start_votes) == 0 and start_votes_timer.is_running():
                start_votes_timer.cancel()

        # The command user has not joined
        else:
            await ctx.send(quitted_str.format(ctx.author.mention))
        
        # Still take away the role from everyone just in case of discord sync issue
        await botutils.remove_alive_role(ctx.author, unlock=True)
    async def fleave(self, ctx, *, member: discord.Member):
        """Force leave command"""

        import globvars

        # The player has joined; make them leave
        if globvars.master_state.pregame.is_joined(member.id):
            globvars.master_state.pregame.safe_remove_player(member.id)
            await ctx.send(
                fleave_str.format(member.name,
                                  len(globvars.master_state.pregame)))
            botutils.update_state_machine()
            # If you are the last player to leave, then cancel the lobby timeout loop
            if len(globvars.master_state.pregame) == 0:
                lobby_timeout.cancel()
            # If the player has voted to start, then remove the start vote
            if member.id in globvars.start_votes:
                globvars.start_votes.remove(member.id)
            # Cancel the start clear timer if no one has voted to start
            if len(globvars.start_votes) == 0 and start_votes_timer.is_running(
            ):
                start_votes_timer.cancel()

        # The player has not joined
        else:
            await ctx.send(fleaved_str.format(ctx.author.mention, member.name))

        await botutils.remove_alive_role(member, unlock=True)
示例#3
0
    async def fleave(self, ctx, *members: Union[discord.Member, str]):
        """Force leave command"""

        import globvars

        if members[0] == "all":
            count = len(globvars.master_state.pregame) - 1
            for player in globvars.master_state.pregame:
                fetched_member = globvars.client.get_guild(
                    SERVER_ID).get_member(player)
                await ctx.send(
                    fleave_str.format(
                        (fetched_member.name if fetched_member else player),
                        count))
                if fetched_member:
                    await botutils.remove_alive_role(fetched_member)
                count -= 1
            globvars.master_state.pregame.clear()
            lobby_timeout.cancel()
            if start_votes_timer.is_running():
                start_votes_timer.cancel()
            botutils.update_state_machine()
        elif isinstance(members[0], discord.Member):
            for member in members:
                # The player has joined; make them leave
                if globvars.master_state.pregame.is_joined(member.id):
                    globvars.master_state.pregame.safe_remove_player(member.id)
                    await ctx.send(
                        fleave_str.format(member.name,
                                          len(globvars.master_state.pregame)))
                    botutils.update_state_machine()
                    # If you are the last player to leave, then cancel the lobby timeout loop
                    if len(globvars.master_state.pregame) == 0:
                        lobby_timeout.cancel()
                    # If the player has voted to start, then remove the start vote
                    if member.id in globvars.start_votes:
                        globvars.start_votes.remove(member.id)
                    # Cancel the start clear timer if no one has voted to start
                    if len(globvars.start_votes
                           ) == 0 and start_votes_timer.is_running():
                        start_votes_timer.cancel()

                # The player has not joined
                else:
                    await ctx.send(
                        fleaved_str.format(ctx.author.mention, member.name))

                await botutils.remove_alive_role(member)
示例#4
0
    async def fleave(self, ctx, *, member: discord.Member):
        """Force leave command"""

        import globvars

        # The player has joined; make them leave.
        if globvars.master_state.pregame.is_joined(member.id):
            globvars.master_state.pregame.safe_remove_player(member.id)
            await ctx.send(
                fleave_str.format(member.name,
                                  len(globvars.master_state.pregame)))
            botutils.update_state_machine()
            # If you are the last player to leave, then cancel the lobby timeout loop
            if len(globvars.master_state.pregame) == 0:
                lobby_timeout.cancel()

        # The player has not joined.
        else:
            await ctx.send(fleaved_str.format(ctx.author.mention, member.name))

        await botutils.remove_alive_role(member)
    async def quit(self, ctx):
        """Quit command"""

        import globvars

        # The command user has joined; make them quit
        if globvars.master_state.pregame.is_joined(ctx.author.id):
            globvars.master_state.pregame.safe_remove_player(ctx.author.id)
            botutils.update_state_machine()
            await ctx.send(
                quit_str.format(ctx.author.name,
                                len(globvars.master_state.pregame)))
            # If you are the last player to leave, then cancel the lobby timeout loop
            if len(globvars.master_state.pregame) == 0:
                lobby_timeout.cancel()

        # The command user has not joined
        else:
            await ctx.send(quitted_str.format(ctx.author.mention))

        # Still take away the role from everyone just in case of discord sync issue
        await botutils.remove_alive_role(ctx.author)
示例#6
0
    async def join(self, ctx):
        """Join command"""

        import globvars

        if globvars.master_state.game:
            # This check is to ensure a player doesn't join right after !start
            # before the game is fully set up and end up breaking the game.
            return

        # The command user has already joined
        if globvars.master_state.pregame.is_joined(ctx.author.id):
            await ctx.send(joined_str.format(ctx.author.mention))

        # The command user has not joined yet; make them join
        else:
            user_ids = set()

            with sqlite3.connect("data.sqlite3") as conn:
                c = conn.cursor()

                c.execute(
                    """
                SELECT
                    primary_user_id,
                    secondary_user_id
                FROM
                    player_map
                WHERE
                    primary_user_id = :user_id
                    OR secondary_user_id = :user_id
                """, {
                        "user_id": ctx.author.id,
                    })

                for row in c.fetchall():
                    primary, secondary = row

                    user_ids.add(primary)
                    user_ids.add(secondary)

            for user_id in globvars.master_state.pregame:
                if user_id in user_ids:
                    user = globvars.client.get_user(user_id)
                    await ctx.send(
                        joined_alt_str.format(ctx.author.mention, str(user)))
                    return

            globvars.master_state.pregame.safe_add_player(ctx.author.id)
            botutils.update_state_machine()
            join_replies = bot_text["doc"]["join"]["outputs"]
            join_weights = bot_text["doc"]["join"]["weights"]

            if join_weights:
                join_reply = random.choices(join_replies, weights=join_weights)
                join_str = join_reply[0]
            else:
                join_str = random.choice(join_replies)

            emoji = random.choice(emojis)
            msg = emoji
            msg += " "
            msg += join_str.format(
                ctx.author.name, len(globvars.master_state.pregame), "player"
                if len(globvars.master_state.pregame) == 1 else "players")
            await ctx.send(msg)

            # If you are the first player to join the game, then start the lobby timeout loop
            if len(globvars.master_state.pregame) == 1:
                if lobby_timeout.is_running():
                    lobby_timeout.cancel()
                lobby_timeout.start()

        # Still give everyone the role just in case of discord sync issue
        await botutils.add_alive_role(ctx.author)