示例#1
0
    async def accept(self, ctx: commands.Context, target: discord.Member):
        """Accept a staff applicant.

        <target> can be a mention or an ID."""
        bot = self.bot
        guild = ctx.guild
        applicant = get(guild.roles, name="Staff Applicant")
        role = MessagePredicate.valid_role(ctx)
        if applicant in target.roles:
            await ctx.send("What role do you want to accept {0} as?".format(
                target.name))
            try:
                await bot.wait_for("message", timeout=30, check=role)
            except asyncio.TimeoutError:
                return await ctx.send("You took too long. Try again, please.")
            role_add = role.result
            await target.add_roles(role_add)
            await target.remove_roles(applicant)
            await ctx.send("Accepted {0} as {1}.".format(
                target.mention, role_add))
            await target.send("You have been accepted as {0} in {1}.".format(
                role_add, guild.name))
        else:
            await ctx.send(
                "Uh oh. Looks like {0} hasn't applied for anything.".format(
                    target.mention))
示例#2
0
    async def locksetup(self, ctx: commands.Context):
        """ Go through the initial setup process. """
        bot = self.bot
        await ctx.send("Do you use roles to access channels? (yes/no)")
        pred = MessagePredicate.yes_or_no(ctx)
        try:
            await bot.wait_for("message", timeout=30, check=pred)
        except asyncio.TimeoutError:
            await ctx.send("You took too long. Try again, please.")
            return
        if pred.result is False:
            await self.config.guild(ctx.guild).everyone.set(True)
        else:
            await self.config.guild(ctx.guild).everyone.set(False)

        await ctx.send("What is your Moderator role?")
        role = MessagePredicate.valid_role(ctx)
        try:
            await bot.wait_for("message", timeout=30, check=role)
        except asyncio.TimeoutError:
            await ctx.send("You took too long. Try again, please.")
            return
        mod_role = role.result
        await self.config.guild(ctx.guild).moderator.set(str(mod_role))

        await ctx.send("You have finished the setup!")
示例#3
0
    async def accept(self, ctx: commands.Context, target: discord.Member):
        """Accept a staff applicant.

        <target> can be a mention or an ID."""
        applicant = get(ctx.guild.roles, name="Staff Applicant")
        role = MessagePredicate.valid_role(ctx)
        if applicant in target.roles:
            await ctx.send(f"What role do you want to accept {target.name} as?")
            try:
                await self.bot.wait_for("message", timeout=30, check=role)
            except asyncio.TimeoutError:
                return await ctx.send("You took too long. Try again, please.")
            role_add = role.result
            try:
                await target.add_roles(role_add)
            except discord.Forbidden:
                return await ctx.send("Uh oh, I cannot give them the role. It might be above all of my roles.")
            await target.remove_roles(applicant)
            await ctx.send(f"Accepted {target.mention} as {role_add}.")
            await target.send(
                f"You have been accepted as {role_add} in {ctx.guild.name}."
            )
        else:
            await ctx.send(
                f"Uh oh. Looks like {target.mention} hasn't applied for anything."
            )
示例#4
0
    async def accept(self, ctx: commands.Context, target: discord.Member):
        """Accept a staff applicant.

        <target> can be a mention or an ID."""
        if not await self.config.guild(ctx.guild).channel_id():
            return await ctx.send(
                "Uh oh, the configuration is not correct. Ask the Admins to set it."
            )

        try:
            accepter = ctx.guild.get_role(
                await self.config.guild(ctx.guild).accepter_id()
            )
        except TypeError:
            accepter = None
        if (
            not accepter
            and not ctx.author.guild_permissions.administrator
            or (accepter and accepter not in ctx.author.roles)
        ):
            return await ctx.send("Uh oh, you cannot use this command.")

        applicant = None
        if await self.config.guild(ctx.guild).applicant_id():
            try:
                applicant = ctx.guild.get_role(
                    await self.config.guild(ctx.guild).applicant_id()
                )
            except TypeError:
                applicant = None
            if not applicant:
                applicant = get(ctx.guild.roles, name="Staff Applicant")
            if not applicant:
                return await ctx.send(
                    "Uh oh, the configuration is not correct. Ask the Admins to set it."
                )
            if applicant not in target.roles:
                return await ctx.send(
                    f"Uh oh. Looks like {target.mention} hasn't applied for anything."
                )

        await ctx.send(f"What role do you want to accept {target.name} as?")
        role = MessagePredicate.valid_role(ctx)
        try:
            await self.bot.wait_for("message", timeout=30, check=role)
        except asyncio.TimeoutError:
            return await ctx.send("You took too long. Try again, please.")
        role_add = role.result
        try:
            await target.add_roles(role_add)
        except discord.Forbidden:
            return await ctx.send(
                "Uh oh, I cannot give them the role. It might be above all of my roles."
            )
        if applicant:
            await target.remove_roles(applicant)
        await ctx.send(f"Accepted {target.mention} as {role_add}.")
        await target.send(f"You have been accepted as {role_add} in {ctx.guild.name}.")
示例#5
0
    async def role_requirement(self, membership):
        await self.ctx.send(_("What role does this membership require?\n"
                              "*Note this is skipped in global mode. If you set this as the only "
                              "requirement in global, it will be accessible to everyone!*"))
        pred = MessagePredicate.valid_role(ctx=self.ctx)
        role = await self.ctx.bot.wait_for("message", timeout=25.0, check=pred)

        if self.mode == "create":
            membership['Role'] = role.content
            return

        async with self.coro() as membership_data:
            membership_data[membership]['Role'] = role.content

        await self.ctx.send(_('Role requirement set to {}.').format(role.content))
