Skip to content

Instantly share code, notes, and snippets.

@ITKewai
Created October 28, 2021 17:25
Show Gist options
  • Save ITKewai/f0129d32cdbfa78bc85cece404e35f24 to your computer and use it in GitHub Desktop.
Save ITKewai/f0129d32cdbfa78bc85cece404e35f24 to your computer and use it in GitHub Desktop.
import re
import sys
import traceback
import discord
from discord.ext import commands
from data.var import *
def translate_errors(_string: str):
eng_ita_error = {
'create_instant_invite': 'Creare inviti',
'kick_members': 'Espellere Membri',
'ban_members': 'Bannare Membri',
'administrator': 'Amministratore',
'manage_channels': 'Gestire canali',
'manage_guild': 'Gestire Server',
'add_reactions': 'Aggiungere reazioni',
'view_audit_log': 'Visualizzare il registro attività',
'priority_speaker': 'Priorità di parola',
'stream': 'Video',
'read_messages': 'Leggere Messaggi',
'view_channel': 'Leggere i canali testuali e vedere i canali vocali',
'send_messages': 'Inviare i messaggi',
'send_tts_messages': 'Usare la sintesi vocale',
'manage_messages': 'Gestire messaggi',
'embed_links': 'Incorporare i link',
'attach_files': 'Allegare i file',
'read_message_history': 'Leggere la cronologia dei messaggi',
'mention_everyone': 'Menziona @everyone: @here e tutti i ruoli',
'external_emojis': 'Usare emoji esterni',
'use_external_emojis': 'Usare emoji esterni',
'view_guild_insights': 'Visualizzare statitiche server',
'connect': 'Collegarsi alle chat vocale',
'speak': 'Parlare',
'mute_members': 'Silenzia membri',
'deafen_members': "Silenzai l'audio degli altri",
'move_members': 'Sposta utenti',
'use_voice_activation': "Usare l'attivazione vocale",
'change_nickname': 'Cambia nickname',
'manage_nicknames': 'Gestire i soprannomi',
'manage_roles': 'Gestire i ruoli',
'manage_permissions': 'Gestire i ruoli',
'manage_webhooks': 'Gestire i webhook',
'manage_emojis': 'Gestire gli emoji',
}
return re.sub('({})'.format('|'.join(map(re.escape, eng_ita_error.keys()))), lambda m: eng_ita_error[m.group()],
_string)
async def embed_gen(ctx, title="", name=None, value=None):
embed = discord.Embed(title=title, colour=discord.Colour.red())
if name and value:
embed.add_field(name=name, value=value, inline=False)
try:
await ctx.send(embed=embed, delete_after=15)
except:
await ctx.send(f'**{name}**\n```{value}```')
else:
try:
await ctx.send(embed=embed, delete_after=15)
except:
await ctx.send(f'**{title}**')
class errori(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.bot.show_error_console = False
self.ignore = ('vol', 'tra', 'equalizer', 'appeal_reason', 'amount', 'tempo', 'target')
@commands.command(description='Effettua il check dei permessi del bot')
@commands.bot_has_permissions(manage_messages=True, attach_files=True, embed_links=True, create_instant_invite=True,
administrator=True)
async def setup(self, ctx):
await ctx.send('Ho tutti i permessi per un corretto funzionamento, ottimo direi!')
@commands.command(description='Attiva o disattiva i log in console', hidden=True)
@commands.is_owner()
async def console(self, ctx):
self.bot.show_error_console = not self.bot.show_error_console
await ctx.send(f'Valore : {self.bot.show_error_console}')
@commands.Cog.listener()
async def on_command_error(self, ctx, error):
if self.bot.show_error_console:
sys.stderr.write('# # # cogs.errori # # #\n')
traceback.print_exception(type(error), error, error.__traceback__)
sys.stderr.write('# # # cogs.errori # # #\n')
if ctx.author.id in self.bot.owner_ids: # ctx.author.id == self.bot.owner_id: se non è in un team
await ctx.message.add_reaction('🔥')
await ctx.reinvoke()
return
if isinstance(error, commands.ConversionError):
await ctx.message.add_reaction('‼')
elif isinstance(error, commands.CheckFailure):
if isinstance(error, commands.PrivateMessageOnly):
await embed_gen(ctx=ctx,
title="⚠ | Comando disponibile sono scrivendo in privato al bot")
elif isinstance(error, commands.NoPrivateMessage):
await embed_gen(ctx=ctx,
name="⚠ | Comando non disponibile in chat privata:",
value='Invitami in un server e scrivimi da esso, **[clicca qui]'
'(https://discord.com/api/oauth2/authorize?client_id='
'714798417746067547&permissions=8&scope=bot)**')
elif isinstance(error, commands.CheckAnyFailure):
await ctx.message.add_reaction('‼')
elif isinstance(error, commands.NotOwner):
await embed_gen(ctx=ctx,
title="⚠ | Comando riservato solo al proprietario del bot")
elif isinstance(error, commands.MissingPermissions):
raw_error = ''
for x in error.missing_permissions:
raw_error += f'{x} \n'
await embed_gen(ctx=ctx,
name="⚠ | Ti mancano i seguenti permessii:",
value=f'```{translate_errors(raw_error)}```')
elif isinstance(error, commands.BotMissingPermissions):
raw_error = ''
for x in error.missing_permissions:
raw_error += f'{x} \n'
await embed_gen(ctx=ctx,
name="⚠ | Mi mancano i seguenti permessi:",
value=f'```{translate_errors(raw_error)}```')
elif isinstance(error, commands.MissingRole):
raw_role = ''
for x in error.missing_role:
raw_role += f'{x} \n'
await embed_gen(ctx=ctx,
name="⚠ | Ti manca il seguente ruolo per utilizzare questo comando:",
value=f'```{raw_role}```')
elif isinstance(error, commands.BotMissingRole):
raw_role = ''
for x in error.missing_role:
raw_role += f'{x} \n'
await embed_gen(ctx=ctx,
name="⚠ | Mi manca il seguente ruolo per utilizzare questo comando:",
value=f'```{raw_role}```')
elif isinstance(error, commands.MissingAnyRole):
raw_roles = ''
for x in error.missing_roles:
raw_roles += f'{x} \n'
await embed_gen(ctx=ctx,
name="⚠ | Ti manca il seguente ruolo per utilizzare questo comando:",
value=f'```{raw_roles}```')
elif isinstance(error, commands.BotMissingAnyRole):
raw_roles = ''
for x in error.missing_roles:
raw_roles += f'{x} \n'
await embed_gen(ctx=ctx,
name="⚠ | Mi mancano i seguenti ruoli per utilizzare questo comando:",
value=f'```{raw_roles}```')
elif isinstance(error, commands.NSFWChannelRequired):
await embed_gen(ctx=ctx,
title="⚠ | Questo comando può essere utilizzato solo nei canali NSFW")
elif str(error) == 'blacklist':
await embed_gen(ctx=ctx,
name="⚠ | SEI FINITO NELLA BLACKLIST:",
value=f'```Tutti i comandi per te sono disabiliati.\n'
f'Se ci sei finito per errore usa il comando:\nappeal```')
elif isinstance(error, commands.CommandNotFound):
await ctx.message.add_reaction('❓')
elif isinstance(error, commands.DisabledCommand):
await embed_gen(ctx=ctx,
name="⚠ | Modalità Manutenzione Attiva:",
value=f'```Tutti i comandi sono disabiliati.\n'
f'Ciro tornerà online il prima possibile```')
elif isinstance(error, commands.CommandInvokeError):
await ctx.message.add_reaction('‼')
elif isinstance(error, commands.UserInputError):
if isinstance(error, commands.MissingRequiredArgument):
await embed_gen(ctx=ctx,
name="⚠ | Manca un parametro per completare il comando:",
value=f'```Riformula il comando includendo {error.param}.')
elif isinstance(error, commands.ArgumentParsingError):
if isinstance(error, commands.UnexpectedQuoteError):
await ctx.message.add_reaction('‼')
elif isinstance(error, commands.InvalidEndOfQuotedStringError):
await ctx.message.add_reaction('‼')
elif isinstance(error, commands.ExpectedClosingQuoteError):
await ctx.message.add_reaction('‼')
elif isinstance(error, commands.BadArgument):
if isinstance(error, commands.MessageNotFound):
await embed_gen(ctx=ctx,
title="⚠ | Messaggio non trovato")
elif isinstance(error, commands.MemberNotFound):
await embed_gen(ctx=ctx,
title=f"Membro `{error.argument}` non trovato in questo server")
elif isinstance(error, commands.GuildNotFound):
await embed_gen(ctx=ctx,
name=f"Server `{error.argument}` non trovato",
value=f"Probabilmente non sono più in quel server")
elif isinstance(error, commands.UserNotFound):
await embed_gen(ctx=ctx,
title=f"Utente `{error.argument}` non trovato")
elif isinstance(error, commands.ChannelNotFound):
await embed_gen(ctx=ctx,
title=f"Canale `{error.argument}` non trovato")
elif isinstance(error, commands.ChannelNotReadable):
await embed_gen(ctx=ctx,
title=f"Non riesco a vedere la cronologia dei messaggi nel canale `{error.argument}`")
elif isinstance(error, commands.BadColourArgument):
await embed_gen(ctx=ctx,
title=f"Colore `{error.argument}` non valido")
elif isinstance(error, commands.RoleNotFound):
await embed_gen(ctx=ctx,
title=f"Ruolo `{error.argument}` non trovato")
elif isinstance(error, commands.BadInviteArgument):
await embed_gen(ctx=ctx,
title=f"Questo invito è invalido o scaduto")
elif isinstance(error, commands.EmojiNotFound):
await embed_gen(ctx=ctx,
title=f"Emoji `{error.argument}` non trovata")
elif isinstance(error, commands.PartialEmojiConversionFailure):
await embed_gen(ctx=ctx,
title=f"Emoji Parziale `{error.argument}` non trovata")
elif isinstance(error, commands.BadBoolArgument):
await ctx.message.add_reaction('‼')
elif isinstance(error, commands.TooManyArguments):
await ctx.message.add_reaction('‼')
elif isinstance(error, commands.errors.CommandOnCooldown):
await ctx.message.add_reaction('❌')
await ctx.message.add_reaction('⏲')
elif isinstance(error, commands.MaxConcurrencyReached):
await ctx.message.add_reaction('❌')
await ctx.message.add_reaction('⏲')
await embed_gen(ctx=ctx,
name="⚠ | Cooldown:",
value=f'```Attendi che il comando precendente finisca```')
elif isinstance(error, commands.errors.ChannelNotFound):
if str(ctx.command) == 'inoltra':
await embed_gen(ctx=ctx,
name="Canale non trovato",
value=f'```Sei sicuro che il canale esista?\ninoltra #canale```')
else:
await self.bot.get_channel(ciro_errori).send(f"`{ctx.guild.id}` + `{ctx.command}`> {error}")
elif isinstance(error, commands.ExtensionError):
if isinstance(error, commands.ExtensionAlreadyLoaded):
await ctx.message.add_reaction('‼')
elif isinstance(error, commands.ExtensionNotLoaded):
await ctx.message.add_reaction('‼')
elif isinstance(error, commands.NoEntryPointError):
await ctx.message.add_reaction('‼')
elif isinstance(error, commands.ExtensionFailed):
await ctx.message.add_reaction('‼')
elif isinstance(error, commands.ExtensionNotFound):
await ctx.message.add_reaction('‼')
elif isinstance(error, commands.CommandRegistrationError):
pass
def setup(bot):
bot.add_cog(errori(bot))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment