예제 #1
0
    async def invite(self, ctx):
        # This tells the user that the command they are trying to use isn't translated yet.
        user_language = {
            "lang":
            self.bot.user_data["UserData"][str(
                ctx.author.id)]["Settings"]["Language"]
        }
        if ctx.command.qualified_name not in localization[
                user_language["lang"]]:

            class Continue(ui.View):
                def __init__(self):
                    super().__init__(timeout=15)
                    self.value = None

                @ui.button(label=localization[user_language["lang"]]
                           ["language_not_available"]["button"],
                           style=ButtonStyle.primary,
                           emoji="▶️",
                           custom_id="continue")
                async def continue_button(self, button, interaction):
                    if interaction.user.id == ctx.author.id:
                        user_language["lang"] = "eng"
                        await self.message.delete()
                        self.value = True
                        self.stop()

                async def on_timeout():
                    await self.message.delete()
                    self.stop()

            emb = Embed(description=localization[user_language["lang"]]
                        ["language_not_available"]["description"]).set_footer(
                            text=localization[user_language["lang"]]
                            ["language_not_available"]["footer"])
            view = Continue()
            view.message = await ctx.send(embed=emb, view=view)
            await view.wait()
            if not view.value:
                return
        user_language = user_language["lang"]

        app_info: AppInfo = await self.bot.application_info()
        permissions = Permissions()
        permissions.update(send_messages=True,
                           embed_links=True,
                           add_reactions=True,
                           manage_messages=True,
                           manage_roles=True,
                           manage_channels=True,
                           use_application_commands=True)

        emb = Embed(
            title=localization[user_language]["invite"]["title"],
            description=localization[user_language]["invite"]["description"].
            format(url=oauth_url(app_info.id, permissions=permissions)),
        ).set_author(name=self.bot.user.name,
                     icon_url=self.bot.user.avatar.url).set_footer(
                         text=localization[user_language]["invite"]["footer"])
        await ctx.send(embed=emb)
예제 #2
0
 async def set_my_permissions(guild: discord.Guild,
                              channel: discord.TextChannel,
                              my_perms: discord.Permissions):
     if not my_perms.send_messages:
         my_perms.update(send_messages=True)
         await channel.set_permissions(guild.me,
                                       overwrite=my_perms,
                                       reason=LOCK_REASON)
예제 #3
0
    async def links(self, ctx):
        permission_names = ("read_messages", "send_messages",
                            "manage_messages", "embed_links", "attach_files",
                            "read_message_history", "add_reactions",
                            "use_external_emojis"
                            "mute_members", "deafen_members", "move_members")
        perms = Permissions()
        perms.update(**dict.fromkeys(permission_names, True))
        embed = Embed(
            description=
            f"""[**Bot Invite Link**]({oauth_url(self.bot.user.id, perms)})
[**Home Server**](https://discord.gg/dWX6fpGUK9)
[**Github Repo**](https://github.com/Sirspam/Coordy-McCoordFace)\n
I hope you're having a good day :)""",
            color=0x00A9E0)
        embed.set_thumbnail(
            url="https://cdn.discordapp.com/emojis/787809230639202354.png?v=1")
        await ctx.reply(embed=embed)
예제 #4
0
파일: help.py 프로젝트: LePokePug/MWSRam
    async def invite(self, ctx: Context):
        """Sends an OAuth bot invite URL"""

        app_info: AppInfo = await self.bot.application_info()
        permissions = Permissions()
        permissions.update(send_messages=True,
                           manage_messages=True,
                           manage_webhooks=True,
                           add_reactions=True,
                           attach_files=True,
                           embed_links=True)

        em = Embed(title=f'OAuth URL for {self.bot.user.name}',
                   description=f'[Click Here]'
                   f'({oauth_url(app_info.id, permissions)}) '
                   f'to invite me to your server.',
                   color=0xff87a3)
        await ctx.send(embed=em)
