Exemplo n.º 1
0
    async def remove(self, ctx, *, args):
        logger.info("command: remove")

        await channel_setup(ctx)
        await user_setup(ctx)

        raw_roles = ctx.author.roles
        user_role_names = [role.name.lower() for role in raw_roles]
        user_role_ids = [role.id for role in raw_roles]
        args = args.upper().split(" ")

        for arg in args:
            if arg not in list(states.keys()):
                logger.info("invalid state")
                await ctx.send(
                    f"**Sorry, `{arg}` is not a valid state.**\n*Valid States:* `{', '.join(map(str, list(states.keys())))}`"
                )

            elif states[arg]["aliases"][0].lower() not in user_role_names[1:]:
                logger.info("doesn't have role")
                await ctx.send(
                    f"**You don't have the `{arg}` state role!**\n*Your Roles:* `{', '.join(map(str, user_role_names[1:]))}`"
                )

            else:
                logger.info("deleting role")
                index = user_role_names.index(
                    states[arg]["aliases"][0].lower())
                role = ctx.guild.get_role(user_role_ids[index])
                await ctx.author.remove_roles(
                    role, reason="Delete state role for bird list")
                await ctx.send(f"**Ok, role {role.name} deleted!**")
Exemplo n.º 2
0
    async def start(self, ctx, *, args_str: str = ""):
        logger.info("command: start session")

        await channel_setup(ctx)
        await user_setup(ctx)

        if database.exists(f"session.data:{str(ctx.author.id)}"):
            logger.info("already session")
            await ctx.send("**There is already a session running.** *Change settings/view stats with `b!session edit`*")
            return
        else:
            args = args_str.split(" ")
            logger.info(f"args: {args}")
            if "bw" in args:
                bw = "bw"
            else:
                bw = ""
            states_args = set(states.keys()).intersection({arg.upper() for arg in args})
            if states_args:
                state = " ".join(states_args).strip()
            else:
                state = " ".join(check_state_role(ctx))
            order_args = set(orders["orders"]).intersection({arg.lower() for arg in args})
            if order_args:
                order = " ".join(order_args).strip()
            else:
                order = ""
            female = "female" in args or "f" in args
            juvenile = "juvenile" in args or "j" in args
            if female and juvenile:
                await ctx.send("**Juvenile females are not yet supported.**\n*Please try again*")
                return
            elif female:
                addon = "female"
            elif juvenile:
                addon = "juvenile"
            else:
                addon = ""
            logger.info(f"adding bw: {bw}; addon: {addon}; state: {state}")

            database.hmset(
                f"session.data:{str(ctx.author.id)}", {
                    "start": round(time.time()),
                    "stop": 0,
                    "correct": 0,
                    "incorrect": 0,
                    "total": 0,
                    "bw": bw,
                    "state": state,
                    "addon": addon,
                    "order": order
                }
            )
            await ctx.send(f"**Session started with options:**\n{await self._get_options(ctx)}")
Exemplo n.º 3
0
def check_state_role(ctx):
    logger.info("checking roles")
    user_states = []
    if ctx.guild is not None:
        logger.info("server context")
        user_role_names = [role.name.lower() for role in ctx.author.roles]
        for state in list(states.keys()):
            # gets similarities
            if len(set(user_role_names).intersection(set(states[state]["aliases"]))) is not 0:
                user_states.append(state)
    else:
        logger.info("dm context")
    logger.info(f"user roles: {user_states}")
    return user_states
