Exemple #1
0
	async def embedcolor(self, ctx, color:str):
		colorint      = f"0x{color}"
		oldembedcolor = config("embedcolor")
		try:
			newembedcolor = int(colorint, 16)
		except ValueError:
			await ctx.reply("Invalid Color!")
			return
		embed = discord.Embed(color=embedcolor, title="Embed Color", description = f"Old color: #{oldembedcolor}\nNew color: #{color}")

		#Generate image with specified hex
		hexcolor = f"#{color}"
		image    = Image.new("RGB", (100,100), hexcolor)
		buffer   = BytesIO()
		image.save(buffer, "png")
		buffer.seek(0)
		#Attach image and set thumbnail
		file = discord.File(fp=buffer, filename="colorimage.png")
		embed.set_thumbnail(url='attachment://colorimage.png')

		msg = await ctx.reply(embed=embed, file=file)
		confirmation = await ConfirmationCheck.confirm(self, ctx, msg)
		if confirmation:
			embed = discord.Embed(color=newembedcolor, title="Embed Color Set!", description = f"Old color: #{oldembedcolor}\nNew color: #{color}")
			embed.set_thumbnail(url='attachment://colorimage.png')
			await msg.edit(embed=embed)
			#Update the config file
			set_config("embedcolor", colorint)
			#Reload cogs
			for cog in ctx.bot.coglist:
				self.bot.reload_extension(cog)
		elif confirmation is False:
			embed = discord.Embed(color=embedcolor, title="Embed Color", description = "Embed color unchanged")
			await msg.edit(embed=embed)
		elif confirmation is None:
			await ctx.reply("Confirmation timed out")
			return
Exemple #2
0
async def on_command_error(ctx, error):
    if hasattr(ctx.command, 'on_error'):
        return
    elif isinstance(error, CommandNotFound) or ctx.command.hidden:
        await ctx.message.add_reaction(str('❔'))
        return
    elif isinstance(error, errors.NotOwner):
        await ctx.message.add_reaction(str('🔏'))
        return
    elif isinstance(error, errors.DisabledCommand):
        await ctx.message.add_reaction(
            str('<:DisabledCommand:804476191268536320>'))
        return
    elif isinstance(error, errors.MissingPermissions):
        await ctx.message.add_reaction(str('🔐'))
        return
    elif isinstance(error, errors.BotMissingPermissions):
        await ctx.reply("I do not have the requisite permissions")
        return
    elif isinstance(error, errors.MissingRole):
        await ctx.message.add_reaction(str('🔐'))
        return
    elif isinstance(error, errors.CommandOnCooldown):
        await ctx.message.add_reaction(str('<:Cooldown:804477347780493313>'))
        if str(error.cooldown.type.name) != "default":
            cooldowntype = f'per {error.cooldown.type.name}'
        else:
            cooldowntype = 'global'
            await ctx.reply(
                f"This command is on a {round(error.cooldown.per, 0)}s {cooldowntype} cooldown. "
                f"Wait {round(error.retry_after, 1)} seconds",
                delete_after=min(10, error.retry_after))
        return
    elif isinstance(error, errors.MissingRequiredArgument):
        await ctx.reply(
            f"Missing required argument!\nUsage:`{ctx.command.signature}`",
            delete_after=30)
        return
    elif isinstance(error, errors.BadArgument):
        await ctx.reply(f"Invalid argument!\nUsage: `{ctx.command.signature}`",
                        delete_after=30)
        return
    elif isinstance(error, errors.NoPrivateMessage):
        await ctx.message.add_reaction(
            str('<:ServerOnlyCommand:803789780793950268>'))
        return
    elif isinstance(error, CustomChecks.IncorrectGuild):
        await ctx.reply(content="This command does not work in this server.",
                        delete_after=10)
        return
    else:
        # Send user a message

        error_str = str(error).replace(personal_info, '')
        await ctx.message.add_reaction('<:CommandError:804193351758381086>')
        await ctx.reply("Error:\n```" + error_str +
                        "```\nSmallPepperZ will be informed",
                        delete_after=60)

        # Get traceback info

        exc = error
        error_type = type(exc)
        trace = exc.__traceback__

        lines = traceback.format_exception(error_type, exc, trace)
        traceback_text = ''.join(lines)

        # Github gist configuration
        errornum = config("errornum")
        errornum = int(errornum) + 1
        set_config("errornum", str(errornum))

        traceback_text = traceback_text.replace(personal_info, '')

        apiurl = "https://api.github.com/gists"
        gist_id = config("githubgist")
        gisttoedit = f'{apiurl}/{gist_id}'
        githubtoken = config('githubtoken')

        headers = {'Authorization': 'token %s' % githubtoken}
        params = {'scope': 'gist'}
        content = f'Error - {error} \n\n\n {traceback_text}'
        formatted_error_number = f'{errornum:02d}'
        payload = {
            "description":
            "SachiBot Errors - A gist full of errors for my bot",
            "public": False,
            "files": {
                "SachiBotPyError %s.log" % formatted_error_number: {
                    "content": content
                }
            }
        }
        # Upload to github gist
        requests.patch(gisttoedit,
                       headers=headers,
                       params=params,
                       data=json.dumps(payload))
        # Build and send embed for error channel
        channel = bot.get_channel(errorchannel)
        embed1 = discord.Embed(title=f"Error {formatted_error_number}",
                               color=embedcolor)
        embed1.add_field(name="Message Url:",
                         value=ctx.message.jump_url,
                         inline='false')
        embed1.add_field(name="Message:",
                         value=ctx.message.clean_content,
                         inline='true')
        embed1.add_field(name="Author:",
                         value=ctx.message.author.mention,
                         inline='true')
        embed1.add_field(name="\u200B", value='\u200B', inline='true')
        # Check if it was in a guild
        try:
            guildname = ctx.guild.name
            channelname = ctx.channel.name
        except:
            guildname = "DM"
            channelname = ctx.author.id
        embed1.add_field(name="Guild:", value=guildname, inline='true')
        embed1.add_field(name="Channel:", value=channelname, inline='true')
        embed1.add_field(name="\u200B", value='\u200B', inline='true')
        embed1.add_field(name="Error:", value=f'```{error}```', inline='false')
        embed1.add_field(
            name="Traceback:",
            value=f'Traceback Gist - '
            f'[SachiBotPyError {formatted_error_number}.log](https://gist.github.com/SmallPepperZ/{gist_id}#file-sachibotpyerror-{formatted_error_number}-log'
            f' \"Github Gist #{formatted_error_number}\") ',
            inline='false')
        await channel.send(embed=embed1)

        ghost_ping = await channel.send('<@!545463550802395146>')
        await ghost_ping.delete()