예제 #5
0
    async def disable(self, ctx: Context):
        """
        Disable automatic newbie roling for this server.
        New members will instantly have write access, unless verification prevents that.
        """

        db_guild = ctx.session.query(NewbieGuild).get(ctx.guild.id)
        if not db_guild:
            await ctx.send(
                'Automatic newbie roling is not enabled for this server.')
            return

        role = ctx.guild.get_role(db_guild.role_id)
        if not role:
            await ctx.send('Role has already been deleted.')
            return

        everyone_role = ctx.guild.default_role
        everyone_perms = everyone_role.permissions
        member_perms = role.permissions

        # Copy old everyone perms and additionally grant perms on member role
        merged_perms = Permissions(everyone_perms.value)
        merged_perms.update(**{perm: val for perm, val in member_perms if val})

        await everyone_role.edit(permissions=merged_perms)
        await role.delete()

        for db_channel in ctx.session.query(NewbieChannel).filter_by(
                guild_id=ctx.guild.id):
            channel = ctx.guild.get_channel(db_channel.channel_id)
            if not channel:
                continue

            everyone_overwrite = channel.overwrites_for(everyone_role)
            everyone_overwrite.update(read_messages=None,
                                      read_message_history=None)
            await channel.set_permissions(everyone_role,
                                          overwrite=everyone_overwrite)

        ctx.session.delete(db_guild)

        logger.info(f'Disabled newbie roling on guild {ctx.guild}.')
        await ctx.send('Disabled newbie roling for this server.')
예제 #6
0
    async def links(self, ctx):
        permission_names = (
            "send_messages",
            "embed_links",
            "attach_files",
            "add_reactions",
            "use_external_emojis"
        )
        perms = Permissions()
        perms.update(**dict.fromkeys(permission_names, True))
        embed = Embed(
            description=
f"""[**Bot Invite Link**]({oauth_url(self.bot.user.id, perms)})
[**Home Server**](https://discord.gg/dWX6fpGUK9)
[**Github Repo**]({self.bot.github_repo})\n
I hope you're having a good day :)""",
            color=0x00A9E0)
        embed.set_thumbnail(url="https://cdn.discordapp.com/emojis/822087750798016552.gif?v=1")
        await ctx.reply(embed=embed)
예제 #7
0
    async def invite(self, ctx: Context):
        """Sends an OAuth bot invite URL"""

        app_info: AppInfo = await self.bot.application_info()
        permissions = Permissions()
        permissions.update(send_messages=True,
                           embed_links=True,
                           manage_messages=True,
                           manage_webhooks=True,
                           add_reactions=True)

        emb = Embed(
            description=f'[Click Here]({oauth_url(app_info.id, permissions)}) '
            f'to invite this bot to your server.\n').set_author(
                name=f"Invite {self.bot.user.name}",
                icon_url=self.bot.user.avatar_url).set_footer(
                    text="Provided by MechHub Bot Factory")

        await ctx.send(embed=emb)
    async def links(self, ctx):
        permission_names = (
            "send_messages",
            "embed_links",
            "attach_files",
            "add_reactions",
            "use_external_emojis"
        )
        perms = Permissions()
        perms.update(**dict.fromkeys(permission_names, True))
        embed = Embed(
            description=
f"""[**Bot Invite Link**]({oauth_url(self.bot.user.id, perms)})
[**Home Server**](https://discord.gg/SaEgfnepn7)
[**Challenge Points Website**](https://new-challenge-points.herokuapp.com/)
[**Github Repo**](https://github.com/Challenge-Points)\n
I hope you're having a good day :)""",
            colour=0xff0000)
        embed.set_thumbnail(url=(self.bot.get_guild(812293813518991390).icon_url))
        await ctx.reply(embed=embed)
