-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
86 lines (65 loc) · 2.13 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import asyncio
import json
import sys
import traceback
import discord
from discord.ext import commands, tasks
import sql
from creds import getDiscordAPIKeys
from errors import sendErrorMessage
try:
TOKEN = getDiscordAPIKeys()
except:
raise ValueError(
"You need to supply a creds.json file. Instructions can be found in the README.md file"
)
async def get_prefix(bot, message):
"""A callable Prefix for our bot. This could be edited to allow per server prefixes."""
# Notice how you can use spaces in prefixes. Try to keep them simple though.
prefixes = ["!ctf ", "?"]
# If we are in a guild, we allow for the user to mention us or use any of the prefixes in our list.
return commands.when_mentioned_or(*prefixes)(bot, message)
initial_extensions = [
"cogs.archive",
"cogs.ctf_setup_commands",
"cogs.ctf_utility_commands",
"cogs.owner_commands",
"cogs.ctftime_stats",
"cogs.solve_check",
"cogs.helpCog",
"cogs.misc_commands",
]
bot = commands.Bot(command_prefix=get_prefix, description="The cog enabled rewrite")
@bot.event
async def on_ready():
print(
f"\nLogged in as: {bot.user.name} - {bot.user.id}\nVersion: {discord.__version__}\n"
)
# Changes our bots Playing Status. type=1(streaming) for a standard game you could remove type and url.
print(f"Ready to Party.")
for guild in bot.guilds:
guild_in_db = await sql.db.getGuildByID(guild.id)
if guild_in_db == None:
print("GUILD ERROR: " + str(guild.id))
await sql.db.addGuild(guild.id, guild.name)
print("GUILD " + str(guild.id) + " added to DB")
@bot.event
async def on_guild_join(guild):
await sql.db.addGuild(guild.id, guild.name)
@bot.event
async def on_command_error(ctx, errormsg):
"""The event triggered when an error is raised while invoking a command.
ctx : Context
error : Exception"""
error = sendErrorMessage(ctx)
print(errormsg)
await error.sendError("E_GENERIC")
if __name__ == "__main__":
sql.init()
async_loop = asyncio.get_event_loop()
async_loop.create_task(sql.db.createPool(async_loop))
print("SQL DB STARTED")
bot.remove_command("help")
for extension in initial_extensions:
bot.load_extension(extension)
bot.run(TOKEN, bot=True)