示例#6
0
 async def _ask_for_role_add(self, ctx: commands.Context):
     await ctx.send("Do you use a role to access to the server? (y/n)")
     try:
         predicator = MessagePredicate.yes_or_no(ctx)
         await self.bot.wait_for("message", timeout=30, check=predicator)
     except asyncio.TimeoutError:
         await ctx.send("Question cancelled, caused by timeout.")
         return
     if predicator.result:
         await ctx.send(
             "Which role should I give when user pass captcha? (Role ID/Name/Mention)"
         )
         role = MessagePredicate.valid_role(ctx)
         try:
             await self.bot.wait_for("message", timeout=60, check=role)
         except asyncio.TimeoutError:
             await ctx.send("Question cancelled, caused by timeout.")
             return
         await self.data.guild(ctx.guild).autorole.set(role.result.id)
     return True
示例#7
0
class BirthdayAdminCommands(MixinMeta):
    @commands.group()
    @commands.guild_only()  # type:ignore
    @commands.admin_or_permissions(manage_guild=True)
    async def bdset(self, ctx: commands.Context):
        """
        Birthday management commands for admins.

        Looking to set your own birthday? Use `[p]birthday set` or `[p]bday set`.
        """

    @commands.bot_has_permissions(manage_roles=True)
    @bdset.command()
    async def interactive(self, ctx: commands.Context):
        """Start interactive setup"""
        # group has guild check
        if TYPE_CHECKING:
            assert ctx.guild is not None
            assert isinstance(ctx.me, discord.Member)

        m: discord.Message = await ctx.send(
            "Just a heads up, you'll be asked for a message for when the user provided their birth"
            " year, a message for when they didn't, the channel to sent notifications, the role,"
            " and the time of day to send them.\n\nWhen you're ready, press the tick."
        )
        start_adding_reactions(m, ReactionPredicate.YES_OR_NO_EMOJIS)
        pred = ReactionPredicate.yes_or_no(m, ctx.author)  # type:ignore
        try:
            await self.bot.wait_for("reaction_add", check=pred, timeout=300)
        except asyncio.TimeoutError:
            await m.edit(content=(
                f"Took too long to react, cancelling setup. Run `{ctx.clean_prefix}bdset"
                " interactive` to start again."))

        if pred.result is not True:
            await ctx.send("Okay, I'll cancel setup.")
            return

        # ============================== MSG WITH YEAR ==============================

        m = await ctx.send(
            "What message should I send if the user provided their birth year?\n\nYou can use the"
            " following variables: `mention`, `name`, `new_age`. Put curly brackets `{}` around"
            " them, for example: {mention} is now {new_age} years old!\n\nYou have 5 minutes."
        )

        try:
            pred = MessagePredicate.same_context(ctx)
            message = await self.bot.wait_for("message",
                                              check=pred,
                                              timeout=300)
        except asyncio.TimeoutError:
            await ctx.send(
                f"Took too long to react, cancelling setup. Run `{ctx.clean_prefix}bdset"
                " interactive` to start again.")
            return

        message_w_year = message.content

        if len(message_w_year) > MAX_BDAY_MSG_LEN:
            await ctx.send("That message is too long, please try again.")
            return

        # ============================== MSG WITHOUT YEAR ==============================

        m = await ctx.send(
            "What message should I send if the user didn't provide their birth year?\n\nYou can"
            " use the following variables: `mention`, `name`. Put curly brackets `{}` around them,"
            " for example: {mention}'s birthday is today! Happy birthday {name}\n\nYou have 5"
            " minutes.")

        try:
            pred = MessagePredicate.same_context(ctx)
            message = await self.bot.wait_for("message",
                                              check=pred,
                                              timeout=300)
        except asyncio.TimeoutError:
            await ctx.send(
                f"Took too long to react, cancelling setup. Run `{ctx.clean_prefix}bdset"
                " interactive` to start again.")
            return

        message_wo_year = message.content

        if len(message_wo_year) > MAX_BDAY_MSG_LEN:
            await ctx.send("That message is too long, please try again.")
            return

        # ============================== CHANNEL ==============================

        m = await ctx.send(
            "Where would you like to send notifications? I will ignore any message with an invalid"
            " channel.\n\nYou have 5 minutes.")

        try:
            pred = MessagePredicate.valid_text_channel(ctx)
            await self.bot.wait_for("message", check=pred, timeout=300)
        except asyncio.TimeoutError:
            await ctx.send(
                f"Took too long to react, cancelling setup. Run `{ctx.clean_prefix}bdset"
                " interactive` to start again.")

        channel: discord.TextChannel = pred.result
        if error := channel_perm_check(ctx.me, channel):
            await ctx.send(
                warning(
                    f"{error} Please make sure"
                    " you rectify this as soon as possible, but I'll let you continue the setup."
                ))

        channel_id = pred.result.id

        # ============================== ROLE ==============================

        m = await ctx.send(
            "What role should I assign to users who have their birthday today? I will ignore any"
            " message which isn't a role.\n\nYou can mention the role, give its exact name, or its"
            " ID.\n\nYou have 5 minutes.")

        try:
            pred = MessagePredicate.valid_role(ctx)
            await self.bot.wait_for("message", check=pred, timeout=300)
        except asyncio.TimeoutError:
            await ctx.send(
                f"Took too long to react, cancelling setup. Run `{ctx.clean_prefix}bdset"
                " interactive` to start again.")

        # no need to check hierarchy for author, since command is locked to admins
        if error := role_perm_check(ctx.me, pred.result):
            await ctx.send(
                warning(
                    f"{error} Please make"
                    " sure you rectify this as soon as possible, but I'll let you continue the"
                    " setup."))
