예제 #1
0
 async def callback(self, response: discord.SlashCommandResponse) -> None:
     server_id = response.options.id or response.guild_id
     if not str(server_id).isdigit():
         return await response.send_message('Not a valid serverid',
                                            ephemeral=True)
     guild = self.parent.cog.bot.get_guild(int(server_id))
     if guild is not None:
         database = await self.parent.cog.database_class_server()
         await database.set(server_id, response.options.reason)
         self.parent.cog.bot.blacklist.append(int(server_id))
         channel = await self.parent.cog.bot.get_welcome_channel(guild)
         embed = ErrorEmbed(title=f'Left {guild.name}')
         embed.description = f'I have to leave the `{guild.name}` because it was marked as a `blacklist guild` by my developer. For further queries please contact my developer.'
         embed.add_field(
             name='Developer',
             value=
             f'[{self.parent.cog.bot.get_user(self.parent.cog.bot.owner_id)}](https://discord.com/users/{self.parent.cog.bot.owner_id})'
         )
         embed.add_field(
             name="Support Server",
             value=f"https://discord.gg/{LinksAndVars.invite_code.value}",
         )
         await channel.send(embed=embed)
         await guild.leave()
         log.info(f'Left guild {guild.id} [Marked as spam]')
         await response.send_message('Server added to the blacklist',
                                     ephemeral=True)
         return
     else:
         return await response.send_message('Server not found',
                                            ephemeral=True)
예제 #2
0
 async def on_guild_join(self, guild: discord.Guild):
     if guild.id in self.blacklist:
         channel = await self.get_welcome_channel(guild)
         embed = ErrorEmbed(title=f'Left {guild.name}')
         embed.description = f'I have to leave the `{guild.name}` because it was marked as a `blacklist guild` by my developer. For further queries please contact my developer.'
         embed.add_field(name = 'Developer', value=f'[{self.get_user(self.owner_id)}](https://discord.com/users/{self.owner_id})')
         embed.add_field(
             name="Support Server",
             value=f"https://discord.gg/{LinksAndVars.invite_code.value}",
         )
         await channel.send(embed=embed)
         await guild.leave()
         log.info(f'Left guild {guild.id} [Marked as spam]')
예제 #3
0
    async def process_commands(self, message):
        ctx = await self.get_context(message, cls=Context)

        if ctx.command is None:
            return

        if ctx.author.id in self.blacklist:
            embed = ErrorEmbed(title='Blacklisted User!')
            embed.description = 'You have been `blacklisted` from using my commands. For further queries please contact my developer.'
            embed.add_field(name = 'Developer', value=f'[{self.get_user(self.owner_id)}](https://discord.com/users/{self.owner_id})')
            embed.add_field(
                name="Support Server",
                value=f"https://discord.gg/{LinksAndVars.invite_code.value}",
            )
            await ctx.send(embed=embed, delete_after=5)
            return

        if ctx.guild is not None and ctx.guild.id in self.blacklist:
            return

        bucket = self.spam_control.get_bucket(message)
        current = message.created_at.timestamp()
        retry_after = bucket.update_rate_limit(current)
        author_id = message.author.id
        if retry_after and author_id != self.owner_id:
            self._auto_spam_count[author_id] += 1
            if self._auto_spam_count[author_id] >= 5:
                await self.add_to_blacklist(author_id)
                del self._auto_spam_count[author_id]
                await self.log_spammer(ctx, message, retry_after, autoblock=True)
            else:
                self.log_spammer(ctx, message, retry_after)
            return
        else:
            self._auto_spam_count.pop(author_id, None)

        try:
            await self.invoke(ctx)
        except:
            pass
예제 #4
0
 async def update_blacklist(self):
     database = await self.db.new(Database.database_category_name.value, Database.user_blacklist_channel_name.value)
     async for message in database._Database__channel.history(limit=None):
         cnt = message.content
         try:
             data = loads(str(cnt))
             data.pop("type")
             data_keys = list(map(str, list(data.keys())))
             self.blacklist.append(int(data_keys[0]))
         except Exception as e:
             log.error(e)
             continue
     database = await self.db.new(Database.database_category_name.value, Database.server_blacklist_channel_name.value)
     async for message in database._Database__channel.history(limit=None):
         cnt = message.content
         try:
             data = loads(str(cnt))
             data.pop("type")
             data_keys = list(map(str, list(data.keys())))
             self.blacklist.append(int(data_keys[0]))
             guild = self.get_guild(int(data_keys[0]))
             if guild is not None:
                 channel = await self.get_welcome_channel(guild)
                 embed = ErrorEmbed(title=f'Left {guild.name}')
                 embed.description = f'I have to leave the `{guild.name}` because it was marked as a `blacklist guild` by my developer. For further queries please contact my developer.'
                 embed.add_field(name = 'Developer', value=f'[{self.get_user(self.owner_id)}](https://discord.com/users/{self.owner_id})')
                 embed.add_field(
                     name="Support Server",
                     value=f"https://discord.gg/{LinksAndVars.invite_code.value}",
                 )
                 await channel.send(embed=embed)
                 await guild.leave()
                 log.info(f'Left guild {guild.id} [Marked as spam]')
         except Exception as e:
             log.error(e)
             continue
     self.blacklist = list(set(self.blacklist))
     log.info('Blacklist Data updated')
