Ejemplo n.º 1
0
    async def on_command_error(self, ctx, error):
        # The local handlers so far only catch bad arguments so we still
        # want to print the rest
        if isinstance(error, disnake.errors.DiscordServerError):
            return
        if isinstance(error, sqlalchemy.exc.InternalError):
            session.rollback()
            return
        if (isinstance(error, commands.BadArgument)
                or isinstance(error, commands.errors.CheckFailure)
                or isinstance(error, commands.errors.MissingAnyRole)
                or isinstance(error, commands.errors.MissingRequiredArgument)
            ) and hasattr(ctx.command, "on_error"):
            return

        if isinstance(error, commands.UserInputError):
            await ctx.send(
                "Chyba ve vstupu, jestli vstup obsahuje `\"` nahraď je za `'`")
            return

        if isinstance(error, commands.CommandNotFound):
            prefix = ctx.message.content[:1]
            if prefix not in config.ignored_prefixes:
                await ctx.send(Messages.no_such_command)
            return

        if isinstance(error, commands.CommandOnCooldown):
            await ctx.send(utils.fill_message("spamming", user=ctx.author.id))
            return

        if isinstance(error, utils.NotHelperPlusError):
            await ctx.send(Messages.helper_plus_only)
            return

        output = "".join(
            traceback.format_exception(type(error), error,
                                       error.__traceback__))
        embed = disnake.Embed(
            title=f"Ignoring exception in command {ctx.command}",
            color=0xFF0000)
        embed.add_field(name="Zpráva", value=ctx.message.content[:1000])
        embed.add_field(name="Autor", value=str(ctx.author))
        if ctx.guild and ctx.guild.id != config.guild_id:
            embed.add_field(name="Guild", value=ctx.guild.name)
        embed.add_field(name="Link", value=ctx.message.jump_url, inline=False)

        channel = self.bot.get_channel(config.bot_dev_channel)

        # send context of command with personal information to DM
        if ctx.command.name == "diplom":
            channel_ctx = self.bot.get_user(config.admin_ids[0])
        else:
            channel_ctx = channel
        await channel_ctx.send(embed=embed)

        output = utils.cut_string(output, 1900)
        if channel is not None:
            for message in output:
                await channel.send(f"```\n{message}\n```")
Ejemplo n.º 2
0
 def add_review(self, author, subject, tier, anonym: bool, text):
     try:
         review = Review(member_ID=str(author),
                         subject=subject,
                         tier=tier,
                         anonym=anonym,
                         text_review=text,
                         date=datetime.date.today())
         session.add(review)
         session.commit()
     except Exception:
         session.rollback()
         raise
Ejemplo n.º 3
0
    async def on_raw_reaction_add(self, payload):
        """Catch reaction, get all properties and then call proper cog/s"""
        ctx: ReactionContext = await ReactionContext.from_payload(
            self.bot, payload)
        if ctx is None:
            return

        if self.bot.get_cog("Vote") is not None and (is_command_message(
                'vote', ctx.message.content) or is_command_message(
                    'singlevote', ctx.message.content, False)):
            try:
                await self.bot.get_cog("Vote").handle_raw_reaction_add(payload)
            except sqlalchemy.exc.InternalError:
                session.rollback()
            return

        cogs = []

        if (ctx.message.embeds
                and ctx.message.embeds[0].title is not discord.Embed.Empty
                and "reviews" in ctx.message.embeds[0].title):
            cogs.append(self.bot.get_cog("Review"))
        if ctx.emoji == "📌":
            cogs.append(self.bot.get_cog("AutoPin"))
        if ctx.channel.id not in config.role_channels:
            cogs.append(self.bot.get_cog("Karma"))
        else:
            cogs.append(self.bot.get_cog("ReactToRole"))
        if (ctx.emoji == "❎"
                and payload.channel_id in config.deduplication_channels
                and not payload.member.bot and ctx.message.author.bot):
            cogs.append(self.bot.get_cog("Warden"))
        if (ctx.message.embeds and ctx.message.embeds[0].author.name
                is not discord.Embed.Empty and "streamlinks"
                in ctx.message.embeds[0].author.name.lower()):
            cogs.append(self.bot.get_cog("StreamLinks"))

        if (ctx.channel.id == config.meme_room or ctx.channel.id == config.meme_repost_room) and \
                ctx.message.author.id != ctx.member.id:
            cogs.append(self.bot.get_cog("MemeRepost"))

        for cog in cogs:
            # check if cog is loaded
            if cog:
                try:
                    await cog.handle_reaction(ctx)
                except sqlalchemy.exc.InternalError:
                    session.rollback()
                except discord.errors.DiscordServerError:
                    pass
