-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbot.py
98 lines (79 loc) · 2.42 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Std Lib Imports
import sys
import asyncio
import signal
# 3rd Party Imports
from discord.ext import commands
import discord
from tortoise import Tortoise
# Local Imports
from cogs import *
from utils import load_config, EmbedHelpCommand, setup_logger
config = load_config()
setup_logger(config.log_level)
def main():
intents = discord.Intents.default()
intents.message_content = True
intents.members = True
bot = commands.Bot(command_prefix=config.bot_prefix, intents=intents)
bot.help_command = EmbedHelpCommand()
# Load Plugins
bot.add_cog(Search())
bot.add_cog(Tags())
bot.add_cog(MapList())
bot.add_cog(Servers(bot))
bot.add_cog(VIP())
bot.add_cog(Misc(bot))
bot.add_cog(Verification(bot))
#bot.add_cog(Hosts())
bot.add_cog(SearchUsers(bot))
bot.add_cog(Release(bot))
# Setup Asyncio Loop
bot.loop.add_signal_handler(signal.SIGINT, lambda: bot.loop.stop())
bot.loop.add_signal_handler(signal.SIGTERM, lambda: bot.loop.stop())
future = asyncio.ensure_future(start(bot, config.bot_token), loop=bot.loop)
future.add_done_callback(lambda f: bot.loop.stop())
try:
bot.loop.run_forever()
except KeyboardInterrupt:
pass
finally:
future.remove_done_callback(bot.loop.stop)
discord.client._cleanup_loop(bot.loop)
async def start(bot, token):
await init_db()
try:
await bot.start(token)
finally:
if not bot.is_closed:
await bot.close()
async def init_db():
await Tortoise.init(
{
"connections": {
"tags": config.databases.tags,
"starboard": config.databases.starboard,
"tf2maps_bot": config.databases.tf2maps_bot,
"tf2maps_site": config.databases.tf2maps_site
},
"apps": {
"tags": {
"models": ["models.Tag"],
"default_connection": "tags"
},
"maplist": {
"models": ["models.Maps"],
"default_connection": "tf2maps_bot"
},
"starboard": {
"models": ["models.Starboard"],
"default_connection": "starboard"
}
}
}
)
# await Tortoise.generate_schemas()
async def close():
await Tortoise.close_connections()
if __name__ == "__main__":
main()