Exemplo n.º 4
0
    async def list_of_birds(self, ctx, state: str = "blank"):
        logger.info("command: list")

        await channel_setup(ctx)
        await user_setup(ctx)

        state = state.upper()

        if state not in list(states.keys()):
            logger.info("invalid state")
            await ctx.send(
                f"**Sorry, `{state}` is not a valid state.**\n*Valid States:* `{', '.join(map(str, list(states.keys())))}`"
            )
            return

        birdLists = []
        temp = ""
        for bird in states[state]['birdList']:
            temp += f"{str(bird)}\n"
            if len(temp) > 1950:
                birdLists.append(temp)
                temp = ""
        birdLists.append(temp)

        songLists = []
        temp = ""
        for bird in states[state]['songBirds']:
            temp += f"{str(bird)}\n"
            if len(temp) > 1950:
                songLists.append(temp)
                temp = ""
        songLists.append(temp)

        if ctx.author.dm_channel is None:
            await ctx.author.create_dm()

        await ctx.author.dm_channel.send(f"**The {state} bird list:**")
        for birds in birdLists:
            await ctx.author.dm_channel.send(f"```{birds}```")

        await ctx.author.dm_channel.send(f"**The {state} bird songs:**")
        for birds in songLists:
            await ctx.author.dm_channel.send(f"```{birds}```")

        await ctx.send(
            f"The `{state}` bird list has **{str(len(states[state]['birdList']))}** birds.\n"
            +
            f"The `{state}` bird list has **{str(len(states[state]['songBirds']))}** songs.\n"
            + "*A full list of birds has been sent to you via DMs.*")
Exemplo n.º 5
0
    async def state(self, ctx, *, args):
        logger.info("command: state set")

        await channel_setup(ctx)
        await user_setup(ctx)

        roles = [role.name.lower() for role in ctx.author.roles]
        args = args.upper().split(" ")

        for arg in args:
            if arg not in list(states.keys()):
                logger.info("invalid state")
                await ctx.send(
                    f"**Sorry, `{arg}` is not a valid state.**\n*Valid States:* `{', '.join(map(str, list(states.keys())))}`"
                )

            elif len(set(roles).intersection(set(
                    states[arg]["aliases"]))) is 0:  # gets similarities
                # need to add roles (does not have role)
                logger.info("add roles")
                raw_roles = ctx.guild.roles
                guild_role_names = [role.name.lower() for role in raw_roles]
                guild_role_ids = [role.id for role in raw_roles]

                if states[arg]["aliases"][0].lower() in guild_role_names:
                    # guild has role
                    index = guild_role_names.index(
                        states[arg]["aliases"][0].lower())
                    role = ctx.guild.get_role(guild_role_ids[index])

                else:
                    # create role
                    logger.info("creating role")
                    role = await ctx.guild.create_role(
                        name=string.capwords(states[arg]["aliases"][0]),
                        permissions=discord.Permissions.none(),
                        hoist=False,
                        mentionable=False,
                        reason="Create state role for bird list")

                await ctx.author.add_roles(
                    role, reason="Set state role for bird list")
                await ctx.send(f"**Ok, added the {role.name} role!**")

            else:
                # have roles already (there were similarities)
                logger.info("already has role")
                await ctx.send(f"**You already have the `{arg}` role!**")