示例#8
0
    async def setlock_setup(self, ctx: commands.Context):
        """ Go through the initial setup process. """
        await ctx.send("Do you use roles to access channels? (yes/no)")
        pred = MessagePredicate.yes_or_no(ctx)
        try:
            await self.bot.wait_for("message", timeout=30, check=pred)
        except asyncio.TimeoutError:
            return await ctx.send("You took too long. Try again, please.")
        if not pred.result:  # if no, everyone can see channels
            await self.config.guild(ctx.guild).everyone.set(True)
            await self.config.guild(ctx.guild).special.clear()
            await self.config.guild(ctx.guild).roles.clear()
            await self.config.guild(ctx.guild).defa.clear()
            await self.config.guild(ctx.guild).def_roles.clear()
            await self.config.guild(ctx.guild).channels.clear_raw()
        else:  # if yes, only some roles can see channels
            await self.config.guild(ctx.guild).everyone.set(False)
            await ctx.send(
                "Do you have different channels that different roles can access? (yes/no)"
            )
            try:
                await self.bot.wait_for("message", timeout=30, check=pred)
            except asyncio.TimeoutError:
                return await ctx.send("You took too long. Try again, please.")
            if not pred.result:  # if not, all special roles can see same channels
                await self.config.guild(ctx.guild).special.set(False)
                arole_list = []
                await ctx.send(
                    "You answered no but you answered yes to `Do you use roles to access channels?`\nWhat roles can access your channels? (Must be **comma separated**)"
                )

                def check(m):
                    return m.author == ctx.author and m.channel == ctx.channel

                try:
                    answer = await self.bot.wait_for("message",
                                                     timeout=120,
                                                     check=check)
                except asyncio.TimeoutError:
                    return await ctx.send(
                        "You took too long. Try again, please.")
                arole_list = await self._get_roles_from_content(
                    ctx, answer.content)
                if not arole_list:
                    return await ctx.send("Invalid answer, canceling.")
                await self.config.guild(ctx.guild).roles.set(arole_list)
            else:  # if yes, some roles can see some channels, some other roles can see some other channels
                await self.config.guild(ctx.guild).special.set(True)
                await self.config.guild(ctx.guild).roles.clear()
                await ctx.send(
                    f"**Use `{ctx.clean_prefix}setlock add` to add a channel.**"
                )
                await ctx.send(
                    "Would you like to add default value for when a channel isn't specified? (yes/no)"
                )
                try:
                    await self.bot.wait_for("message", timeout=30, check=pred)
                except asyncio.TimeoutError:
                    return await ctx.send(
                        "You took too long. Try again, please.")
                if not pred.result:  # if no, it will give an error
                    await ctx.send(
                        f"Okay, `{ctx.clean_prefix}lock` will give an error and will not lock a channel if the channel hasn't been added."
                    )
                    await self.config.guild(ctx.guild).defa.set(False)
                    await self.config.guild(ctx.guild).def_roles.clear()
                else:  # if yes, lock will do default perms
                    await self.config.guild(ctx.guild).defa.set(True)
                    drole_list = []
                    await ctx.send(
                        "What are the default roles that can access your channels? (Must be **comma separated**)"
                    )

                    def check(m):
                        return m.author == ctx.author and m.channel == ctx.channel

                    try:
                        answer = await self.bot.wait_for("message",
                                                         timeout=120,
                                                         check=check)
                    except asyncio.TimeoutError:
                        return await ctx.send(
                            "You took too long. Try again, please.")
                    drole_list = await self._get_roles_from_content(
                        ctx, answer.content)
                    if not drole_list:
                        return await ctx.send("Invalid answer, canceling.")
                    await self.config.guild(ctx.guild
                                            ).def_roles.set(drole_list)
        await ctx.send("What is your Moderator role?")
        role = MessagePredicate.valid_role(ctx)
        try:
            await self.bot.wait_for("message", timeout=30, check=role)
        except asyncio.TimeoutError:
            return await ctx.send("You took too long. Try again, please.")
        mod_role = role.result
        await self.config.guild(ctx.guild).moderator.set(mod_role.id)
        await self.config.guild(ctx.guild).has_been_set.set(True)

        await ctx.send("You have finished the setup!")
示例#9
0
    async def economysetup(self, ctx: commands.Context):
        """ Go through the initial setup process. """
        currency = await bank.get_currency_name(ctx.guild)
        pred = MessagePredicate.yes_or_no(ctx)
        await ctx.send(
            "Do you want the winner to have a specific role? (yes/no)")
        try:
            await self.bot.wait_for("message", timeout=30, check=pred)
        except asyncio.TimeoutError:
            return await ctx.send("You took too long. Try again, please.")
        if pred.result:
            await ctx.send("What role should it be?")
            role = MessagePredicate.valid_role(ctx)
            try:
                await self.bot.wait_for("message", timeout=30, check=role)
            except asyncio.TimeoutError:
                return await ctx.send("You took too long. Try again, please.")
            required = role.result
            await self.config.guild(ctx.guild).required.set(str(required))
        await ctx.send(
            f"What amount of {currency} do you want me to give away? (whole number)"
        )
        predi = MessagePredicate.valid_int(ctx)
        try:
            await self.bot.wait_for("message", timeout=30, check=predi)
        except asyncio.TimeoutError:
            return await ctx.send("You took too long. Try again, please.")
        amount = predi.result
        await self.config.guild(ctx.guild).amount.set(amount)

        await ctx.send(
            "I will send a few options of the raffle message. Please, choose number of the one you like the most."
            "```cs\nWrite '1' for this:```It's time for our {amount} giveaway!\nCongratulations {winner}! :tada: You just won {amount} {currency_name}!"
            "```cs\nWrite '2' for this:```Congratulations {winner}! :tada: You just won {amount} {currency_name}!"
            "```cs\nWrite '3' for this:```{winner} just won {amount} {currency_name}! :tada:"
            "```cs\nWrite '4' for a custom message.```")
        msg_list = ["1", "2", "3", "4"]
        predic = MessagePredicate.contained_in(msg_list, ctx)
        try:
            await self.bot.wait_for("message", timeout=30, check=predic)
        except asyncio.TimeoutError:
            return await ctx.send("You took too long. Try again, please.")
        msg = msg_list[predic.result]
        await self.config.guild(ctx.guild).msg.set(int(msg))
        if int(msg) == 4:
            await ctx.send(
                "What's your message? Available parametres are: `{winner}`, `{amount}`, `{currency}`, `{server}`"
            )

            def check(m):
                return m.author == ctx.author and m.channel == ctx.channel

            try:
                answer = await self.bot.wait_for("message",
                                                 timeout=120,
                                                 check=check)
            except asyncio.TimeoutError:
                return await ctx.send("You took too long. Try again, please.")
            custom = answer.content
            await self.config.guild(ctx.guild).custom.set(custom)
        await ctx.send(
            f"You have finished the setup! Command `{ctx.clean_prefix}economyraffle` is ready to be used. *Please note that scheduler isn't part of this cog.*"
        )
