-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
30 lines (27 loc) · 1.01 KB
/
run.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
from server.app import ServerWrapper
from bot.controller.base_controller import BaseController
from telegram.ext import Updater
from config import BotConfig
from telegram.ext import Defaults
from threading import Thread
from queue import Queue
# Enable debug logging
import logging
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
if __name__ == '__main__':
# Main thread here
# Queue to communicate with server and bot threads
q = Queue()
# Server here
server_wrapper = ServerWrapper(q)
sThread = Thread(target=server_wrapper.run, args=(), name="Server Thread")
sThread.start()
# Bot here
defaults = Defaults(parse_mode="HTML")
updater = Updater(BotConfig.API_TOKEN, use_context=True, defaults=defaults)
dispatcher = updater.dispatcher
base_controller = BaseController(dispatcher, q)
base_controller.start()
bThread = Thread(target=updater.start_polling, args=(), name="Bot Thread")
bThread.start()