2016-07-09 11:26:43 +12:00
|
|
|
import discord
|
2016-07-19 07:57:23 +12:00
|
|
|
import traceback
|
2016-07-31 02:59:35 +12:00
|
|
|
import logging
|
|
|
|
import datetime
|
2016-08-07 10:20:16 +12:00
|
|
|
import pendulum
|
2016-08-12 14:13:02 +12:00
|
|
|
import os
|
2017-02-13 11:40:28 +13:00
|
|
|
import aiohttp
|
2016-08-12 14:13:02 +12:00
|
|
|
|
2016-08-26 16:56:16 +12:00
|
|
|
os.chdir(os.path.dirname(os.path.realpath(__file__)))
|
2016-07-09 11:26:43 +12:00
|
|
|
|
2016-08-27 01:23:02 +12:00
|
|
|
from discord.ext import commands
|
2018-10-30 14:00:37 +13:00
|
|
|
import utils
|
2016-08-27 01:23:02 +12:00
|
|
|
|
2020-10-07 15:15:09 +13:00
|
|
|
intent = discord.Intents.all()
|
|
|
|
intent.presences = False
|
|
|
|
|
2018-10-05 08:38:15 +13:00
|
|
|
opts = {
|
2020-09-14 06:06:02 +12:00
|
|
|
"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),
|
2020-10-07 15:15:09 +13:00
|
|
|
"intents": intent,
|
2018-10-05 08:38:15 +13:00
|
|
|
}
|
2016-08-31 07:51:04 +12:00
|
|
|
|
2017-03-06 09:40:00 +13:00
|
|
|
bot = commands.AutoShardedBot(**opts)
|
2020-09-14 06:06:02 +12:00
|
|
|
logging.basicConfig(level=logging.INFO, filename="bonfire.log")
|
2016-07-08 10:10:24 +12:00
|
|
|
|
2016-07-31 12:20:55 +12:00
|
|
|
|
2019-01-28 15:58:39 +13:00
|
|
|
@bot.before_invoke
|
|
|
|
async def start_typing(ctx):
|
2019-01-28 19:23:19 +13:00
|
|
|
try:
|
|
|
|
await ctx.trigger_typing()
|
|
|
|
except (discord.Forbidden, discord.HTTPException):
|
|
|
|
pass
|
2019-01-28 15:58:39 +13:00
|
|
|
|
|
|
|
|
2020-10-11 13:10:00 +13:00
|
|
|
@bot.event
|
|
|
|
async def on_ready():
|
|
|
|
completion = "Ready in: ```\n{}```".format(
|
|
|
|
(pendulum.now(tz="UTC") - bot.uptime).in_words()
|
|
|
|
)
|
|
|
|
await bot.get_guild(214143647447253003).get_channel(214146604519784449).send(
|
|
|
|
completion
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2016-09-24 14:38:58 +12:00
|
|
|
@bot.event
|
2017-03-08 12:26:13 +13:00
|
|
|
async def on_command_completion(ctx):
|
2019-01-28 15:58:39 +13:00
|
|
|
author = ctx.author.id
|
|
|
|
guild = ctx.guild.id if ctx.guild else None
|
|
|
|
command = ctx.command.qualified_name
|
|
|
|
|
|
|
|
await bot.db.execute(
|
|
|
|
"INSERT INTO command_usage(command, guild, author) VALUES ($1, $2, $3)",
|
|
|
|
command,
|
|
|
|
guild,
|
2020-09-14 06:06:02 +12:00
|
|
|
author,
|
2019-01-28 15:58:39 +13:00
|
|
|
)
|
2016-08-04 13:31:38 +12:00
|
|
|
|
2018-10-30 14:00:37 +13:00
|
|
|
# Now add credits to a users amount
|
|
|
|
# user_credits = bot.db.load('credits', key=ctx.author.id, pluck='credits') or 1000
|
|
|
|
# user_credits = int(user_credits) + 5
|
|
|
|
# update = {
|
|
|
|
# 'member_id': str(ctx.author.id),
|
|
|
|
# 'credits': user_credits
|
|
|
|
# }
|
|
|
|
# await bot.db.save('credits', update)
|
|
|
|
|
2016-09-01 07:09:47 +12:00
|
|
|
|
2016-07-09 13:42:33 +12:00
|
|
|
@bot.event
|
2017-05-12 11:25:22 +12:00
|
|
|
async def on_command_error(ctx, error):
|
2019-01-28 15:58:39 +13:00
|
|
|
error = error.original if hasattr(error, "original") else error
|
|
|
|
ignored_errors = (
|
|
|
|
commands.CommandNotFound,
|
|
|
|
commands.DisabledCommand,
|
|
|
|
discord.Forbidden,
|
|
|
|
aiohttp.ClientOSError,
|
|
|
|
commands.CheckFailure,
|
|
|
|
commands.CommandOnCooldown,
|
|
|
|
)
|
|
|
|
|
|
|
|
if isinstance(error, ignored_errors):
|
2016-09-18 13:29:48 +12:00
|
|
|
return
|
2019-01-28 15:58:39 +13:00
|
|
|
elif isinstance(error, discord.HTTPException) and (
|
2020-09-14 06:06:02 +12:00
|
|
|
"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)
|
|
|
|
):
|
2019-01-28 15:58:39 +13:00
|
|
|
return
|
2020-09-14 06:06:02 +12:00
|
|
|
elif isinstance(error, discord.NotFound) and "Unknown Channel" in str(error):
|
2016-11-12 15:22:35 +13:00
|
|
|
return
|
2016-09-23 13:48:18 +12:00
|
|
|
|
2017-04-09 14:52:10 +12:00
|
|
|
try:
|
2020-08-08 11:35:49 +12:00
|
|
|
if isinstance(error, (commands.BadArgument, commands.BadUnionArgument)):
|
2020-09-14 06:06:02 +12:00
|
|
|
fmt = "Please provide a valid argument to pass to the command: {}".format(
|
|
|
|
error
|
|
|
|
)
|
2017-04-09 14:52:10 +12:00
|
|
|
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)
|
2020-09-14 06:06:02 +12:00
|
|
|
elif isinstance(
|
|
|
|
error,
|
|
|
|
(
|
2019-12-01 10:24:17 +13:00
|
|
|
commands.InvalidEndOfQuotedStringError,
|
|
|
|
commands.ExpectedClosingQuoteError,
|
2020-09-14 06:06:02 +12:00
|
|
|
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"
|
|
|
|
)
|
2017-04-09 14:52:10 +12:00
|
|
|
else:
|
2019-11-20 12:13:10 +13:00
|
|
|
if isinstance(bot.error_channel, int):
|
|
|
|
bot.error_channel = bot.get_channel(bot.error_channel)
|
2019-11-20 12:29:12 +13:00
|
|
|
|
|
|
|
if bot.error_channel is None:
|
2019-11-20 12:13:10 +13:00
|
|
|
now = datetime.datetime.now()
|
2020-09-14 06:06:02 +12:00
|
|
|
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,
|
|
|
|
)
|
2019-11-20 12:13:10 +13:00
|
|
|
traceback.print_tb(error.__traceback__, file=f)
|
2020-09-14 06:06:02 +12:00
|
|
|
print("{0.__class__.__name__}: {0}".format(error), file=f)
|
2019-11-20 12:13:10 +13:00
|
|
|
else:
|
2020-09-14 06:06:02 +12:00
|
|
|
await bot.error_channel.send(
|
|
|
|
f"""```
|
2019-11-20 12:13:10 +13:00
|
|
|
Command = {discord.utils.escape_markdown(ctx.message.clean_content).strip()}
|
|
|
|
{''.join(traceback.format_tb(error.__traceback__)).strip()}
|
2020-09-14 06:06:02 +12:00
|
|
|
{error.__class__.__name__}: {error}```"""
|
|
|
|
)
|
2017-04-09 14:52:10 +12:00
|
|
|
except discord.HTTPException:
|
|
|
|
pass
|
2016-07-31 12:20:55 +12:00
|
|
|
|
2016-07-18 09:10:12 +12:00
|
|
|
|
2020-09-14 06:06:02 +12:00
|
|
|
if __name__ == "__main__":
|
|
|
|
bot.remove_command("help")
|
2019-01-28 15:58:39 +13:00
|
|
|
# Setup our bot vars, db and cache
|
2017-06-28 14:01:36 +12:00
|
|
|
bot.db = utils.DB()
|
2019-01-28 15:58:39 +13:00
|
|
|
bot.cache = utils.Cache(bot.db)
|
2019-11-20 12:22:42 +13:00
|
|
|
bot.error_channel = utils.error_channel
|
2019-01-30 12:37:13 +13:00
|
|
|
# Start our startup task (cache sets up the database, so just this)
|
2019-01-28 15:58:39 +13:00
|
|
|
bot.loop.create_task(bot.cache.setup())
|
2017-02-26 10:45:59 +13:00
|
|
|
for e in utils.extensions:
|
2016-07-09 13:27:19 +12:00
|
|
|
bot.load_extension(e)
|
2017-06-07 20:30:19 +12:00
|
|
|
|
2018-09-24 10:41:05 +12:00
|
|
|
bot.uptime = pendulum.now(tz="UTC")
|
2017-02-26 10:45:59 +13:00
|
|
|
bot.run(utils.bot_token)
|