示例#10
0
    async def applysetup(self, ctx: commands.Context):
        """Go through the initial setup process."""
        pred = MessagePredicate.yes_or_no(ctx)
        role = MessagePredicate.valid_role(ctx)

        applicant = get(ctx.guild.roles, name="Staff Applicant")
        channel = get(ctx.guild.text_channels, name="staff-applications")

        await ctx.send(
            "This will create required channel and role. Do you wish to continue? (yes/no)"
        )
        try:
            await self.bot.wait_for("message", timeout=30, check=pred)
        except asyncio.TimeoutError:
            return await ctx.send("You took too long. Try again, please.")
        if not pred.result:
            return await ctx.send("Setup cancelled.")
        if not applicant:
            try:
                applicant = await ctx.guild.create_role(
                    name="Staff Applicant", reason="Application cog setup"
                )
            except discord.Forbidden:
                return await ctx.send(
                    "Uh oh. Looks like I don't have permissions to manage roles."
                )
        if not channel:
            await ctx.send("Do you want everyone to see the applications channel? (yes/no)")
            try:
                await self.bot.wait_for("message", timeout=30, check=pred)
            except asyncio.TimeoutError:
                return await ctx.send("You took too long. Try again, please.")
            if pred.result:
                overwrites = {
                    ctx.guild.default_role: discord.PermissionOverwrite(send_messages=False),
                    ctx.guild.me: discord.PermissionOverwrite(send_messages=True),
                }
            else:
                overwrites = {
                    ctx.guild.default_role: discord.PermissionOverwrite(read_messages=False),
                    ctx.guild.me: discord.PermissionOverwrite(read_messages=True),
                }
            try:
                channel = await ctx.guild.create_text_channel(
                    "staff-applications",
                    overwrites=overwrites,
                    reason="Application cog setup",
                )
            except discord.Forbidden:
                return await ctx.send(
                    "Uh oh. Looks like I don't have permissions to manage channels."
                )
        await ctx.send(f"What role can accept or reject applicants?")
        try:
            await self.bot.wait_for("message", timeout=30, check=role)
        except asyncio.TimeoutError:
            return await ctx.send("You took too long. Try again, please.")
        accepter = role.result
        await self.config.guild(ctx.guild).applicant_id.set(applicant.id)
        await self.config.guild(ctx.guild).channel_id.set(channel.id)
        await self.config.guild(ctx.guild).accepter_id.set(accepter.id)
        await ctx.send(
            "You have finished the setup! Please, move your new channel to the category you want it in."
        )
