This repository has been archived by the owner on Oct 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
80 lines (62 loc) · 2.39 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
70
71
72
73
74
75
76
77
78
79
80
"""Overriding commands.Bot"""
import discord
import logging
from typing import *
from discord.ext import commands
from utils.database import CursorDB
from utils.config import DockerConfig
log = logging.getLogger(__name__)
config = DockerConfig("config.ini")
EXTENSIONS = (
"cogs.resolve",
"cogs.download",
"cogs.role",
"cogs.token",
# "cogs.moderator",
"cogs.upload",
"cogs.renderer",
"cogs.scene",
# "cogs.log"
)
commands.MinimalHelpCommand()
class Bot(commands.Bot, CursorDB):
"""
Primary class that contains the bot object to run
"""
def __init__(self):
self.bot_options = {}
self._get_options()
super().__init__(**self.bot_options)
CursorDB.__init__(self)
for extension in EXTENSIONS:
# try:
self.load_extension(extension)
log.info(f"Loaded the extension {extension}")
# except:
# log.warning(f"Failed to load the extension {extension}")
def _get_options(self):
for k, v in config.items("BOT"):
k = k.lower()
if (v):
self.bot_options[k] = eval(v)
async def on_ready(self):
log.info(f"Logged in as {self.user} (ID: {self.user.id})")
await self.change_presence(activity=discord.Game(name = "skins.tw"))
async def close(self):
log.critical("Closing")
await self.close()
async def on_command(self, ctx: commands.Context):
dest = [f"#{ctx.channel} ({ctx.guild})", "DM"][not ctx.guild]
log.info(f"{ctx.author} used command in {dest}: {ctx.message.content}")
name = ctx.command.name
self.execute(f"""INSERT INTO command_stat (guild_id, name)
VALUES({ctx.guild.id}, '{name}')
ON DUPLICATE KEY
UPDATE count = count + 1""")
async def on_guild_join(self, guild: discord.Guild):
log.warning(f"{self.user} (ID: {self.user.id}) has joined {guild.name} (ID: {guild.id})")
self.execute(f"""INSERT INTO guild_log_permission (guild_id) VALUES({guild.id})""")
self.execute(f"""INSERT INTO guild_log_channel (guild_id) VALUES({guild.id})""")
async def on_guild_remove(self, guild: discord.Guild):
log.warning(f"{self.user} (ID: {self.user.id}) has left {guild.name} (ID: {guild.id})")
self.execute(f"""DELETE FROM guild_log_permission WHERE guild_id={guild.id}""")