-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathservstatsbot.py
54 lines (46 loc) · 1.34 KB
/
servstatsbot.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
# -*- coding: utf-8 -*-
import asyncio
from multiprocessing import Process
import os
import telepot
from telepot.aio.loop import MessageLoop
from telepot.aio.delegate import pave_event_space, per_chat_id, create_open
from botTools import BotTools
# bot tools
from botData import BotData
from botConfig import BotConfig
# Message handler
from mainMessageHandler import MainMessageHandler
from routine import Routine
TIMEOUT = 20 * 60
if __name__ == "__main__":
# Get proc id
pid = os.getpid()
op = open(os.path.dirname(os.path.abspath(__file__)) + "/ssb.pid", "w")
op.write(str(pid))
op.close()
# Init config
config = BotConfig(os.path.dirname(os.path.abspath(__file__))
+ "/settings.ini")
config.loadSettings()
data = BotData()
tools = BotTools(config, data)
# Run Bot
bot = telepot.aio.DelegatorBot(config.TOKEN, [
pave_event_space()(
per_chat_id(), create_open,
MainMessageHandler, config, data, tools,
timeout=TIMEOUT
)
])
monitoring = Routine(config, data, tools)
process = Process(
target=monitoring.routine,
daemon=True
)
process.start()
# Message Handler
loop = asyncio.get_event_loop()
loop.create_task(MessageLoop(bot).run_forever())
print('Listening ...')
loop.run_forever()