forked from TechUni2020/TechUniBOT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtechunibot.py
45 lines (35 loc) · 1.33 KB
/
techunibot.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
import os
import asyncio
from multiprocessing import Process, Queue
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from techuni.techuni_discord import TechUniDiscordBot
from techuni.techuni_socket import SocketServer
from techuni.techuni_database.schema import JoinApplicationTable
from techuni.techuni_database import DatabaseSession
def socket_main(queue):
TechUniDiscordBot.socket_applier = queue
socket_s = SocketServer("localhost", int(os.environ.get("SOCKET_PORT")))
asyncio.run(socket_s.start())
def main():
# Database
database_engine = create_engine(str(os.environ.get("DATABASE_URL")), echo=False)
session_factory = sessionmaker(bind=database_engine, autoflush=True, autocommit=False)
## init database
JoinApplicationTable.metadata.create_all(database_engine)
database_session = DatabaseSession(session_factory())
# Socket
socket_queue = Queue()
TechUniDiscordBot.socket_applier = socket_queue
# Discord BOT
bot = TechUniDiscordBot(database_session)
# --- Process Start --- #
# Socket
socket_process = Process(target=socket_main, args=(socket_queue,))
socket_process.start()
# Discord BOT
bot.run(str(os.environ.get("DISCORD_BOT_TOKEN")))
socket_process.join()
database_session.close()
if __name__ == "__main__":
main()