コード例 #1
0
ファイル: bot.py プロジェクト: BikiniBottomDiscord/squire
 def __init__(self, started_at, **kwargs):
     super().__init__(command_prefix=settings.prefix,
                      description="sQUIRE, Defender of Bikini Bottom",
                      help_command=commands.MinimalHelpCommand(),
                      intents=discord.Intents.all(),
                      **kwargs)
     self.version = settings.version
     self.started_at = started_at
     self.session = aiohttp.ClientSession()
     self.add_check(lambda ctx: is_mod(ctx.author))
     self._exit_code = 0
コード例 #2
0
ファイル: admins.py プロジェクト: pvffyn/wakeful
 async def check(self, ctx, user : discord.User):
     if is_mod(self.bot, ctx.author):
         try:
             thing = await self.bot.db.fetchrow("SELECT * FROM blacklist WHERE user_id = $1", user.id)
             thing["user_id"]
         except TypeError:
             em=discord.Embed(description=f"{user.mention} isn't blacklisted", color=color())
             await ctx.reply(embed=em, mention_author=False)
         else:
             em=discord.Embed(description=f"{user.mention} is blacklisted", color=color())
             await ctx.reply(embed=em, mention_author=False)
コード例 #3
0
ファイル: raid.py プロジェクト: BikiniBottomDiscord/squire
    async def invites(self, ctx, code=None):
        """Returns information on this server's invites, or on a single invite."""
        invites = await ctx.guild.invites()

        # if a code is provided, info about that invite
        if code:
            invite = discord.utils.get(invites, code=code)

            if not invite:
                return await ctx.send(f"Invite with code {code} not found.")

            return await ctx.send(
                f"__Invite__: `{invite.code}`\n"
                f"> inviter: {invite.inviter} ({invite.inviter.id})\n"
                f"> created_at: {invite.created_at}\n"
                f"> uses: {invite.uses}\n")

        # if no code is provided, general server invite breakdown
        inv_by_mods = 0
        inv_by_bots = 0
        inv_permanent = 0
        inv_unused = 0

        for i in invites:
            if is_mod(i.inviter) and not i.inviter.bot:
                inv_by_mods += 1
            if i.inviter.bot:
                inv_by_bots += 1
            if i.max_age == 0:
                inv_permanent += 1
            if i.uses == 0:
                inv_unused += 1

        await ctx.send(f"__Server Invites__:\n"
                       f"> total: {len(invites)}\n"
                       f"> mods: {inv_by_mods}\n"
                       f"> bots: {inv_by_bots}\n"
                       f"> permanent: {inv_permanent}\n"
                       f"> unused: {inv_unused}\n")
コード例 #4
0
    async def on_message(self, msg):
        if self.emptyPrefix:
            await self.process_commands(msg)
            return

        if pwd.getpwuid(os.getuid())[0] != "pi":
            if not is_mod(self, msg.author):
                return
        
        prefix = await get_prefix(self, msg)
        
        if msg.guild is None:
            if msg.content.startswith(prefix):
                return await msg.channel.send(f"DM commands are disabled, please invite me to a guild\nInvite: https://discord.com/api/oauth2/authorize?client_id={self.user.id}&permissions=8&scope=self\nSupport Server: {self.invite}")

        if msg.author.bot:
            return

        if await is_blacklisted(self, msg.author):
            return

        for i in prefix:
            if msg.content.startswith(i):
                    
                if msg.guild is not None:
                    try:
                        command = msg.content.split(i)
                    except ValueError:
                        command = msg.content
                    command = command[1]
                    res = await self.db.fetchrow("SELECT commands FROM commands WHERE guild = $1", msg.guild.id)
                    try:
                        commands = res["commands"]
                    except:
                        success = False
                    else:
                        success = True
                    if success:
                        command_obj = self.get_command(command)
                        try:
                            self.get_command(command).parent
                        except:
                            command_name = None
                        else:
                            command_name = "".join(command_obj.name if command_obj.parent is None else f"{command_obj.parent.name} {command_obj.name}")
                        commands = commands.split(",")
                        if command_name in commands and command != "":
                            if is_mod(self, msg.author):
                                pass
                            else:
                                em=discord.Embed(description=f"This command has been disabled by the server administrators", color=color())
                                return await msg.channel.send(embed=em)
                        else:
                            pass
                    else:
                        pass
                await self.process_commands(msg)
                return
            
            if msg.content == f"<@!{self.user.id}>" or msg.content == f"<@{self.user.id}>":
                if msg.guild:
                    em=discord.Embed(description=f"The prefix for `{msg.guild.name}` is `{prefix[2]}`", color=color())
                    return await msg.channel.send(embed=em)
                else:
                    em=discord.Embed(description=f"The prefix for dms is `{prefix[2]}`", color=color())
                    return await msg.channel.send(embed=em)
