-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
80 lines (61 loc) · 2.48 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
import os
import json
import motor.motor_asyncio as motor
import discord
from discord.ext import commands
database_password = os.environ.get("DATABASE_PASSWORD")
db_client = motor.AsyncIOMotorClient(database_password)
db = db_client["ap-students"]
config_file = open('config.json')
config = json.load(config_file)
class APBot(commands.Bot):
def __init__(self):
super().__init__(
command_prefix=config["command_prefix"],
intents=discord.Intents.all(),
application_id=config["application_id"],
)
async def setup_hook(self) -> None:
initial_extensions = ['cogs.errorhandler',
'cogs.events',
'cogs.meta',
'cogs.moderation.appeal',
'cogs.moderation.commands',
'cogs.moderation.decay',
'cogs.modmail',
'cogs.rolereact',
'cogs.study',
# 'cogs.threads',
]
for extension in initial_extensions:
await self.load_extension(extension)
await bot.tree.sync(guild=discord.Object(id=config["guild_id"]))
async def on_ready(self):
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.playing, name="DM me to contact mods!"))
print(f'Joined: {bot.user}')
async def read_user_config(self, user_id: int):
config_from_db = await db["user_config"].find_one({"user_id": user_id})
if config_from_db is None:
config_from_db = {
"user_id": user_id,
"infraction_points": 0,
"infractions": []
}
await db["user_config"].insert_one(config_from_db)
return config_from_db
async def update_user_config(self, user_id: int, new_config):
old_config = await db["user_config"].find_one({"user_id": user_id})
if old_config is None:
config = {
"user_id": user_id,
"infraction_points": 0,
"infractions": []
}
old_config = await db["user_config"].insert_one(config)
_id = old_config['_id']
await db["user_config"].replace_one({"_id": _id}, new_config)
bot = APBot()
bot.guild_id = config["guild_id"]
bot.user_config = db["user_config"]
token = os.environ.get("DISCORD_BOT_SECRET")
bot.run(token)