Ejemplo n.º 4
0
    async def on_raw_reaction_add(self, payload):
        """Catch reaction, get all properties and then call proper cog/s"""
        ctx: ReactionContext = await ReactionContext.from_payload(self.bot, payload)
        if ctx is None:
            return

        if self.bot.get_cog("Vote") is not None and (
            is_command_message("vote", ctx.message.content)
            or is_command_message("singlevote", ctx.message.content, False)
        ):
            try:
                await self.bot.get_cog("Vote").handle_raw_reaction_add(payload)
            except sqlalchemy.exc.InternalError:
                session.rollback()
            return

        cogs = []
        # send embed to user where he left reading
        if ctx.emoji == "🔖":
            await self.bot.get_cog("Bookmark").bookmark_reaction(ctx)
            return

        if ctx.emoji == "📌":
            cogs.append(self.bot.get_cog("AutoPin"))
        if ctx.channel.id not in config.role_channels:
            cogs.append(self.bot.get_cog("Karma"))
        else:
            cogs.append(self.bot.get_cog("Roles"))
        if (
            ctx.emoji == "❎"
            and payload.channel_id in config.deduplication_channels
            and not payload.member.bot
            and ctx.message.author.bot
        ):
            cogs.append(self.bot.get_cog("Warden"))

        if (ctx.channel.id == config.meme_room or ctx.channel.id == config.meme_repost_room) and \
                ctx.message.author.id != ctx.member.id:
            cogs.append(self.bot.get_cog("MemeRepost"))

        for cog in cogs:
            # check if cog is loaded
            if cog:
                try:
                    await cog.handle_reaction(ctx)
                except sqlalchemy.exc.InternalError:
                    session.rollback()
                except disnake.errors.DiscordServerError:
                    pass
Ejemplo n.º 5
0
    def create(self, subject: str, link: str, username: str, description: str,
               thumbnail_url: str, created_at: datetime):
        try:
            streamlink = StreamLink(subject=subject,
                                    link=link,
                                    member_name=username,
                                    description=description,
                                    thumbnail_url=thumbnail_url,
                                    created_at=created_at)

            session.add(streamlink)
            session.commit()
        except:  # noqa: E722
            session.rollback()
            raise
Ejemplo n.º 6
0
 def add_review(self, author, subject, tier, anonym: bool, text) -> Review:
     try:
         review = Review(
             discord_id=str(author),
             subject=subject,
             tier=tier,
             anonym=anonym,
             text_review=text,
             date=datetime.date.today(),
         )
         session.add(review)
         session.commit()
     except Exception:
         session.rollback()
         raise
     return review
Ejemplo n.º 7
0
    async def on_slash_command_error(
            self, inter: disnake.ApplicationCommandInteraction, error):
        if isinstance(error, disnake.errors.DiscordServerError):
            return

        if isinstance(error, sqlalchemy.exc.InternalError):
            session.rollback()
            return

        if isinstance(error, disnake.InteractionTimedOut):
            await inter.response.send_message(Messages.command_timed_out)
            return

        if isinstance(error, commands.CommandOnCooldown):
            await inter.response.send_message(
                utils.fill_message("spamming", user=inter.author.id))
            return

        url = f"https://discord.com/channels/{inter.guild_id}/{inter.channel_id}/{inter.id}"

        output = "".join(
            traceback.format_exception(type(error), error,
                                       error.__traceback__))
        embed = disnake.Embed(
            title=f"Ignoring exception in command {inter.data.name}",
            color=0xFF0000)
        embed.add_field(name="Zpráva", value=inter.filled_options)
        embed.add_field(name="Autor", value=str(inter.author))
        if inter.guild and inter.guild.id != config.guild_id:
            embed.add_field(name="Guild", value=inter.guild.name)
        embed.add_field(name="Link", value=url, inline=False)

        channel = self.bot.get_channel(config.bot_dev_channel)

        # send context of command with personal information to DM
        if inter.data.name == "diplom":
            channel_ctx = self.bot.get_user(config.admin_ids[0])
        else:
            channel_ctx = channel
        await channel_ctx.send(embed=embed)

        output = utils.cut_string(output, 1900)
        if channel is not None:
            for message in output:
                await channel.send(f"```\n{message}\n```")