コード例 #5
0
ファイル: admins.py プロジェクト: pvffyn/wakeful
 async def playing(self, ctx, *, game):
     if is_mod(self.bot, ctx.author):
         await self.bot.change_presence(activity=discord.Game(name=game))
         await ctx.message.add_reaction(self.bot.icons['greentick'])
         self.bot.status = ""
コード例 #6
0
ファイル: admins.py プロジェクト: pvffyn/wakeful
 async def streaming(self, ctx, url, *, game):
     if is_mod(self.bot, ctx.author):
         await self.bot.change_presence(activity=discord.Streaming(name=str(game), url=f'https://www.twitch.tv/{url.lower()}'))
         await ctx.message.add_reaction(self.bot.icons['greentick'])
         self.bot.status = ""
コード例 #7
0
ファイル: admins.py プロジェクト: pvffyn/wakeful
 async def remove(self, ctx, user : discord.User):
     if is_mod(self.bot, ctx.author):
         await self.bot.db.fetch("DELETE FROM blacklist WHERE user_id = $1", user.id)
         em=discord.Embed(description=f"Successfully unblacklisted {user.mention}", color=color())
         await ctx.reply(embed=em, mention_author=False)
コード例 #8
0
ファイル: admins.py プロジェクト: pvffyn/wakeful
 async def add(self, ctx, user : discord.User):
     if is_mod(self.bot, ctx.author):
         await self.bot.db.fetch("INSERT INTO blacklist (user_id) VALUES ($1)", user.id)
         em=discord.Embed(description=f"Successfully blacklisted {user.mention}", color=color())
         await ctx.reply(embed=em, mention_author=False)
コード例 #9
0
ファイル: admins.py プロジェクト: pvffyn/wakeful
 async def developer(self, ctx):
     if is_mod(self.bot, ctx.author):
         await ctx.invoke(self.bot.get_command("help"), **{"command":"developer"})
コード例 #10
0
ファイル: admins.py プロジェクト: pvffyn/wakeful
 async def reset(self, ctx):
     if is_mod(self.bot, ctx.author):
         await self.bot.change_presence(activity=discord.Game(f"@wakeful for prefix | {len(self.bot.guilds)} guilds & {len(self.bot.users)} users"))
         self.bot.status = None
         await ctx.message.add_reaction(self.bot.icons['greentick'])
コード例 #11
0
ファイル: admins.py プロジェクト: pvffyn/wakeful
 async def competing(self, ctx, *, game):
     if is_mod(self.bot, ctx.author):
         await self.bot.change_presence(activity=discord.Activity(name=f"{game}", type=5))
         await ctx.message.add_reaction(self.bot.icons['greentick'])
         self.bot.status = ""