示例#11
0
    async def create(
        self,
        ctx: commands.Context,
        source_voice_channel: discord.VoiceChannel,
        dest_category: discord.CategoryChannel,
    ):
        """Create an AutoRoom Source.

        Anyone joining an AutoRoom Source will automatically have a new
        voice channel (AutoRoom) created in the destination category,
        and then be moved into it.
        """
        if not await self.check_required_perms(ctx.guild):
            await ctx.send(
                error(
                    "I am missing a permission that the AutoRoom cog requires me to have. "
                    "Check `[p]autoroomset permissions` for more details. "
                    "Try creating the AutoRoom Source again once I have these permissions."
                )
            )
            return
        new_source = {"dest_category_id": dest_category.id}

        # Public or private
        options = ["public", "private"]
        pred = MessagePredicate.lower_contained_in(options, ctx)
        await ctx.send(
            "**Welcome to the setup wizard for creating an AutoRoom Source!**"
            "\n"
            f"Users joining the {source_voice_channel.mention} AutoRoom Source will have an AutoRoom "
            f"created in the {dest_category.mention} category and be moved into it."
            "\n\n"
            "**Public/Private**"
            "\n"
            "AutoRooms can either be public or private. Public AutoRooms are visible to other users, "
            "where the AutoRoom Owner can kick/ban users out of them. Private AutoRooms are only visible to the "
            "AutoRoom Owner, where they can allow users into their room."
            "\n\n"
            "Would you like these created AutoRooms to be public or private to other users by default? (`public`/`private`)"
        )
        try:
            await ctx.bot.wait_for("message", check=pred, timeout=60)
        except asyncio.TimeoutError:
            await ctx.send("No valid answer was received, canceling setup process.")
            return
        new_source["room_type"] = options[pred.result]

        # Text channel
        pred = MessagePredicate.yes_or_no(ctx)
        await ctx.send(
            "**Text Channel**"
            "\n"
            "AutoRooms can optionally have a text channel created with them, where only the AutoRoom members can"
            "see and message in it. This is useful to keep AutoRoom specific chat out of your other channels."
            "\n\n"
            "Would you like these created AutoRooms to also have a created text channel? (`yes`/`no`)"
        )
        try:
            await ctx.bot.wait_for("message", check=pred, timeout=60)
        except asyncio.TimeoutError:
            await ctx.send("No valid answer was received, canceling setup process.")
            return
        new_source["text_channel"] = pred.result

        # Channel name
        options = ["username", "game"]
        pred = MessagePredicate.lower_contained_in(options, ctx)
        await ctx.send(
            "**Channel Name**"
            "\n"
            "When an AutoRoom is created, a name will be generated for it. How would you like that name to be generated?"
            "\n\n"
            f'`username` - Shows up as "{ctx.author.display_name}\'s Room"\n'
            "`game    ` - AutoRoom Owner's playing game, otherwise `username`"
        )
        try:
            await ctx.bot.wait_for("message", check=pred, timeout=60)
        except asyncio.TimeoutError:
            await ctx.send("No valid answer was received, canceling setup process.")
            return
        new_source["channel_name_type"] = options[pred.result]

        # Member role ask
        pred = MessagePredicate.yes_or_no(ctx)
        await ctx.send(
            "**Member Role**"
            "\n"
            "By default, Public AutoRooms are visible to the whole server. Some servers have member roles for limiting "
            "what unverified members can see and do."
            "\n\n"
            "Would you like these created AutoRooms to only be visible to a certain member role? (`yes`/`no`)"
        )
        try:
            await ctx.bot.wait_for("message", check=pred, timeout=60)
        except asyncio.TimeoutError:
            await ctx.send("No valid answer was received, canceling setup process.")
            return
        if pred.result:
            # Member role get
            pred = MessagePredicate.valid_role(ctx)
            await ctx.send(
                "What role is your member role? Only provide one; if you have multiple, you can add more after the "
                "setup process."
            )
            try:
                await ctx.bot.wait_for("message", check=pred, timeout=60)
            except asyncio.TimeoutError:
                pass
            if pred.result:
                new_source["member_roles"] = [pred.result.id]
            else:
                await ctx.send("No valid answer was received, canceling setup process.")
                return

        # Save new source
        await self.config.custom(
            "AUTOROOM_SOURCE", ctx.guild.id, source_voice_channel.id
        ).set(new_source)
        await ctx.send(
            checkmark(
                "Settings saved successfully!\n"
                "Check out `[p]autoroomset modify` for even more AutoRoom Source settings, "
                "or to make modifications to your above answers."
            )
        )
