-
Notifications
You must be signed in to change notification settings - Fork 5
/
bot.py
54 lines (43 loc) · 1.53 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
import discord
from discord.ext import commands
import os
import json
from datetime import datetime
from motor.motor_asyncio import AsyncIOMotorClient
from redis.client import Redis
import asyncio
async def get_prefix(bot, message):
guild_id = str(message.guild.id)
prefix_info = await bot.db.prefixes.find_one({'guild_id': guild_id})
prefix = '!?'
if prefix_info:
prefix = prefix_info['prefix']
else:
prefix_info = {
'guild_id': guild_id,
'prefix': prefix
}
await bot.db.prefixes.insert_one(prefix_info)
return commands.when_mentioned_or(prefix)(bot, message)
async def load_cogs(bot):
for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
await bot.load_extension(f'cogs.{filename[:-3]}')
async def main():
intents = discord.Intents.default()
bot = commands.Bot(command_prefix=get_prefix, intents=intents)
bot.launch_time = datetime.utcnow()
await load_cogs(bot)
with open('settings.json', 'r') as f:
settings = json.load(f)
token = settings['token']
bot.owner_id = settings['owner_id']
bot.leaderboards_api_url = settings['leaderboards_api_url']
motor_client = AsyncIOMotorClient(settings['mongo_uri'])
bot.db = motor_client['coa']
player_cache = Redis.from_url(settings['redis_url'], db=0)
max_page_cache = Redis.from_url(settings['redis_url'], db=1)
bot.player_cache = player_cache
bot.max_page_cache = max_page_cache
await bot.start(token)
asyncio.run(main())