1
0
Fork 0
mirror of synced 2024-05-07 06:02:24 +12:00

Use allowed mentions

This commit is contained in:
Dan Hess 2020-09-13 13:06:02 -05:00
parent 23602080ed
commit 33c79ab097

74
bot.py
View file

@ -12,15 +12,16 @@ from discord.ext import commands
import utils
opts = {
'command_prefix': utils.command_prefix,
'description': utils.bot_description,
'pm_help': None,
'command_not_found': '',
'activity': discord.Activity(name=utils.default_status, type=0)
"command_prefix": utils.command_prefix,
"description": utils.bot_description,
"pm_help": None,
"command_not_found": "",
"activity": discord.Activity(name=utils.default_status, type=0),
"allowed_mentions": discord.AllowedMentions(everyone=False),
}
bot = commands.AutoShardedBot(**opts)
logging.basicConfig(level=logging.INFO, filename='bonfire.log')
logging.basicConfig(level=logging.INFO, filename="bonfire.log")
@bot.before_invoke
@ -41,7 +42,7 @@ async def on_command_completion(ctx):
"INSERT INTO command_usage(command, guild, author) VALUES ($1, $2, $3)",
command,
guild,
author
author,
)
# Now add credits to a users amount
@ -69,56 +70,69 @@ async def on_command_error(ctx, error):
if isinstance(error, ignored_errors):
return
elif isinstance(error, discord.HTTPException) and (
'empty message' in str(error) or
'INTERNAL SERVER ERROR' in str(error) or
'REQUEST ENTITY TOO LARGE' in str(error) or
'Unknown Message' in str(error) or
'Origin Time-out' in str(error) or
'Bad Gateway' in str(error) or
'Gateway Time-out' in str(error) or
'Explicit content' in str(error)):
"empty message" in str(error)
or "INTERNAL SERVER ERROR" in str(error)
or "REQUEST ENTITY TOO LARGE" in str(error)
or "Unknown Message" in str(error)
or "Origin Time-out" in str(error)
or "Bad Gateway" in str(error)
or "Gateway Time-out" in str(error)
or "Explicit content" in str(error)
):
return
elif isinstance(error, discord.NotFound) and 'Unknown Channel' in str(error):
elif isinstance(error, discord.NotFound) and "Unknown Channel" in str(error):
return
try:
if isinstance(error, (commands.BadArgument, commands.BadUnionArgument)):
fmt = "Please provide a valid argument to pass to the command: {}".format(error)
fmt = "Please provide a valid argument to pass to the command: {}".format(
error
)
await ctx.message.channel.send(fmt)
elif isinstance(error, commands.NoPrivateMessage):
fmt = "This command cannot be used in a private message"
await ctx.message.channel.send(fmt)
elif isinstance(error, commands.MissingRequiredArgument):
await ctx.message.channel.send(error)
elif isinstance(error, (
elif isinstance(
error,
(
commands.InvalidEndOfQuotedStringError,
commands.ExpectedClosingQuoteError,
commands.UnexpectedQuoteError)
):
await ctx.message.channel.send("Quotes must go around the arguments you want to provide to the command,"
" recheck where your quotes are")
commands.UnexpectedQuoteError,
),
):
await ctx.message.channel.send(
"Quotes must go around the arguments you want to provide to the command,"
" recheck where your quotes are"
)
else:
if isinstance(bot.error_channel, int):
bot.error_channel = bot.get_channel(bot.error_channel)
if bot.error_channel is None:
now = datetime.datetime.now()
with open("error_log", 'a') as f:
print("In server '{0.message.guild}' at {1}\n"
"Full command: `{0.message.content}`".format(ctx, str(now)), file=f)
with open("error_log", "a") as f:
print(
"In server '{0.message.guild}' at {1}\n"
"Full command: `{0.message.content}`".format(ctx, str(now)),
file=f,
)
traceback.print_tb(error.__traceback__, file=f)
print('{0.__class__.__name__}: {0}'.format(error), file=f)
print("{0.__class__.__name__}: {0}".format(error), file=f)
else:
await bot.error_channel.send(f"""```
await bot.error_channel.send(
f"""```
Command = {discord.utils.escape_markdown(ctx.message.clean_content).strip()}
{''.join(traceback.format_tb(error.__traceback__)).strip()}
{error.__class__.__name__}: {error}```""")
{error.__class__.__name__}: {error}```"""
)
except discord.HTTPException:
pass
if __name__ == '__main__':
bot.remove_command('help')
if __name__ == "__main__":
bot.remove_command("help")
# Setup our bot vars, db and cache
bot.db = utils.DB()
bot.cache = utils.Cache(bot.db)