Exemplo n.º 6
0
    async def start(self, ctx, *, args_str: str = ""):
        logger.info("command: start race")

        await channel_setup(ctx)
        await user_setup(ctx)

        if ctx.guild is None:
            logger.info("dm context")
            await ctx.send("**Sorry, racing is not avaliable in DMs.**")
            return

        if not str(ctx.channel.name).startswith("racing"):
            logger.info("not race channel")
            await ctx.send("**Sorry, racing is not availiable in this channel.**\n" +
                           "*Set the channel name to start with `racing` to enable it.*")
            return

        if database.exists(f"race.data:{str(ctx.channel.id)}"):
            logger.info("already race")
            await ctx.send("**There is already a race in session.** *Change settings/view stats with `b!race view`*")
            return
        else:
            args = args_str.split(" ")
            logger.info(f"args: {args}")
            if "bw" in args:
                bw = "bw"
            else:
                bw = ""

            states_args = set(states.keys()).intersection(
                {arg.upper() for arg in args})
            if states_args:
                state = " ".join(states_args).strip()
            else:
                state = " ".join(check_state_role(ctx))

            female = "female" in args or "f" in args
            juvenile = "juvenile" in args or "j" in args
            if female and juvenile:
                await ctx.send("**Juvenile females are not yet supported.**\n*Please try again*")
                return
            elif female:
                addon = "female"
            elif juvenile:
                addon = "juvenile"
            else:
                addon = ""

            song = "song" in args or "s" in args
            image = "image" in args or "i" in args or "picture" in args or "p" in args
            if song and image:
                await ctx.send("**Songs and images are not yet supported.**\n*Please try again*")
                return
            elif song:
                media = "song"
            elif image:
                media = "image"
            else:
                media = "image"

            ints = []
            for n in args:
                try:
                    ints.append(int(n))
                except ValueError:
                    continue
            if len(ints) is not 0:
                limit = int(ints[0])
            else:
                limit = 10

            if limit > 1000000:
                await ctx.send("**Sorry, the maximum amount to win is 1 million.**")
                limit = 1000000

            logger.info(
                f"adding bw: {bw}; addon: {addon}; state: {state}; media: {media}; limit: {limit}")

            database.hmset(
                f"race.data:{str(ctx.channel.id)}", {
                    "start": round(time.time()),
                    "stop": 0,
                    "limit": limit,
                    "bw": bw,
                    "state": state,
                    "addon": addon,
                    "media": media
                }
            )

            database.zadd(f"race.scores:{str(ctx.channel.id)}", {
                          str(ctx.author.id): 0})
            await ctx.send(f"**Race started with options:**\n{await self._get_options(ctx)}")

            if str(database.hget(f"race.data:{str(ctx.channel.id)}", "media"))[2:-1] == "image":
                logger.info("auto sending next bird image")
                addon, bw = map(str, database.hmget(
                    f"race.data:{str(ctx.channel.id)}", ["addon", "bw"]))
                birds = self.bot.get_cog("Birds")
                await birds.send_bird_(ctx, addon[2:-1], bw[2:-1])

            if str(database.hget(f"race.data:{str(ctx.channel.id)}", "media"))[2:-1] == "song":
                logger.info("auto sending next bird song")
                birds = self.bot.get_cog("Birds")
                await birds.send_song_(ctx)
Exemplo n.º 7
0
    async def bird_orders(self,
                          ctx,
                          order: str = "blank",
                          state: str = "blank"):
        logger.info("command: orders")

        await channel_setup(ctx)
        await user_setup(ctx)

        order = order.lower()
        state = state.upper()

        if order not in list(orders["orders"]):
            logger.info("invalid order")
            await ctx.send(
                f"**Sorry, `{order}` is not a valid order.**\n*Valid Orders:* `{', '.join(map(str, list(orders['orders'])))}`"
            )
            return

        if state not in list(states.keys()):
            logger.info("invalid state")
            await ctx.send(
                f"**Sorry, `{state}` is not a valid state.**\n*Valid States:* `{', '.join(map(str, list(states.keys())))}`"
            )
            return

        birds_in_order = set(orders[order])
        birds_in_state = set(states[state]["birdList"])
        song_birds_in_state = set(states[state]["songBirds"])
        bird_list = list(birds_in_order.intersection(birds_in_state))
        song_bird_list = list(birds_in_order.intersection(song_birds_in_state))

        if len(bird_list) is 0 and len(song_bird_list) is 0:
            logger.info("no birds for order/state")
            await ctx.send(
                f"**Sorry, no birds could be found for the order/state combo.**\n*Please try again*"
            )
            return

        birdLists = []
        temp = ""
        for bird in bird_list:
            temp += f"{str(bird)}\n"
            if len(temp) > 1950:
                birdLists.append(temp)
                temp = ""
        birdLists.append(temp)

        songLists = []
        temp = ""
        for bird in song_bird_list:
            temp += f"{str(bird)}\n"
            if len(temp) > 1950:
                songLists.append(temp)
                temp = ""
        songLists.append(temp)

        if ctx.author.dm_channel is None:
            await ctx.author.create_dm()

        await ctx.author.dm_channel.send(
            f"**The `{order}` in the `{state}` bird list:**")
        for birds in birdLists:
            await ctx.author.dm_channel.send(f"```{birds}```")

        await ctx.author.dm_channel.send(
            f"**The `{order}` in the `{state}` bird songs:**")
        for birds in songLists:
            await ctx.author.dm_channel.send(f"```{birds}```")

        await ctx.send(
            f"The `{order}` in the `{state}` bird list has **{str(len(bird_list))}** birds.\n"
            +
            f"The `{order}` in the `{state}` bird list has **{str(len(song_bird_list))}** songs.\n"
            + "*A full list of birds has been sent to you via DMs.*")
Exemplo n.º 8
0
    async def edit(self, ctx, *, args_str: str = ""):
        logger.info("command: view session")

        await channel_setup(ctx)
        await user_setup(ctx)

        if database.exists(f"session.data:{str(ctx.author.id)}"):
            args = args_str.split(" ")
            logger.info(f"args: {args}")
            if "bw" in args:
                if len(database.hget(f"session.data:{str(ctx.author.id)}", "bw")) is 0:
                    logger.info("adding bw")
                    database.hset(f"session.data:{str(ctx.author.id)}", "bw", "bw")
                else:
                    logger.info("removing bw")
                    database.hset(f"session.data:{str(ctx.author.id)}", "bw", "")
            states_args = set(states.keys()).intersection({arg.upper() for arg in args})
            if states_args:
                toggle_states = list(states_args)
                current_states = str(database.hget(f"session.data:{str(ctx.author.id)}", "state"))[2:-1].split(" ")
                add_states = []
                logger.info(f"toggle states: {toggle_states}")
                logger.info(f"current states: {current_states}")
                for state in set(toggle_states).symmetric_difference(set(current_states)):
                    add_states.append(state)
                logger.info(f"adding states: {add_states}")
                database.hset(f"session.data:{str(ctx.author.id)}", "state", " ".join(add_states).strip())
            order_args = set(orders["orders"]).intersection({arg.lower() for arg in args})
            if order_args:
                toggle_order = list(order_args)
                current_orders = str(database.hget(f"session.data:{str(ctx.author.id)}", "order"))[2:-1].split(" ")
                add_orders = []
                logger.info(f"toggle orders: {toggle_order}")
                logger.info(f"current orders: {current_orders}")
                for o in set(toggle_order).symmetric_difference(set(current_orders)):
                    add_orders.append(o)
                logger.info(f"adding orders: {add_orders}")
                database.hset(f"session.data:{str(ctx.author.id)}", "order", " ".join(add_orders).strip())
            female = "female" in args or "f" in args
            juvenile = "juvenile" in args or "j" in args
            if female and juvenile:
                await ctx.send("**Juvenile females are not yet supported.**\n*Please try again*")
                return
            elif female:
                addon = "female"
                if len(database.hget(f"session.data:{str(ctx.author.id)}", "addon")) is 0:
                    logger.info("adding female")
                    database.hset(f"session.data:{str(ctx.author.id)}", "addon", addon)
                else:
                    logger.info("removing female")
                    database.hset(f"session.data:{str(ctx.author.id)}", "addon", "")
            elif juvenile:
                addon = "juvenile"
                if len(database.hget(f"session.data:{str(ctx.author.id)}", "addon")) is 0:
                    logger.info("adding juvenile")
                    database.hset(f"session.data:{str(ctx.author.id)}", "addon", addon)
                else:
                    logger.info("removing juvenile")
                    database.hset(f"session.data:{str(ctx.author.id)}", "addon", "")
            await self._send_stats(ctx, f"**Session started previously.**\n")
        else:
            await ctx.send("**There is no session running.** *You can start one with `b!session start`*")