-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
58 lines (45 loc) · 1.08 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
import os
import signal
import asyncio
import setproctitle
import psutil
from bot import Bot
from omegaconf import OmegaConf
import nest_asyncio
nest_asyncio.apply()
bots = {}
profiles = {}
def load_profiles():
dir = os.listdir("profiles")
for file in dir:
profile_data = OmegaConf.load("profiles/" + file)
profile_name = file.removesuffix('.yml')
profiles[profile_name] = profile_data
def shutdown(loop):
for task in asyncio.Task.all_tasks():
task.cancel()
def is_process_running(name):
for process in psutil.process_iter(['name']):
if process.info['name'] == name:
return True
return False
async def main():
load_profiles()
loop = asyncio.get_event_loop()
for name, data in profiles.items():
bots[name] = Bot()
loop.create_task(bots[name].run(name, data))
try:
loop.run_forever()
except KeyboardInterrupt:
pass
finally:
print("closing bots...")
for name, bot in bots.items():
await bot.close()
if __name__ == "__main__":
if is_process_running('prymia'):
print("already running")
else:
setproctitle.setproctitle('prymia')
asyncio.run(main())