예제 #5
0
    async def on_command_error(self, ctx: commands.Context, error):
        if (ctx.cog is not None
                and ctx.cog.qualified_name.lower() == 'Music'.lower()):
            return
        error_channel = await self.bot.fetch_channel(
            ChannelAndMessageId.error_logs_channel.value)
        if isinstance(error, commands.CommandOnCooldown):
            e1 = ErrorEmbed(title="Command Error!", description=f"`{error}`")
            e1.set_footer(text=f"{ctx.author.name}")
            await ctx.channel.send(embed=e1,
                                   delete_after=self.delete_after_time)

        elif isinstance(error, (NoChannelProvided, IncorrectChannelError)):
            return

        elif isinstance(error, commands.MissingRequiredArgument):
            e4 = ErrorEmbed(title="Command Error!", description=f"`{error}`")
            e4.set_footer(text=f"{ctx.author.name}")
            await ctx.channel.send(embed=e4,
                                   delete_after=self.delete_after_time)

        elif isinstance(error, commands.CommandNotFound):
            e2 = ErrorEmbed(title="Command Error!", description=f"`{error}`")
            e2.set_footer(text=f"{ctx.author.name}")
            await ctx.channel.send(embed=e2,
                                   delete_after=self.delete_after_time)

        elif isinstance(error, commands.BotMissingPermissions):
            e = ErrorEmbed(description=error)
            await ctx.send(embed=e, delete_after=self.delete_after_time)

        elif isinstance(error, commands.MissingPermissions):
            e = ErrorEmbed(description=error)
            await ctx.send(embed=e, delete_after=self.delete_after_time)

        elif isinstance(error, commands.UserInputError):
            await ctx.send(
                embed=Embed(
                    description=
                    f"There was something **wrong** with your **input**!\n Please type\n ```)help {ctx.command.name}```,\n to know how to use the command"
                ),
                delete_after=self.delete_after_time,
            )

        elif isinstance(error, commands.NotOwner):
            return

        elif isinstance(error, commands.CheckFailure):
            return

        elif isinstance(error, commands.CheckAnyFailure):
            return

        elif isinstance(error, commands.EmojiNotFound):
            await ctx.send(
                embed=ErrorEmbed(
                    description=
                    f"The emoji provided {error.argument} was **not found!**"),
                delete_after=self.delete_after_time,
            )

        elif isinstance(error, commands.PartialEmojiConversionFailure):
            return

        elif isinstance(error, commands.BadInviteArgument):
            return

        elif isinstance(error, commands.PartialEmojiConversionFailure):
            return

        elif isinstance(error, commands.RoleNotFound):
            await ctx.send(embed=ErrorEmbed(description=error),
                           delete_after=self.delete_after_time)

        elif isinstance(error, commands.NSFWChannelRequired):
            await ctx.send(
                embed=ErrorEmbed(
                    description=
                    f"{error.channel.mention} is an **NSFW Channel**! **{ctx.command.name}** can be run only in **NSFW Channels**! :triumph:"
                ),
                delete_after=self.delete_after_time,
            )

        elif isinstance(error, commands.MissingRole):
            await ctx.send(
                embed=ErrorEmbed(
                    description=
                    f"You **need** the following **role**: **{' '.join(error.missing_role)}**"
                ),
                delete_after=self.delete_after_time,
            )

        elif isinstance(error, commands.MissingAnyRole):
            await ctx.send(
                embed=ErrorEmbed(
                    description=
                    f"You **need** the following **role**: **{' '.join(error.missing_roles)}**"
                ),
                delete_after=self.delete_after_time,
            )

        elif isinstance(error, commands.BotMissingRole):
            await ctx.send(
                embed=ErrorEmbed(
                    description=
                    f"I **need** the following **role**: **{' '.join(error.missing_role)}**"
                ),
                delete_after=self.delete_after_time,
            )

        elif isinstance(error, commands.BotMissingAnyRole):
            await ctx.send(
                embed=ErrorEmbed(
                    description=
                    f"I **need** the following **role**: **{' '.join(error.missing_roles)}**"
                ),
                delete_after=self.delete_after_time,
            )

        elif isinstance(error, commands.BadBoolArgument):
            await ctx.send(embed=ErrorEmbed(description=error),
                           delete_after=self.delete_after_time)

        elif isinstance(error, commands.BadColourArgument):
            await ctx.send(embed=ErrorEmbed(description=error),
                           delete_after=self.delete_after_time)

        elif isinstance(error, commands.ChannelNotFound):
            await ctx.send(embed=ErrorEmbed(description=error),
                           delete_after=self.delete_after_time)

        elif isinstance(error, commands.MessageNotFound):
            await ctx.send(embed=ErrorEmbed(description=error),
                           delete_after=self.delete_after_time)

        elif isinstance(error, commands.MemberNotFound):
            await ctx.send(embed=ErrorEmbed(description=error),
                           delete_after=self.delete_after_time)

        elif isinstance(error, commands.GuildNotFound):
            await ctx.send(embed=ErrorEmbed(description=error),
                           delete_after=self.delete_after_time)

        elif isinstance(error, commands.UserNotFound):
            await ctx.send(embed=ErrorEmbed(description=error),
                           delete_after=self.delete_after_time)

        elif isinstance(error, commands.ChannelNotReadable):
            await ctx.send(
                embed=ErrorEmbed(
                    description=
                    f"I need the **read message history** permission in that channel! In order to execute **{ctx.command.name}**"
                ),
                delete_after=self.delete_after_time,
            )

        elif isinstance(error, commands.DisabledCommand):
            return

        elif isinstance(error, commands.MaxConcurrencyReached):
            await ctx.send(embed=ErrorEmbed(description=error),
                           delete_after=self.delete_after_time)

        elif isinstance(error, commands.PrivateMessageOnly):
            await ctx.send(
                embed=ErrorEmbed(
                    description=f"**{ctx.command.name}** works only in **DM's**"
                ),
                delete_after=self.delete_after_time,
            )

        elif isinstance(error, commands.NoPrivateMessage):
            await ctx.send(
                embed=ErrorEmbed(
                    description=
                    f"**{ctx.command.name}** doesn't work in **DM's**"),
                delete_after=self.delete_after_time,
            )

        elif isinstance(error, commands.CommandOnCooldown):
            l = self.bot.get_command(ctx.command.name)
            left = l.get_cooldown_retry_after(ctx)
            e = ErrorEmbed(title=f"Cooldown left - {round(left)}")
            await ctx.send(embed=e, delete_after=self.delete_after_time)

        elif isinstance(error, commands.CommandInvokeError):
            e7 = ErrorEmbed(
                title=
                "Oh no, I guess I have not been given proper access! Or some internal error",
                description=f"`{error}`"[:2000],
            )
            e7.add_field(name="Command Error Caused By:",
                         value=f"{ctx.command}")
            e7.add_field(name="By", value=f"{ctx.author.name}")
            e7.set_footer(text=f"{ctx.author.name}")
            await ctx.channel.send(embed=e7,
                                   delete_after=self.delete_after_time)

            e = Embed(
                title=f"In **{ctx.guild.name}**",
                description=f"User affected {ctx.message.author}",
            )
            if ctx.guild.icon:
                e.set_thumbnail(url=ctx.guild.icon.url)
            if ctx.guild.banner:
                e.set_image(url=ctx.guild.banner.with_format("png").url)
            e.add_field(name="**Total Members**", value=ctx.guild.member_count)
            e.add_field(
                name="**Bots**",
                value=sum(1 for member in ctx.guild.members if member.bot),
            )
            e.add_field(name="**Server ID**", value=ctx.guild.id, inline=True)
            await ctx.send(
                "**Error report was successfully sent**",
                delete_after=self.delete_after_time,
            )
            try:
                raise error
            except Exception:

                await error_channel.send(
                    embeds=[e7, e],
                    file=discord.File(
                        io.BytesIO(str(traceback.format_exc()).encode()),
                        filename="traceback.txt",
                    ),
                )

        else:
            haaha = ctx.author.avatar.url
            e9 = ErrorEmbed(title="Oh no there was some error",
                            description=f"`{error}`"[:2000])
            e9.add_field(name="**Command Error Caused By**",
                         value=f"{ctx.command}")
            e9.add_field(
                name="**By**",
                value=f"**ID** : {ctx.author.id}, **Name** : {ctx.author.name}",
            )
            e9.set_thumbnail(url=f"{haaha}")
            e9.set_footer(text=f"{ctx.author.name}")
            await ctx.channel.send(embed=e9,
                                   delete_after=self.delete_after_time)

            e = Embed(
                title=f"In **{ctx.guild.name}**",
                description=f"User affected {ctx.message.author}",
            )
            if ctx.guild.icon:
                e.set_thumbnail(url=ctx.guild.icon.url)
            if ctx.guild.banner:
                e.set_image(url=ctx.guild.banner.with_format("png").url)
            e.add_field(name="**Total Members**", value=ctx.guild.member_count)
            e.add_field(
                name="**Bots**",
                value=sum(1 for member in ctx.guild.members if member.bot),
            )
            e.add_field(name="**Server ID**", value=ctx.guild.id, inline=True)
            await ctx.send(
                "**Error report was successfully sent**",
                delete_after=self.delete_after_time,
            )
            try:
                raise error
            except Exception:
                await error_channel.send(
                    embed=e,
                    file=discord.File(
                        io.BytesIO(
                            str(traceback.format_exc()).encode(),
                            filename="traceback.txt",
                        )))