This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.py
74 lines (66 loc) · 3.1 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from multiprocessing import Process
from sys import platform
import requests
import vk_api
from vk_api.bot_longpoll import VkBotEventType
import pendulum
from bot.Api import Vk
from bot.events.Events import MessagesDeny, MemberLeave, MemberJoin, Comment
from bot.messages.NewMessage import NewMessage
from bot.schedule.DisrtibuteSchedule import AutoDistribution
from bot.schedule.Updater import AutoUpdater
from bot.stuff.Config import Config as Config
from bot.stuff.Logging import GetMainLogger, GetCustomLogger
from bot.stuff import Utilities
from bot.stuff.Utilities import TZ
Vk = Vk()
Logger = GetMainLogger()
EventLogger = GetCustomLogger('EventLog', 'EventLog')
ExceptionLogger = GetCustomLogger('Exception', 'ExceptionLog')
def MainBot():
Logger.info(f'Бот запущен! Версия: {Config.VERSION}')
Logger.info('Старт прослушивания сервера!')
print('LongPooling started!')
Vk.ConsoleMessage(f'Бот запущен на платформе {platform}\nТекущая версия: {Config.VERSION}\nВремя: {pendulum.now()}')
Utilities.INIT_TIME = pendulum.now(TZ)
while True:
if not Config.DEBUGGING:
try:
for event in Vk.LongPool.listen():
try:
EventLogger.info(f'from: {event.obj.message["peer_id"]}; text: {event.obj.message["text"]};\n{event.obj.message}')
except Exception as e:
ExceptionLogger.warning(f'Exception {e} caused')
if event.type == VkBotEventType.MESSAGE_NEW:
try:
NewMessage(event)
except Exception as e:
print(e)
Vk.ConsoleMessage(f'Ошибка: {e} caused by {event.obj.message}')
Logger.warning('Exception!')
ExceptionLogger.warning(f'Exception {e} caused by {event.obj.message}')
elif event.type == VkBotEventType.MESSAGE_DENY:
MessagesDeny(event)
elif event.type == VkBotEventType.GROUP_JOIN:
MemberJoin(event)
elif event.type == VkBotEventType.GROUP_LEAVE:
MemberLeave(event)
elif event.type == VkBotEventType.WALL_REPLY_NEW:
Comment(event)
except requests.exceptions.ReadTimeout:
Vk.ConsoleMessage('LongPool перезапущен!')
Logger.warning('LongPool is restarted')
ExceptionLogger.warning('LongPool is restarted')
else:
for event in Vk.LongPool.listen():
print(event)
if event.type == VkBotEventType.MESSAGE_NEW:
NewMessage(event)
if __name__ == '__main__':
ListenProcess = Process(target=MainBot)
UpdateProcess = Process(target=AutoUpdater)
DistributeProcess = Process(target=AutoDistribution)
print('Initialization...')
ListenProcess.start()
UpdateProcess.start()
# DistributeProcess.start()