예제 #9
0
    async def createtemplate(self, ctx: Context):
        '''Creates a new template for your guild'''

        # Send the flavour text behind getting a template name
        clean_prefix = ctx.prefix if '<@' not in ctx.prefix else str(
            self.bot.get_user(
                int(''.join([i for i in ctx.prefix if i.isdigit()]))))
        await ctx.send(''.join([
            "What name do you want to give this template? ",
            "This will be used for the set and get commands, eg if the name of your ",
            f"template is `test`, the commands generated will be `{clean_prefix}settest` ",
            f"to set a profile, `{clean_prefix}gettest` to get a profile, ",
            f"and `{clean_prefix}deletetest` to delete a profile. ",
            "A profile name is case insensitive.",
        ]))

        # Get name from the messages they send
        while True:
            # Get message
            try:
                name_message = await self.bot.wait_for(
                    'message',
                    check=lambda m: m.author == ctx.author and m.channel == ctx
                    .channel,
                    timeout=120)

            # Catch timeout
            except AsyncTimeoutError:
                await ctx.send(
                    f"{ctx.author.mention}, your template creation has timed out after 2 minutes of inactivity."
                )
                return

            # Check name for characters
            profile_name = name_message.content.lower()
            if [i for i in profile_name if i not in ASCII_LOWERCASE + DIGITS]:
                await ctx.send(
                    "You can only use normal lettering and digits in your command name. Please run this command again to set a new one."
                )
                return

            # Check name for length
            if 30 >= len(profile_name) >= 1:
                pass
            else:
                await ctx.send(
                    "The maximum length of a profile name is 30 characters. Please give another name."
                )
                continue

            # Check name is unique
            if Profile.all_guilds[ctx.guild.id].get(profile_name):
                await ctx.send(
                    f"This server already has a template with name `{profile_name}`. Please run this command again to provide another one."
                )
                return
            break

        # Get colour
        # TODO
        colour = 0x000000

        # Get verification channel
        await ctx.send(
            "What channel would you like the the verification process to happen in? If you want profiles to be verified automatically, just say `continue`."
        )
        verification_channel_id = None
        try:
            verification_message = await self.bot.wait_for(
                'message',
                check=lambda m: m.author == ctx.author and m.channel == ctx.
                channel,
                timeout=120)
        except AsyncTimeoutError:
            await ctx.send(
                f"{ctx.author.mention}, because of your 2 minutes of inactivity, profiles have been set to automatic approval."
            )
        else:
            if verification_message.channel_mentions:
                verification_channel = verification_message.channel_mentions[0]
                proper_permissions = Permissions()
                proper_permissions.update(read_messages=True,
                                          add_external_emojis=True,
                                          send_messages=True,
                                          add_reactions=True,
                                          embed_links=True)
                if verification_channel.permissions_for(
                        ctx.guild.me).is_superset(proper_permissions):
                    verification_channel_id = verification_channel.id
                    pass
                else:
                    await ctx.send(
                        "I don't have all the permissions I need to be able to send messages to that channel. I need `read messages`, `send messages`, `add external emojis`, `add reactions`, and `embed links`. Please update the channel permissions, and run this command again."
                    )
                    return
            # elif verification_message.content.lower() == 'continue':
            #     pass

        # Get an ID for the profile
        profile = Profile(
            profile_id=generate_id(),
            colour=colour,
            guild_id=ctx.guild.id,
            verification_channel_id=verification_channel_id,
            name=profile_name,
        )

        # Now we start the field loop
        index = 0
        field = True
        image_set = False
        while field:
            field = await self.create_new_field(ctx, profile.profile_id, index,
                                                image_set)
            if field:
                image_set = isinstance(field.field_type,
                                       ImageField) or image_set
            index += 1
            if index == 20:
                break

        # Save it all to database
        async with self.bot.database() as db:
            await db(
                'INSERT INTO profile (profile_id, name, colour, guild_id, verification_channel_id) VALUES ($1, $2, $3, $4, $5)',
                profile.profile_id, profile.name, profile.colour,
                profile.guild_id, profile.verification_channel_id)
            for field in profile.fields:
                await db(
                    'INSERT INTO field (field_id, name, index, prompt, timeout, field_type, optional, profile_id) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)',
                    field.field_id, field.name, field.index, field.prompt,
                    field.timeout, field.field_type.name, field.optional,
                    field.profile_id)

        # Output to user
        self.log_handler.info(
            f"New template '{profile.name}' created on guild {ctx.guild.id}")
        await ctx.send(
            f"Your template has been created with {len(profile.fields)} fields. Users can now run `{ctx.prefix}set{profile.name.lower()}` to set a profile, or `{ctx.prefix}get{profile.name.lower()} @User` to get the profile of another user."
        )