コード例 #12
0
ファイル: events.py プロジェクト: pvffyn/wakeful
    async def on_command_error(self, ctx, error):
        if isinstance(error, TooLong):
            await ctx.reply(str(error),
                            mention_author=False,
                            allowed_mentions=discord.AllowedMentions.none())

        elif isinstance(error, commands.CommandOnCooldown):
            if not is_mod(self.bot, ctx.author):
                em = discord.Embed(
                    description=
                    f"This command is on cooldown, try again in `{round(error.retry_after, 1)}` seconds.",
                    color=color())
                await ctx.reply(embed=em, mention_author=False)
            else:
                ctx.command.reset_cooldown(ctx)
                await self.bot.process_commands(ctx.message)

        elif isinstance(error, commands.MissingRequiredArgument):
            param = str(error.param).split(":")
            param = param[0].replace(" ", "")
            em = discord.Embed(
                description=f"`{param}` is a required argument that is missing",
                color=color())
            await ctx.reply(embed=em, mention_author=False)

        elif isinstance(error, commands.CommandNotFound):
            if ctx.prefix != "":
                cmd = ctx.invoked_with
                cmds = [cmd.name for cmd in self.bot.commands]
                match = difflib.get_close_matches(cmd, cmds)
                try:
                    command = self.bot.get_command(match[0])
                except IndexError:
                    command = None
                if command:
                    if not command.hidden:
                        em = discord.Embed(
                            description=
                            f"`{cmd}` is not a valid command, did you mean `{match[0]}`?",
                            color=color())
                        msg = await ctx.reply(embed=em,
                                              mention_author=False,
                                              delete_after=5)
                        reactions = [
                            self.bot.icons['greentick'],
                            self.bot.icons['redtick']
                        ]
                        for reaction in reactions:
                            await msg.add_reaction(reaction)

                        reaction, user = await self.bot.wait_for(
                            "reaction_add",
                            check=lambda reaction, user: user == ctx.author and
                            str(reaction.emoji
                                ) in reactions and reaction.message == msg)
                        if str(reaction.emoji) == self.bot.icons['greentick']:
                            alt_ctx = await copy_context_with(
                                ctx,
                                author=ctx.author,
                                content=f"{ctx.prefix}{match[0]}")
                            await self.bot.invoke(alt_ctx)
                        elif str(reaction.emoji) == self.bot.icons['redtick']:
                            await msg.delete()
                else:
                    em = discord.Embed(
                        description=f"`{cmd}` is not a valid command",
                        color=color())
                    m = await ctx.reply(embed=em,
                                        mention_author=False,
                                        delete_after=3)

        elif isinstance(error, commands.NSFWChannelRequired):
            em = discord.Embed(
                description=
                f"This command has to be executed in an nsfw channel",
                color=color())
            await ctx.reply(embed=em, mention_author=False)

        elif isinstance(error, commands.MemberNotFound):
            em = discord.Embed(
                description=f"Couldn't find member `{error.argument}`",
                color=color())
            await ctx.reply(embed=em, mention_author=False)

        elif isinstance(error, commands.BotMissingPermissions):
            perms = ", ".join(
                perm.replace("_", " ").lower() for perm in error.missing_perms)
            em = discord.Embed(
                description=
                f"I need {perms} permissions to execute this command",
                color=color())
            await ctx.reply(embed=em, mention_author=False)

        elif isinstance(error, commands.MissingPermissions):
            perms = ", ".join(
                perm.replace("_", " ").lower() for perm in error.missing_perms)
            em = discord.Embed(
                description=
                f"You need {perms} permissions to execute this command",
                color=color())
            await ctx.reply(embed=em, mention_author=False)

        elif isinstance(error, commands.NotOwner):
            if list(error.args) != [] and len(list(error.args)) != 0:
                msg = list(error.args)[0]
                em = discord.Embed(description=msg, color=color())
                return await ctx.reply(embed=em, mention_author=False)
            em = discord.Embed(
                description="You aren't allowed to execute this command",
                color=color())
            await ctx.reply(embed=em, mention_author=False)

        elif isinstance(error, commands.CommandInvokeError):
            error = error.original
            if isinstance(error, TooLong):
                await ctx.reply(
                    str(error),
                    mention_author=False,
                    allowed_mentions=discord.AllowedMentions.none())

            elif isinstance(error, aiohttp.ClientConnectionError):
                address = f"{error.host}:{error.port}"
                em = discord.Embed(
                    description=f"I couldn't connect to `{address}`",
                    color=color())
                await ctx.reply(embed=em, mention_author=False)

            elif isinstance(error, commands.BotMissingPermissions):
                perms = ", ".join(
                    perm.replace("_", " ").lower()
                    for perm in error.missing_perms)
                em = discord.Embed(
                    description=
                    f"I need {perms} permissions to execute this command",
                    color=color())
                await ctx.reply(embed=em, mention_author=False)

            elif isinstance(error, discord.Forbidden):
                em = discord.Embed(
                    description=f"I don't have permission to do this",
                    color=color())
                await ctx.reply(embed=em, mention_author=False)
            else:
                if is_mod(self.bot, ctx.author):
                    errormsg = "".join(
                        traceback.format_exception(type(error), error,
                                                   error.__traceback__))
                    try:
                        await ctx.reply(
                            f"```py\n{errormsg}```",
                            mention_author=False,
                            allowed_mentions=discord.AllowedMentions.none())
                    except Exception:
                        raise error
                    else:
                        raise error
                else:
                    em = discord.Embed(description=f"```py\n{error}```",
                                       color=color())
                    await ctx.reply(embed=em, mention_author=False)
                    raise error

        else:
            if is_mod(self.bot, ctx.author):
                errormsg = "".join(
                    traceback.format_exception(type(error), error,
                                               error.__traceback__))
                try:
                    await ctx.reply(
                        f"```py\n{errormsg}```",
                        mention_author=False,
                        allowed_mentions=discord.AllowedMentions.none())
                except Exception:
                    raise error
                else:
                    raise error
            else:
                em = discord.Embed(description=f"```py\n{error}```",
                                   color=color())
                await ctx.reply(embed=em, mention_author=False)
                raise error