示例#12
0
    async def shop_add(self, ctx: commands.Context):
        """Add an item to the Marshmallow shop"""

        def check(m):
            return m.author == ctx.author and m.channel == ctx.channel

        types = ["item", "role", "certificate"]
        pred = MessagePredicate.lower_contained_in(types)
        pred_int = MessagePredicate.valid_int(ctx)
        pred_role = MessagePredicate.valid_role(ctx)
        pred_yn = MessagePredicate.yes_or_no(ctx)

        await ctx.send(
            "Do you want to add an item, role or certificate?\nCertificates can be gift card codes, game keys, etc."
        )
        try:
            await self.bot.wait_for("message", timeout=30, check=pred)
        except asyncio.TimeoutError:
            return await ctx.send("You took too long. Try again.")
        if pred.result == 0:
            await ctx.send(
                "What is item's name? Don't include `@` in the name."
            )
            try:
                answer = await self.bot.wait_for("message", timeout=120, check=check)
            except asyncio.TimeoutError:
                return await ctx.send("You took too long. Try again.")
            item_name = answer.content
            item_name = item_name.strip("@")
            try:
                is_already_item = await self.config.guild(ctx.guild).items.get_raw(
                    item_name
                )
                if is_already_item:
                    return await ctx.send(
                        "This item already exists."
                    )
            except KeyError:
                ### START ADD CODE ###
                await ctx.send("Describe the item.")
                try:
                    await self.bot.wait_for("message", timeout=120, check=pred_int)
                except asyncio.TimeoutError:
                    return await ctx.send("You took too long. Try again.")
                item_details = answer.content
                if item_details == "":
                    return await ctx.send("Please enter a description.")
                ### END ADD CODE ###
                await ctx.send("How many marshmallows should this cost?")
                try:
                    await self.bot.wait_for("message", timeout=120, check=pred_int)
                except asyncio.TimeoutError:
                    return await ctx.send("You took too long. Try again.")
                price = pred_int.result
                if price <= 0:
                    return await ctx.send("price has to be at least 1.")
                await ctx.send("How many are available?")
                try:
                    await self.bot.wait_for("message", timeout=120, check=pred_int)
                except asyncio.TimeoutError:
                    return await ctx.send("You took too long. Try again.")
                stock = pred_int.result
                if stock <= 0:
                    return await ctx.send("Amount in stock has to be at least 1.")
                await ctx.send("Is this redeemable?")
                try:
                    await self.bot.wait_for("message", timeout=120, check=pred_yn)
                except asyncio.TimeoutError:
                    return await ctx.send("You took too long. Try again.")
                redeemable = pred_yn.result
                ### START ADD CODE ###
                if not redeemable:
                    return await ctx.send("Please respond y or n.")
                await ctx.send("Is this returnable?")
                try:
                    await self.bot.wait_for("message", timeout=120, check=pred_yn)
                except asyncio.TimeoutError:
                    return await ctx.send("You took too long. Try again.")
                returnable = pred_yn.result
                ### END ADD CODE ###
                await self.config.guild(ctx.guild).items.set_raw(
                    item_name,
                    value={
                        ### START ADD CODE ###
                        "description": item_details,
                        ### END ADD CODE ###
                        "price": price,
                        "stock": stock,
                        "redeemable": redeemable,
                        ### START ADD CODE ###
                        "returnable": returnable,
                        ### END ADD CODE ###
                    },
                )
                await ctx.send(f"{item_name} added.")
        elif pred.result == 1:
            await ctx.send("What is the role?")
            try:
                await self.bot.wait_for("message", timeout=30, check=pred_role)
            except asyncio.TimeoutError:
                return await ctx.send("You took too long. Try again.")
            role = pred_role.result
            try:
                is_already_role = await self.config.guild(ctx.guild).roles.get_raw(
                    role.name
                )
                if is_already_role:
                    return await ctx.send(
                        "This item already exists."
                    )
            except KeyError:
                ### START ADD CODE ###
                await ctx.send("Describe the role.")
                try:
                    await self.bot.wait_for("message", timeout=120, check=pred_int)
                except asyncio.TimeoutError:
                    return await ctx.send("You took too long. Try again.")
                item_details = answer.content
                if item_details == "":
                    return await ctx.send("Please enter a description.")
                ### END ADD CODE ###
                await ctx.send("How many marshmallows should this cost?")
                try:
                    await self.bot.wait_for("message", timeout=120, check=pred_int)
                except asyncio.TimeoutError:
                    return await ctx.send("You took too long. Try again.")
                price = pred_int.result
                if price <= 0:
                    return await ctx.send("price has to be at least 1.")
                await ctx.send("How many are available?")
                try:
                    await self.bot.wait_for("message", timeout=120, check=pred_int)
                except asyncio.TimeoutError:
                    return await ctx.send("You took too long. Try again.")
                stock = pred_int.result
                if stock <= 0:
                    return await ctx.send("Amount in stock has to be at least 1.")
                await self.config.guild(ctx.guild).roles.set_raw(
                    role.name, value={"description": item_details, "price": price, "stock": stock}
                )
                await ctx.send(f"{role.name} added.")
        elif pred.result == 2:
            await ctx.send(
                "What is the certificate's name? Don't include `@` in the name."
            )
            try:
                answer = await self.bot.wait_for("message", timeout=120, check=check)
            except asyncio.TimeoutError:
                return await ctx.send("You took too long. Try again.")
            certificate_name = answer.content
            certificate_name = certificate_name.strip("@")
            try:
                is_already_certificate = await self.config.guild(ctx.guild).certificates.get_raw(
                    certificate_name
                )
                if is_already_certificate:
                    return await ctx.send(
                        "This certificate already exists."
                    )
            except KeyError:
                ### START ADD CODE ###
                await ctx.send("Describe the certificate.")
                try:
                    await self.bot.wait_for("message", timeout=120, check=pred_int)
                except asyncio.TimeoutError:
                    return await ctx.send("You took too long. Try again.")
                item_details = answer.content
                if item_details == "":
                    return await ctx.send("Please enter a description.")
                ### END ADD CODE ###
                await ctx.send("How many marshmallows should this cost?")
                try:
                    await self.bot.wait_for("message", timeout=120, check=pred_int)
                except asyncio.TimeoutError:
                    return await ctx.send("You took too long. Try again.")
                price = pred_int.result
                if price <= 0:
                    return await ctx.send("price has to be at least 1.")
                await ctx.send("How many are available?")
                try:
                    await self.bot.wait_for("message", timeout=120, check=pred_int)
                except asyncio.TimeoutError:
                    return await ctx.send("You took too long. Try again.")
                stock = pred_int.result
                if stock <= 0:
                    return await ctx.send("Amount in stock has to be at least 1.")
                await ctx.send("Is the item redeemable?")
                try:
                    await self.bot.wait_for("message", timeout=120, check=pred_yn)
                except asyncio.TimeoutError:
                    return await ctx.send("You took too long. Try again.")
                redeemable = pred_yn.result
                ### START ADD CODE ###
                if not redeemable:
                    return await ctx.send("Please respond y or n.")
                await ctx.send("Is this returnable?")
                try:
                    await self.bot.wait_for("message", timeout=120, check=pred_yn)
                except asyncio.TimeoutError:
                    return await ctx.send("You took too long. Try again.")
                returnable = pred_yn.result
                ### END ADD CODE ###
                await self.config.guild(ctx.guild).certificates.set_raw(
                    certificate_name,
                    value={
                        ### START ADD CODE ###
                        "description": item_details,
                        ### END ADD CODE ###
                        "price": price,
                        "stock": stock,
                        "redeemable": redeemable,
                        ### START ADD CODE ###
                        "returnable": returnable,
                        ### END ADD CODE ###
                    },
                )
                await ctx.send(f"{certificate_name} added.")
        else:
            await ctx.send("Huh?")
