-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
78 lines (63 loc) · 2.25 KB
/
main.py
File metadata and controls
78 lines (63 loc) · 2.25 KB
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
from dotenv import find_dotenv, load_dotenv
load_dotenv(find_dotenv())
import asyncio
import os
import signal
from concurrent.futures import ProcessPoolExecutor
import bot.voicecreate as vc
import discord
from bot.cogs.lib.colors import Colors
from bot.cogs.lib.mongodb.migration_runner import MigrationRunner
from metrics.exporter import MetricsExporter
def sighandler(signum: int, frame):
match signum:
case signal.SIGTERM:
print(Colors.colorize(Colors.FGYELLOW, "<SIGTERM received>"))
case signal.SIGINT:
print(Colors.colorize(Colors.FGYELLOW, "<SIGINT received>"))
exit(0)
def main():
try:
migrations = MigrationRunner()
migrations.start_migrations()
DISCORD_TOKEN = os.environ.get("VCB_DISCORD_BOT_TOKEN", "")
if not DISCORD_TOKEN:
print(Colors.colorize(Colors.FGRED, "<VCB_DISCORD_BOT_TOKEN not set>"))
exit(1)
intents = discord.Intents.all()
intents.message_content = True
intents.members = True
intents.presences = True
intents.guilds = True
intents.guild_messages = True
intents.guild_reactions = True
voiceCreate = vc.VoiceCreate(intents=intents)
voiceCreate.remove_command('help')
voiceCreate.run(DISCORD_TOKEN)
except KeyboardInterrupt:
print(Colors.colorize(Colors.FGYELLOW, "<KeyboardInterrupt received>"))
exit(0)
def exporter():
try:
EXPORTER_ENABLED = os.environ.get("VCBE_CONFIG_METRICS_ENABLED", "false").lower() == "true"
if EXPORTER_ENABLED:
exporter = MetricsExporter()
exporter.run()
else:
print(Colors.colorize(Colors.FGYELLOW, "<Metrics exporter disabled>"))
except KeyboardInterrupt:
print(Colors.colorize(Colors.FGYELLOW, "<KeyboardInterrupt received>"))
exit(0)
if __name__ == '__main__':
loop = asyncio.get_event_loop()
try:
signal.signal(signal.SIGTERM, sighandler)
signal.signal(signal.SIGINT, sighandler)
executor = ProcessPoolExecutor(2)
loop.run_in_executor(executor, main)
loop.run_in_executor(executor, exporter)
loop.run_forever()
except KeyboardInterrupt:
pass
finally:
loop.close()