Exemple #3
0
def save_status(self):
	set_config('status', (self.bot_member.activity.type, self.bot_member.activity.name, self.bot_member.status))
Exemple #4
0
async def uncaught_error(ctx,
                         error,
                         bot: discord.Client,
                         silent: bool = False):
    error_str = str(error).replace(personal_info, '')
    # Send user a message
    if not silent:
        await ctx.message.add_reaction('<:CommandError:804193351758381086>')
        await ctx.reply(
            f"Error:\n```{error_str}```\n{bot.owner.name} will be informed",
            delete_after=60)

    # Get traceback info

    lines = traceback.format_exception(type(error), error, error.__traceback__)
    traceback_text = ''.join(lines)

    # Github gist configuration
    errornum = int(config("errornum")) + 1
    set_config("errornum", str(errornum))

    traceback_text = traceback_text.replace(personal_info, '')

    apiurl = "https://api.github.com/gists"
    gist_id = config("githubgist")
    githubtoken = config('githubtoken')

    payload = {
        "description": "SachiBot Errors - A gist full of errors for my bot",
        "public": False,
        "files": {
            f"SachiBotPyError {errornum:02d}.log": {
                "content": f'Error - {error} \n\n\n {traceback_text}'
            }
        }
    }
    # Upload to github gist
    requests.patch(f'{apiurl}/{gist_id}',
                   headers={'Authorization': f'token {githubtoken}'},
                   params={'scope': 'gist'},
                   data=json.dumps(payload))
    # Build and send embed for error channel
    channel = bot.get_channel(errorchannel)
    embed1 = discord.Embed(title=f"Error {errornum:02d}", color=embedcolor)
    embed1.add_field(name="Message Url:",
                     value=ctx.message.jump_url,
                     inline='false')
    embed1.add_field(name="Message:",
                     value=ctx.message.clean_content,
                     inline='true')
    embed1.add_field(name="Author:",
                     value=ctx.message.author.mention,
                     inline='true')
    embed1.add_field(name="\u200B", value='\u200B', inline='true')
    # Check if it was in a guild
    try:
        guildname = ctx.guild.name
        channelname = ctx.channel.name
    except:
        guildname = "DM"
        channelname = ctx.author.id
    embed1.add_field(name="Guild:", value=guildname, inline='true')
    embed1.add_field(name="Channel:", value=channelname, inline='true')
    embed1.add_field(name="\u200B", value='\u200B', inline='true')
    embed1.add_field(name="Error:", value=f'```{error}```', inline='false')
    embed1.add_field(
        name="Traceback:",
        value=f'Traceback Gist - '
        f'[SachiBotPyError {errornum:02d}.log](https://gist.github.com/SmallPepperZ/{gist_id}#file-sachibotpyerror-{errornum:02d}-log'
        f' \"Github Gist #{errornum:02d}\") ',
        inline='false')
    await channel.send(embed=embed1)
    ghost_ping = await channel.send(f'<@!{bot.owner.id}>')
    await ghost_ping.delete()