示例#13
0
    async def store_add(self, ctx: commands.Context):
        """Add a buyable item/role/game key."""
        bot = self.bot

        def check(m):
            return m.author == ctx.author and m.channel == ctx.channel

        types = ["item", "role", "game"]
        pred = MessagePredicate.lower_contained_in(types)
        pred_int = MessagePredicate.valid_int(ctx)
        pred_role = MessagePredicate.valid_role(ctx)
        pred_yn = MessagePredicate.yes_or_no(ctx)

        await ctx.send(
            "Do you want to add an item, role or game?\nItem and role = returnable, game = non returnable."
        )
        try:
            await bot.wait_for("message", timeout=30, check=pred)
        except asyncio.TimeoutError:
            return await ctx.send("You took too long. Try again, please.")
        if pred.result == 0:
            await ctx.send(
                "What is the name of the item? Note that you cannot include `@` in the name."
            )
            try:
                answer = await bot.wait_for("message",
                                            timeout=120,
                                            check=check)
            except asyncio.TimeoutError:
                return await ctx.send("You took too long. Try again, please.")
            item_name = answer.content
            item_name = item_name.strip("@")
            try:
                is_already_item = await self.config.guild(
                    ctx.guild).items.get_raw(item_name)
                if is_already_item:
                    return await ctx.send(
                        "This item is already set. Please, remove it first.")
            except KeyError:
                await ctx.send("How many cookies should this item be?")
                try:
                    await bot.wait_for("message", timeout=120, check=pred_int)
                except asyncio.TimeoutError:
                    return await ctx.send(
                        "You took too long. Try again, please.")
                price = pred_int.result
                if price <= 0:
                    return await ctx.send("Uh oh, price has to be more than 0."
                                          )
                await ctx.send(
                    "What quantity of this item should be available?")
                try:
                    await bot.wait_for("message", timeout=120, check=pred_int)
                except asyncio.TimeoutError:
                    return await ctx.send(
                        "You took too long. Try again, please.")
                quantity = pred_int.result
                if quantity <= 0:
                    return await ctx.send(
                        "Uh oh, quantity has to be more than 0.")
                await ctx.send("Is the item redeemable?")
                try:
                    await bot.wait_for("message", timeout=120, check=pred_yn)
                except asyncio.TimeoutError:
                    return await ctx.send(
                        "You took too long. Try again, please.")
                redeemable = pred_yn.result
                await self.config.guild(ctx.guild).items.set_raw(
                    item_name,
                    value={
                        "price": price,
                        "quantity": quantity,
                        "redeemable": redeemable,
                    },
                )
                await ctx.send("{0} added.".format(item_name))
        elif pred.result == 1:
            await ctx.send("What is the role?")
            try:
                await bot.wait_for("message", timeout=30, check=pred_role)
            except asyncio.TimeoutError:
                return await ctx.send("You took too long. Try again, please.")
            role = pred_role.result
            try:
                is_already_role = await self.config.guild(
                    ctx.guild).roles.get_raw(role.name)
                if is_already_role:
                    return await ctx.send(
                        "This item is already set. Please, remove it first.")
            except KeyError:
                await ctx.send("How many cookies should this role be?")
                try:
                    await bot.wait_for("message", timeout=120, check=pred_int)
                except asyncio.TimeoutError:
                    return await ctx.send(
                        "You took too long. Try again, please.")
                price = pred_int.result
                if price <= 0:
                    return await ctx.send("Uh oh, price has to be more than 0."
                                          )
                await ctx.send(
                    "What quantity of this item should be available?")
                try:
                    await bot.wait_for("message", timeout=120, check=pred_int)
                except asyncio.TimeoutError:
                    return await ctx.send(
                        "You took too long. Try again, please.")
                quantity = pred_int.result
                if quantity <= 0:
                    return await ctx.send(
                        "Uh oh, quantity has to be more than 0.")
                await self.config.guild(ctx.guild
                                        ).roles.set_raw(role.name,
                                                        value={
                                                            "price": price,
                                                            "quantity":
                                                            quantity
                                                        })
                await ctx.send("{0} added.".format(role.name))
        elif pred.result == 2:
            await ctx.send(
                "What is the name of the game? Note that you cannot include `@` in the name."
            )
            try:
                answer = await bot.wait_for("message",
                                            timeout=120,
                                            check=check)
            except asyncio.TimeoutError:
                return await ctx.send("You took too long. Try again, please.")
            game_name = answer.content
            game_name = game_name.strip("@")
            try:
                is_already_game = await self.config.guild(
                    ctx.guild).games.get_raw(game_name)
                if is_already_game:
                    return await ctx.send(
                        "This item is already set. Please, remove it first.")
            except KeyError:
                await ctx.send("How many cookies should this game be?")
                try:
                    await bot.wait_for("message", timeout=120, check=pred_int)
                except asyncio.TimeoutError:
                    return await ctx.send(
                        "You took too long. Try again, please.")
                price = pred_int.result
                if price <= 0:
                    return await ctx.send("Uh oh, price has to be more than 0."
                                          )
                await ctx.send(
                    "What quantity of this item should be available?")
                try:
                    await bot.wait_for("message", timeout=120, check=pred_int)
                except asyncio.TimeoutError:
                    return await ctx.send(
                        "You took too long. Try again, please.")
                quantity = pred_int.result
                if quantity <= 0:
                    return await ctx.send(
                        "Uh oh, quantity has to be more than 0.")
                await ctx.send("Is the item redeemable?")
                try:
                    await bot.wait_for("message", timeout=120, check=pred_yn)
                except asyncio.TimeoutError:
                    return await ctx.send(
                        "You took too long. Try again, please.")
                redeemable = pred_yn.result
                await self.config.guild(ctx.guild).games.set_raw(
                    game_name,
                    value={
                        "price": price,
                        "quantity": quantity,
                        "redeemable": redeemable,
                    },
                )
                await ctx.send("{0} added.".format(game_name))
        else:
            await ctx.send("This answer is not supported. Try again, please.")
