-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
69 lines (56 loc) · 2.38 KB
/
bot.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
import json
from datetime import datetime
import discord
from discord import Activity, ActivityType, Intents, Status
from config import token
from utilities.database import modifyData, mysql_login, selector
intents = Intents(guilds=True)
bot = discord.Bot(intents=intents, status=Status.dnd,
activity=Activity(type=ActivityType.watching, name="you"))
bot.load_extensions("cogs") # Loads all cogs in the cogs folder
bot.load_extensions("cogs.events")
print(bot.extensions)
BOOTED = False
@bot.listen()
async def on_connect():
print('Connected to Discord!')
print('Connecting to database')
cursor = await mysql_login()
database = cursor.cursor()
print('Connected to database\nCreating the required tables if necessary')
database.execute("CREATE TABLE IF NOT EXISTS settings (GUILD VARCHAR(20) PRIMARY KEY, config JSON)")
database.execute("CREATE TABLE IF NOT EXISTS economy (UID VARCHAR(20) PRIMARY KEY, CASH FLOAT SIGNED, BANK FLOAT SIGNED)")
database.execute("CREATE TABLE IF NOT EXISTS cooldowns (UID VARCHAR(20) PRIMARY KEY, command VARCHAR(20), cooldown INT)")
print('Tables have been created')
database.close()
@bot.listen()
async def on_ready():
global BOOTED
if BOOTED:
print("Reconnect(?)")
if not BOOTED:
# await bot.sync_commands() #You might need to uncomment this if the slash commands aren't appearing
print(f'Logged in as {bot.user}')
print('------')
BOOTED = True
@bot.check
async def guild_only(ctx):
return ctx.guild is not None
@bot.check
async def block_disabled_commands(ctx):
result = await selector("SELECT config FROM settings WHERE GUILD = %s", [ctx.guild.id])
if result == ():
configuration = {'currency': True, 'socials': True}
configuration = json.dumps(configuration)
await modifyData("INSERT INTO settings (GUILD, config) VALUES (%s, %s)", [ctx.guild.id, configuration])
print(f"{datetime.now().__format__('%a %d %b %y, %H:%M:%S')} - Corrected guild absence in settings upon command execution.")
result = (await selector("SELECT config FROM settings WHERE GUILD = %s", [ctx.guild.id]))[0]
result = json.loads(result)
cog = ctx.cog.__class__.__name__
if cog.lower() not in result:
return True
elif cog.lower() in result and result[cog.lower()]:
return True
else:
return False
bot.run(token)