Ejemplo n.º 8
0
    async def on_command_error(self, ctx: commands.Context, error):
        if isinstance(error, sqlalchemy.exc.InternalError):
            session.rollback()
            return
        elif isinstance(error, discord.DiscordServerError):
            return

        if isinstance(error, commands.CommandNotFound):
            await general_util.delete_message(self.bot, ctx)
            await ctx.channel.send(embed=general_util.generate_error_message(
                Strings.error_unknown_command),
                                   delete_after=Config.base_error_duration)
        elif isinstance(error, commands.CommandOnCooldown):
            await general_util.delete_message(self.bot, ctx)
            await ctx.channel.send(embed=general_util.generate_error_message(
                Strings.populate_string("error_command_on_cooldown",
                                        remaining=round(error.retry_after,
                                                        2))),
                                   delete_after=Config.base_error_duration)
        elif isinstance(error, commands.MissingPermissions):
            await general_util.delete_message(self.bot, ctx)
            await ctx.channel.send(embed=general_util.generate_error_message(
                Strings.error_missing_permission),
                                   delete_after=Config.base_error_duration)
        elif isinstance(error, commands.MissingRole):
            await general_util.delete_message(self.bot, ctx)
            await ctx.channel.send(embed=general_util.generate_error_message(
                Strings.populate_string("error_missing_role",
                                        role=error.missing_role)),
                                   delete_after=Config.base_error_duration)
        elif isinstance(error, commands.MissingRequiredArgument):
            await general_util.delete_message(self.bot, ctx)
            await ctx.channel.send(
                embed=general_util.generate_error_message(
                    Strings.populate_string(
                        "error_missing_argument",
                        argument=error.param,
                        signature=general_util.get_command_signature(ctx))),
                delete_after=Config.base_long_error_duration)
        elif isinstance(error, commands.BadArgument):
            await general_util.delete_message(self.bot, ctx)
            await ctx.channel.send(embed=general_util.generate_error_message(
                Strings.error_bad_argument),
                                   delete_after=Config.base_error_duration)
        elif isinstance(error, commands.MaxConcurrencyReached):
            await general_util.delete_message(self.bot, ctx)
            await ctx.channel.send(embed=general_util.generate_error_message(
                Strings.error_max_concurrency_reached),
                                   delete_after=Config.base_error_duration)
        elif isinstance(error, commands.NoPrivateMessage):
            await ctx.channel.send(embed=general_util.generate_error_message(
                Strings.error_no_private_message),
                                   delete_after=Config.base_error_duration)
        else:
            output = "".join(
                traceback.format_exception(type(error), error,
                                           error.__traceback__))
            logger.error(output)

            channel = self.bot.get_channel(
                Config.bot_log_channel
            ) if Config.bot_log_channel != -1 else None
            if channel is None: return

            embed = discord.Embed(
                title=f"Ignoring exception in command {ctx.command}",
                color=0xFF0000)
            embed.add_field(name="Message", value=ctx.message.content[:1000])
            embed.add_field(name="Autor", value=str(ctx.author))
            embed.add_field(name="Type", value=str(type(error)))
            if ctx.guild:
                embed.add_field(name="Guild", value=ctx.guild.name)
            embed.add_field(name="Link",
                            value=ctx.message.jump_url,
                            inline=False)

            await channel.send(embed=embed)

            output = general_util.split_to_parts(output, 1900)
            if channel is not None:
                for message in output:
                    await channel.send(f"```\n{message}\n```")