DeepBlue/bot.py

99 lines
2.6 KiB
Python
Raw Normal View History

2020-01-06 22:29:42 +00:00
import discord
2020-01-07 01:41:08 +00:00
import os
import json
2020-01-06 22:29:42 +00:00
from discord.ext import commands
2020-01-08 01:08:07 +00:00
from util import logging, config
2020-01-07 01:41:08 +00:00
# Bot URL https://discordapp.com/api/oauth2/authorize?client_id=657709911337074698&permissions=314432&scope=bot
2020-01-08 01:26:36 +00:00
# The config must be loaded before everything else
2020-01-08 01:08:07 +00:00
total = 0
failed = 0
2020-01-07 17:04:00 +00:00
2020-01-08 01:08:07 +00:00
logging.info("Starting up...\n")
logging.info("--- Loading configs ---\n")
if not config.load("config.json"):
failed += 1
total += 1
logging.info("Finished loading configs.")
logging.info(f"Total {total}, Failed {failed}\n")
client = commands.Bot(command_prefix=config.settings["prefix"], case_insensitive=True)
2020-01-07 17:04:00 +00:00
2020-01-07 01:41:08 +00:00
@client.command()
@commands.is_owner()
2020-01-08 01:26:36 +00:00
async def load(ctx : commands.Context, extension : str):
2020-01-07 03:07:39 +00:00
try:
client.load_extension(f"cogs.{extension}")
await ctx.message.add_reaction("👍")
except:
await ctx.message.add_reaction("👎")
2020-01-07 01:41:08 +00:00
@client.command()
@commands.is_owner()
2020-01-08 01:26:36 +00:00
async def unload(ctx : commands.Context, extension : str):
2020-01-07 03:07:39 +00:00
try:
client.unload_extension(f"cogs.{extension}")
await ctx.message.add_reaction("👍")
except:
await ctx.message.add_reaction("👎")
2020-01-07 01:41:08 +00:00
2020-01-07 03:07:39 +00:00
@client.command()
@commands.is_owner()
2020-01-08 01:26:36 +00:00
async def reload(ctx : commands.Context, extension : str):
2020-01-07 03:07:39 +00:00
try:
client.reload_extension(f"cogs.{extension}")
await ctx.message.add_reaction("👍")
except:
await ctx.message.add_reaction("👎")
2020-01-06 22:29:42 +00:00
@client.event
async def on_ready():
2020-01-08 01:26:36 +00:00
# Try to load cogs
2020-01-08 01:08:07 +00:00
logging.info("--- Loading cogs ---\n")
2020-01-07 01:41:08 +00:00
total = 0
failed = 0
# Load all cogs on startup
# Load "fun" cogs
for filename in os.listdir("./cogs/fun"):
if filename.endswith(".py"):
total += 1
cog = f"cogs.fun.{filename[:-3]}"
try:
client.load_extension(cog)
logging.info(f"Trying {cog}.....Success!")
2020-01-08 01:08:07 +00:00
except Exception as e:
logging.info(f"Trying {cog}.....Failed!")
logging.error(str(e))
2020-01-07 01:41:08 +00:00
failed += 1
# Load "api" cogs
for filename in os.listdir("./cogs/api"):
if filename.endswith(".py"):
total += 1
cog = f"cogs.api.{filename[:-3]}"
try:
client.load_extension(cog)
logging.info(f"Trying {cog}.....Success!")
2020-01-08 01:08:07 +00:00
except Exception as e:
logging.info(f"Trying {cog}.....Failed!")
logging.error(str(e))
2020-01-07 01:41:08 +00:00
failed += 1
logging.info("Finished loading cogs.")
logging.info(f"Total {total}, Failed {failed}\n")
logging. info("Deep Blue finished loading.")
2020-01-06 22:29:42 +00:00
2020-01-07 17:04:00 +00:00
2020-01-08 01:08:07 +00:00
key = config.settings["client_key"]
2020-01-07 01:41:08 +00:00
client.run(key)