示例#14
0
    async def create(
        self,
        ctx: commands.Context,
        source_voice_channel: discord.VoiceChannel,
        dest_category: discord.CategoryChannel,
    ):
        """Create an AutoRoom Source.

        Anyone joining an AutoRoom Source will automatically have a new
        voice channel (AutoRoom) created in the destination category,
        and then be moved into it.
        """
        good_permissions, details = self.check_perms_source_dest(
            source_voice_channel, dest_category, detailed=True)
        if not good_permissions:
            await ctx.send(
                error(
                    "I am missing a permission that the AutoRoom cog requires me to have. "
                    "Check below for the permissions I require in both the AutoRoom Source "
                    "and the destination category. "
                    "Try creating the AutoRoom Source again once I have these permissions."
                    "\n"
                    f"{details}"
                    "\n"
                    "The easiest way of doing this is just giving me these permissions as part of my server role, "
                    "otherwise you will need to give me these permissions on the source channel and destination "
                    "category, as specified above."))
            return
        new_source = {"dest_category_id": dest_category.id}

        # Room type
        options = ["public", "private", "server"]
        pred = MessagePredicate.lower_contained_in(options, ctx)
        await ctx.send(
            "**Welcome to the setup wizard for creating an AutoRoom Source!**"
            "\n"
            f"Users joining the {source_voice_channel.mention} AutoRoom Source will have an AutoRoom "
            f"created in the {dest_category.mention} category and be moved into it."
            "\n\n"
            "**AutoRoom Type**"
            "\n"
            "AutoRooms can be one of the following types when created:"
            "\n"
            "`public ` - Visible to other users, and the AutoRoom Owner can kick/ban users out of them."
            "\n"
            "`private` - Only visible to the AutoRoom Owner, who can allow users into their room."
            "\n"
            "`server ` - Same as a public AutoRoom, but with no AutoRoom Owner. "
            "No modifications can be made to the generated AutoRoom."
            "\n\n"
            "What would you like these created AutoRooms to be by default? (`public`/`private`/`server`)"
        )
        try:
            await ctx.bot.wait_for("message", check=pred, timeout=60)
        except asyncio.TimeoutError:
            await ctx.send(
                "No valid answer was received, canceling setup process.")
            return
        new_source["room_type"] = options[pred.result]

        # Check perms room type
        good_permissions, details = self.check_perms_source_dest(
            source_voice_channel,
            dest_category,
            with_manage_roles_guild=new_source["room_type"] != "server",
            detailed=True,
        )
        if not good_permissions:
            await ctx.send(
                error(
                    f"Since you want to have this AutoRoom Source create {new_source['room_type']} AutoRooms, "
                    "I will need a few extra permissions. "
                    "Try creating the AutoRoom Source again once I have these permissions."
                    "\n"
                    f"{details}"))
            return

        # Text channel
        pred = MessagePredicate.yes_or_no(ctx)
        await ctx.send(
            "**Text Channel**"
            "\n"
            "AutoRooms can optionally have a text channel created with them, where only the AutoRoom members can"
            "see and message in it. This is useful to keep AutoRoom specific chat out of your other channels."
            "\n\n"
            "Would you like these created AutoRooms to also have a created text channel? (`yes`/`no`)"
        )
        try:
            await ctx.bot.wait_for("message", check=pred, timeout=60)
        except asyncio.TimeoutError:
            await ctx.send(
                "No valid answer was received, canceling setup process.")
            return
        new_source["text_channel"] = pred.result

        # Check perms text channel
        good_permissions, details = self.check_perms_source_dest(
            source_voice_channel,
            dest_category,
            with_manage_roles_guild=new_source["room_type"] != "server",
            with_text_channel=new_source["text_channel"],
            detailed=True,
        )
        if not good_permissions:
            await ctx.send(
                warning(
                    f"Since you want to have this AutoRoom Source also create text channels, "
                    "I will need a few extra permissions. "
                    "Until I have these permissions, text channels will not be created."
                    "\n"
                    f"{details}"))

        # Channel name
        options = ["username", "game"]
        pred = MessagePredicate.lower_contained_in(options, ctx)
        await ctx.send(
            "**Channel Name**"
            "\n"
            "When an AutoRoom is created, a name will be generated for it. How would you like that name to be generated?"
            "\n\n"
            f'`username` - Shows up as "{ctx.author.display_name}\'s Room"\n'
            "`game    ` - AutoRoom Owner's playing game, otherwise `username`")
        try:
            await ctx.bot.wait_for("message", check=pred, timeout=60)
        except asyncio.TimeoutError:
            await ctx.send(
                "No valid answer was received, canceling setup process.")
            return
        new_source["channel_name_type"] = options[pred.result]

        # Member role ask
        pred = MessagePredicate.yes_or_no(ctx)
        await ctx.send(
            "**Member Role**"
            "\n"
            "By default, Public AutoRooms are visible to the whole server. Some servers have member roles for limiting "
            "what unverified members can see and do."
            "\n\n"
            "Would you like these created AutoRooms to only be visible to a certain member role? (`yes`/`no`)"
        )
        try:
            await ctx.bot.wait_for("message", check=pred, timeout=60)
        except asyncio.TimeoutError:
            await ctx.send(
                "No valid answer was received, canceling setup process.")
            return
        if pred.result:
            # Member role get
            pred = MessagePredicate.valid_role(ctx)
            await ctx.send(
                "What role is your member role? Only provide one; if you have multiple, you can add more after the "
                "setup process.")
            try:
                await ctx.bot.wait_for("message", check=pred, timeout=60)
            except asyncio.TimeoutError:
                pass
            if pred.result:
                new_source["member_roles"] = [pred.result.id]
            else:
                await ctx.send(
                    "No valid answer was received, canceling setup process.")
                return

        # Save new source
        await self.config.custom("AUTOROOM_SOURCE", ctx.guild.id,
                                 source_voice_channel.id).set(new_source)
        await ctx.send(
            checkmark(
                "Settings saved successfully!\n"
                "Check out `[p]autoroomset modify` for even more AutoRoom Source settings, "
                "or to make modifications to your above answers."))