pythonbot/dan63047bot.py

495 lines
24 KiB
Python
Raw Normal View History

2020-04-04 16:07:39 +00:00
import vk_api
import datetime
2020-04-11 14:40:25 +00:00
import time
2020-04-04 16:07:39 +00:00
import requests
2020-04-04 21:18:12 +00:00
import logging
2020-04-05 14:41:33 +00:00
import pyowm
2020-04-05 22:46:06 +00:00
import random
2020-04-07 16:00:49 +00:00
import json
2020-05-08 19:30:43 +00:00
import threading
2020-04-06 10:26:50 +00:00
import wikipediaapi as wiki
2020-05-05 21:33:56 +00:00
from collections import deque
2020-05-04 20:26:22 +00:00
from config import vk, owm, vk_mda, group_id, album_for_command, owner_id
2020-04-11 21:50:14 +00:00
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
2020-05-04 20:26:22 +00:00
bot = {}
users = {}
2020-05-04 20:26:22 +00:00
debug_array = {'vk_warnings': 0, 'logger_warnings': 0, 'start_time': 0, 'messages_get': 0, 'messages_answered': 0}
2020-04-13 18:25:48 +00:00
root_logger = logging.getLogger()
2020-04-11 21:50:14 +00:00
root_logger.setLevel(logging.INFO)
handler = logging.FileHandler('bot.log', 'w', 'utf-8')
2020-05-05 21:33:56 +00:00
handler.setFormatter(logging.Formatter('[%(asctime)s][%(levelname)s] %(message)s'))
2020-04-11 21:50:14 +00:00
root_logger.addHandler(handler)
longpoll = VkBotLongPoll(vk, group_id)
2020-04-13 18:25:48 +00:00
def update_users_json(massive):
with open("users.json", 'w') as write_file:
data = massive
json.dump(data, write_file)
write_file.close()
def load_users():
try:
with open("users.json", 'r') as users_file:
users_not_json = json.load(users_file)
for i in users_not_json:
users[i] = users_not_json[i]
users_file.close()
for i in users:
bot[int(i)] = VkBot(i, users[i]["midnight"])
except Exception as lol:
log(True, f"Проблема с загрузкой users.json: {str(lol)}")
2020-04-27 11:48:20 +00:00
def log(warning, text):
if warning:
logging.warning(text)
2020-05-04 20:26:22 +00:00
debug_array['logger_warnings'] += 1
2020-05-05 21:33:56 +00:00
print("[" + time.strftime("%d.%m.%Y %H:%M:%S", time.gmtime()) + "][WARNING] " + text)
2020-04-27 11:48:20 +00:00
else:
logging.info(text)
print("[" + time.strftime("%d.%m.%Y %H:%M:%S", time.gmtime()) + "] " + text)
2020-04-13 18:25:48 +00:00
def toFixed(numObj, digits=0):
return f"{numObj:.{digits}f}"
2020-04-11 21:50:14 +00:00
class MyVkLongPoll(VkBotLongPoll):
def listen(self):
while True:
2020-04-13 18:25:48 +00:00
try:
2020-04-11 21:50:14 +00:00
for event in self.check():
yield event
except Exception as e:
2020-04-27 11:48:20 +00:00
err = "Беды с ВК: " + str(e)
log(True, err)
2020-05-04 20:26:22 +00:00
debug_array['vk_warnings'] += 1
2020-04-11 21:50:14 +00:00
time.sleep(15)
continue
2020-04-04 16:07:39 +00:00
2020-04-13 18:25:48 +00:00
def get_weather(place):
try:
weather_request = owm.weather_at_place(place)
except pyowm.exceptions.api_response_error.NotFoundError as i:
2020-04-27 11:48:20 +00:00
err = "Ошибка OpenWeather API: " + str(i)
log(True, err)
2020-04-13 18:25:48 +00:00
return "Такого города нет, либо данных о погоде нет"
weather_answer = weather_request.get_weather()
2020-04-27 11:48:20 +00:00
info = "Результат поиска погоды через OpenWeather API: " + str(weather_answer)
log(False, info)
2020-04-13 18:25:48 +00:00
return "В городе " + place + " сейчас " + weather_answer.get_detailed_status() + ", " + str(
round(weather_answer.get_temperature('celsius')['temp'])) + "°C"
2020-04-03 21:18:34 +00:00
class VkBot:
2020-04-03 19:56:57 +00:00
def __init__(self, peer_id, midnight=False):
2020-04-04 16:07:39 +00:00
2020-04-27 11:48:20 +00:00
log(False, f"Создан объект бота! id{peer_id}")
2020-04-05 16:24:24 +00:00
self._CHAT_ID = peer_id
2020-04-12 09:47:30 +00:00
self._ECHO_MODE = False
2020-05-11 18:24:34 +00:00
self._ACCESS_LEVEL = 1
if midnight:
self._MIDNIGHT_EVENT = True
else:
self._MIDNIGHT_EVENT = False
2020-04-03 19:56:57 +00:00
2020-05-11 18:24:34 +00:00
if int(self._CHAT_ID) == int(owner_id):
2020-05-04 20:26:22 +00:00
self._OWNER = True
else:
self._OWNER = False
2020-04-13 18:25:48 +00:00
self._COMMANDS = ["!image", "!my_id", "!h", "!user_id", "!group_id", "!help", "!weather", "!wiki", "!byn",
2020-05-11 18:24:34 +00:00
"!echo", "!game", "!debug", "!midnight", "!access"]
2020-04-04 16:07:39 +00:00
2020-05-08 19:30:43 +00:00
def event(self, event):
if event == "midnight" and self._MIDNIGHT_EVENT:
current_time = datetime.datetime.fromtimestamp(time.time() + 10800)
2020-05-12 09:18:46 +00:00
image = None
2020-05-09 21:46:09 +00:00
midnight_text = ["Мидннайт!", "Полночь!", "Midnight!", "миднигхт", "Середина ночи", "Смена даты!"]
midnight_after = ["Ложись спать!", "P E A C E A N D T R A N Q U I L I T Y", "Поиграй в майнкрафт",
2020-05-12 09:18:46 +00:00
"Втыкай в ВК дальше", "hat in time is gay", "R34 по ахиту это смертный грех", "Egg",
"вещ или бан", "Мой ник в игре _ичё"]
2020-05-09 21:46:09 +00:00
midnight_output = random.choice(midnight_text) + "<br>" + f"Наступило {current_time.strftime('%d.%m.%Y')}<br><br>"
2020-05-11 18:24:34 +00:00
random_thing = random.randint(0, 2)
if random_thing == 0:
2020-05-09 21:46:09 +00:00
midnight_output += random.choice(midnight_after)
2020-05-11 18:24:34 +00:00
elif random_thing == 1:
2020-05-12 09:18:46 +00:00
midnight_output += "Картинка дня:"
image = self.random_image()
2020-05-11 18:24:34 +00:00
elif random_thing == 2:
midnight_output += "Цвет дня в формате HEX: #%02x%02x%02x" % (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
2020-05-09 21:46:09 +00:00
self.send(midnight_output)
2020-05-12 09:18:46 +00:00
log(False, f"Бот id{self._CHAT_ID} оповестил о миднайте", image)
2020-05-08 19:30:43 +00:00
2020-05-11 18:24:34 +00:00
def get_message(self, message, user_id):
2020-04-12 09:47:30 +00:00
if self._ECHO_MODE:
if message == "!echo off":
2020-05-08 19:30:43 +00:00
self.send(message)
2020-04-12 09:47:30 +00:00
self._ECHO_MODE = False
2020-04-27 11:48:20 +00:00
log(False, f"Бот id{self._CHAT_ID} вышел из режима эхо")
2020-05-08 19:30:43 +00:00
debug_array['messages_answered'] += 1
2020-04-12 09:47:30 +00:00
else:
2020-05-08 19:30:43 +00:00
self.send(message)
2020-04-27 11:48:20 +00:00
log(False, f"Эхо-бот id{self._CHAT_ID}: {message}")
2020-05-08 19:30:43 +00:00
debug_array['messages_answered'] += 1
2020-04-12 09:47:30 +00:00
else:
2020-05-08 19:30:43 +00:00
respond = {'attachment': None, 'text': None}
message = message.split(' ', 1)
if message[0] == self._COMMANDS[0]:
respond['attachment'] = self.random_image()
elif message[0] == self._COMMANDS[1]:
respond['text'] = "Ваш ид: " + str(self._CHAT_ID)
2020-05-08 19:30:43 +00:00
elif message[0] == self._COMMANDS[2] or message[0] == self._COMMANDS[5]:
respond[
2020-05-10 09:39:15 +00:00
'text'] = "Я бот, призванный доставлять неудобства. <br>Команды:<br>!my_id - сообщит ваш id в ВК<br>!user_id *id* - сообщит информацию о этом пользователе<br>!group_id *id* - сообщит информацию о этой группе<br>!image - отправляет рандомную картинку из альбома<br>!weather *город* - отправляет текущую погоду в городе (данные из OpenWeather API)<br>!wiki *запрос* - отправляет информацию об этом из Wikipedia<br>!byn - отправляет текущий курс валют, полученный из API НБ РБ<br>!echo - бот отправляет вам всё, что вы ему пишите<br>!game *камень/ножницы/бумага/статистика* - бот будет играть с вами в \"Камень, ножницы, бумага\" и записывать статистику<br>!midnight - бот будет уведомлять вас о 00:00 по Москве. Отправьте ещё раз, чтобы бот больше вас не уведомлял<br>!h, !help - справка<br>Дата последнего обновления: 10.05.2020 (обновление команды !midnight)<br>Проект бота на GitHub: https://github.com/dan63047/dan63047pythonbot"
2020-05-08 19:30:43 +00:00
elif message[0] == self._COMMANDS[3]:
try:
respond['text'] = self.get_info_user(message[1])
except IndexError:
respond['text'] = "Отсуствует аргумент"
elif message[0] == self._COMMANDS[4]:
try:
respond['text'] = self.get_info_group(message[1])
except IndexError:
respond['text'] = "Отсуствует аргумент"
elif message[0] == self._COMMANDS[6]:
try:
respond['text'] = get_weather(message[1])
except IndexError:
respond['text'] = "Отсуствует аргумент"
elif message[0] == self._COMMANDS[7]:
try:
respond['text'] = self.wiki_article(message[1])
except IndexError:
respond['text'] = "Отсуствует аргумент"
elif message[0] == self._COMMANDS[8]:
respond['text'] = self.exchange_rates()
elif message[0] == self._COMMANDS[9]:
vk.method('messages.send', {'peer_id': self._CHAT_ID,
'message': "Теперь бот работает в режиме эхо. Чтобы"
" это выключить, введить \"!echo off\"",
'random_id': time.time()})
self._ECHO_MODE = True
log(False, f"Бот id{self._CHAT_ID} в режиме эхо")
elif message[0] == self._COMMANDS[10]:
try:
message[1] = message[1].lower()
respond['text'] = self.game(message[1])
except IndexError:
respond['text'] = "Отсуствует аргумент"
elif message[0] == self._COMMANDS[11]:
2020-05-11 18:24:34 +00:00
if self._ACCESS_LEVEL or int(user_id) == int(owner_id):
try:
respond['text'] = self.debug(message[1])
except IndexError:
respond['text'] = self.debug()
else:
respond["text"] = "Отказано в доступе"
2020-05-08 19:30:43 +00:00
elif message[0] == self._COMMANDS[12]:
2020-05-11 18:24:34 +00:00
if self._ACCESS_LEVEL or int(user_id) == int(owner_id):
if self._MIDNIGHT_EVENT:
self._MIDNIGHT_EVENT = False
self.send("Уведомление о миднайте выключено")
log(False, f"Бот id{self._CHAT_ID}: Юзер отписался от ивента \"Миднайт\"")
else:
self._MIDNIGHT_EVENT = True
self.send("Бот будет уведомлять вас о каждом миднайте")
log(False, f"Бот id{self._CHAT_ID}: Юзер подписался на ивент \"Миднайт\"")
users[self._CHAT_ID]["midnight"] = self._MIDNIGHT_EVENT
update_users_json(users)
else:
respond['text'] = "Отказано в доступе"
elif message[0] == self._COMMANDS[13]:
if int(user_id) == int(owner_id):
try:
if message[1] == "owner":
respond['text'] = "Теперь некоторыми командами может пользоваться только владелец бота"
self._ACCESS_LEVEL = 0
elif message[1] == "all":
respond['text'] = "Теперь все могут пользоваться всеми командами"
self._ACCESS_LEVEL = 1
else:
respond['text'] = "Некорректный аргумент"
except IndexError:
respond['text'] = "Отсуствует аргумент"
2020-05-08 19:30:43 +00:00
else:
2020-05-11 18:24:34 +00:00
respond['text'] = "Отказано в доступе"
2020-05-08 19:30:43 +00:00
if respond['text'] or respond['attachment']:
self.send(respond['text'], respond['attachment'])
debug_array['messages_answered'] += 1
def debug(self, arg=None):
if arg == "log":
if self._OWNER:
with open("bot.log", 'r') as f:
log = list(deque(f, 10))
text_log = "<br>Последние 10 строк из лога:<br>"
for i in range(len(log)):
text_log += log[i]
f.close()
return text_log
else:
return "Отказано в доступе"
else:
up_time = time.time() - debug_array['start_time']
time_d = int(up_time) / (3600 * 24)
time_h = int(up_time) / 3600 - int(time_d) * 24
time_min = int(up_time) / 60 - int(time_h) * 60 - int(time_d) * 24 * 60
time_sec = int(up_time) - int(time_min) * 60 - int(time_h) * 3600 - int(time_d) * 24 * 60 * 60
str_up_time = '%01d:%02d:%02d:%02d' % (time_d, time_h, time_min, time_sec)
datetime_time = datetime.datetime.fromtimestamp(debug_array['start_time'])
answer = "UPTIME: " + str_up_time + "<br>Прослушано сообщений: " + str(
debug_array['messages_get']) + " (Отвечено на " + str(
debug_array['messages_answered']) + ")<br>Ошибок в работе: " + str(
debug_array['logger_warnings']) + " (Из них беды с ВК: " + str(debug_array['vk_warnings']) + ")<br>Обьектов бота: " + str(len(bot)) + "<br>Запуск бота по часам сервера: " + datetime_time.strftime('%d.%m.%Y %H:%M:%S UTC')
return answer
2020-05-04 20:26:22 +00:00
2020-04-13 18:25:48 +00:00
def game(self, thing):
if thing == "статистика":
with open("data_file.json", "r") as read_file:
data = json.load(read_file)
if str(self._CHAT_ID) in data:
winrate = (data[str(self._CHAT_ID)]['wins'] / data[str(self._CHAT_ID)]['games']) * 100
return f"Камень, ножницы, бумага<br>Сыграно игр: {data[str(self._CHAT_ID)]['games']}<br>Из них:<br>•Побед: {data[str(self._CHAT_ID)]['wins']}<br>•Поражений: {data[str(self._CHAT_ID)]['defeats']}<br>•Ничей: {data[str(self._CHAT_ID)]['draws']}<br>Процент побед: {toFixed(winrate, 2)}%"
2020-04-13 18:25:48 +00:00
else:
return "Похоже, вы ещё никогда не играли в Камень, ножницы, бумага"
elif thing == "камень" or thing == "ножницы" or thing == "бумага":
things = ["камень", "ножницы", "бумага"]
bot_thing = random.choice(things)
if thing == "камень" and bot_thing == "ножницы":
result = 2
elif thing == "ножницы" and bot_thing == "бумага":
result = 2
elif thing == "бумага" and bot_thing == "камень":
result = 2
elif thing == "ножницы" and bot_thing == "камень":
result = 1
elif thing == "бумага" and bot_thing == "ножницы":
result = 1
elif thing == "камень" and bot_thing == "бумага":
result = 2
elif thing == "камень" and bot_thing == "камень":
result = 0
elif thing == "ножницы" and bot_thing == "ножницы":
result = 0
elif thing == "бумага" and bot_thing == "бумага":
result = 0
if result == 2:
response = f"Камень, ножницы, бумага<br>{thing} vs. {bot_thing}<br>Вы выиграли!"
elif result == 1:
response = f"Камень, ножницы, бумага<br>{thing} vs. {bot_thing}<br>Вы проиграли!"
elif result == 0:
response = f"Камень, ножницы, бумага<br>{thing} vs. {bot_thing}<br>Ничья!"
with open("data_file.json", 'r') as write_file:
try:
data = json.load(write_file)
except Exception:
data = {}
if str(self._CHAT_ID) not in data:
data[str(self._CHAT_ID)] = {}
data[str(self._CHAT_ID)]["games"] = 0
data[str(self._CHAT_ID)]["wins"] = 0
data[str(self._CHAT_ID)]["defeats"] = 0
data[str(self._CHAT_ID)]["draws"] = 0
2020-04-13 18:25:48 +00:00
if result == 2:
data[str(self._CHAT_ID)]["games"] += 1
data[str(self._CHAT_ID)]["wins"] += 1
2020-04-13 18:25:48 +00:00
elif result == 1:
data[str(self._CHAT_ID)]["games"] += 1
data[str(self._CHAT_ID)]["defeats"] += 1
2020-04-13 18:25:48 +00:00
elif result == 0:
data[str(self._CHAT_ID)]["games"] += 1
data[str(self._CHAT_ID)]["draws"] += 1
2020-04-13 18:25:48 +00:00
with open("data_file.json", "w") as write_file:
json.dump(data, write_file)
return response
else:
return "Неверный аргумент<br>Использование команды:<br>!game *камень/ножницы/бумага/статистика*"
2020-04-05 14:41:33 +00:00
2020-04-04 16:07:39 +00:00
def get_info_user(self, id):
try:
user_info = vk.method('users.get', {'user_ids': id, 'fields': 'verified,last_seen,sex'})
except vk_api.exceptions.ApiError as lol:
2020-04-27 11:48:20 +00:00
err = "Ошибка метода users.get: " + str(lol)
log(True, err)
2020-04-13 18:25:48 +00:00
return "Пользователь не найден<br>" + str(lol)
2020-04-15 10:45:05 +00:00
if "deactivated" in user_info[0]:
if user_info[0]['deactivated'] == 'banned':
return user_info[0]['first_name'] + " " + user_info[0]['last_name'] + " забанен"
elif user_info[0]['deactivated'] == 'deleted':
return "Профиль был удалён"
2020-04-15 10:36:12 +00:00
2020-04-04 16:07:39 +00:00
if user_info[0]['is_closed']:
is_closed = "Да"
else:
is_closed = "Нет"
if user_info[0]['sex'] == 1:
sex = "Женский"
elif user_info[0]['sex'] == 2:
sex = "Мужской"
else:
sex = "Неизвестно"
if user_info[0]['last_seen']['platform'] == 1:
platform = "m.vk.com"
elif user_info[0]['last_seen']['platform'] == 2:
platform = "iPhone"
elif user_info[0]['last_seen']['platform'] == 3:
platform = "iPad"
elif user_info[0]['last_seen']['platform'] == 4:
platform = "Android"
elif user_info[0]['last_seen']['platform'] == 5:
platform = "Windows Phone"
elif user_info[0]['last_seen']['platform'] == 6:
platform = "Windows 10"
elif user_info[0]['last_seen']['platform'] == 7:
platform = "vk.com"
else:
platform = "тип платформы неизвестен"
time = datetime.datetime.fromtimestamp(user_info[0]['last_seen']['time'])
2020-04-27 11:48:20 +00:00
answer = user_info[0]['first_name'] + " " + user_info[0]['last_name'] + "<br>Его ид: " + \
str(user_info[0]['id']) + "<br>Профиль закрыт: " + is_closed + "<br>Пол: " + sex \
+ "<br>Последний онлайн: " + time.strftime('%d.%m.%Y в %H:%M:%S') + " (" + platform + ")"
2020-04-04 16:07:39 +00:00
return answer
def get_info_group(self, id):
try:
group_info = vk.method('groups.getById', {'group_id': id, 'fields': 'description,members_count'})
except vk_api.exceptions.ApiError as lol:
2020-04-27 11:48:20 +00:00
err = "Ошибка метода groups.getById: " + str(lol)
log(True, err)
2020-04-13 18:25:48 +00:00
return "Группа не найдена<br>" + str(lol)
2020-04-27 11:48:20 +00:00
info = "Результат метода API groups.getById: " + str(group_info)
log(False, info)
2020-04-04 16:07:39 +00:00
if group_info[0]['description'] == "":
description = "Отсутствует"
else:
description = group_info[0]['description']
2020-04-13 18:25:48 +00:00
answer = group_info[0]['name'] + "<br>Описание: " + description + "<br>Ид группы: " + str(
group_info[0]['id']) + "<br>Подписчиков: " + str(group_info[0]['members_count'])
2020-04-04 16:07:39 +00:00
return answer
2020-04-03 19:56:57 +00:00
2020-04-05 22:46:06 +00:00
def random_image(self):
2020-05-05 21:33:56 +00:00
group = "-" + str(group_id)
2020-04-13 18:25:48 +00:00
random_images_query = vk_mda.method('photos.get',
2020-05-04 20:26:22 +00:00
{'owner_id': group, 'album_id': album_for_command, 'count': 1000})
2020-04-27 11:48:20 +00:00
info = "Результат метода photos.get: Получено " + str(random_images_query['count']) + " фото"
log(False, info)
2020-04-06 10:26:50 +00:00
random_number = random.randrange(random_images_query['count'])
2020-04-13 18:25:48 +00:00
return "photo" + str(random_images_query['items'][random_number]['owner_id']) + "_" + str(
random_images_query['items'][random_number]['id'])
2020-04-05 22:46:06 +00:00
2020-04-06 10:26:50 +00:00
def wiki_article(self, search):
w = wiki.Wikipedia('ru')
page = w.page(search)
if page.exists():
2020-04-13 18:25:48 +00:00
answer = page.title + "<br>" + page.summary
2020-04-06 10:26:50 +00:00
else:
answer = "Такой статьи не существует"
return answer
2020-05-08 19:30:43 +00:00
def exchange_rates(self):
2020-04-10 16:06:15 +00:00
try:
2020-04-13 18:25:48 +00:00
rates_USD = json.loads(
requests.get("https://www.nbrb.by/api/exrates/rates/145?periodicity=0", timeout=10).text)
rates_EUR = json.loads(
requests.get("https://www.nbrb.by/api/exrates/rates/292?periodicity=0", timeout=10).text)
rates_RUB = json.loads(
requests.get("https://www.nbrb.by/api/exrates/rates/298?periodicity=0", timeout=10).text)
return "Текущий курс валют по данным НБ РБ:<br>" + rates_USD['Cur_Name'] + ": " + str(
rates_USD['Cur_Scale']) + " " + rates_USD['Cur_Abbreviation'] + " = " + str(
rates_USD['Cur_OfficialRate']) + " BYN<br>" + rates_EUR['Cur_Name'] + ": " + str(
rates_EUR['Cur_Scale']) + " " + rates_EUR['Cur_Abbreviation'] + " = " + str(
rates_EUR['Cur_OfficialRate']) + " BYN<br>" + "Российский рубль" + ": " + str(
rates_RUB['Cur_Scale']) + " " + rates_RUB['Cur_Abbreviation'] + " = " + str(
rates_RUB['Cur_OfficialRate']) + " BYN"
2020-04-10 16:06:15 +00:00
except Exception as mda:
2020-04-27 11:48:20 +00:00
err = "Ошибка получения данных из НБ РБ API: " + str(mda)
log(True, err)
2020-04-13 18:25:48 +00:00
return "Невозможно получить данные из НБ РБ: " + str(mda)
2020-04-10 16:06:15 +00:00
2020-05-08 19:30:43 +00:00
def send(self, message=None, attachment=None):
message = vk.method('messages.send',
{'peer_id': self._CHAT_ID, 'message': message, 'random_id': time.time(),
'attachment': attachment})
log(False, f'Бот id{self._CHAT_ID}: Ответ метода ВК "messages.send": {message}')
2020-04-03 19:56:57 +00:00
2020-05-08 19:30:43 +00:00
def bots():
log(False, "Бот начал работу")
debug_array['start_time'] = time.time()
2020-04-11 21:50:14 +00:00
for event in MyVkLongPoll.listen(longpoll):
try:
if event.type == VkBotEventType.MESSAGE_NEW:
2020-05-08 19:30:43 +00:00
log(False, f'Новое сообщение: {event.message}')
2020-05-04 20:26:22 +00:00
debug_array['messages_get'] += 1
if int(event.message.peer_id) in bot:
2020-05-11 18:24:34 +00:00
bot[event.message.peer_id].get_message(event.message.text, event.message.from_id)
2020-04-11 21:50:14 +00:00
else:
bot[event.message.peer_id] = VkBot(event.message.peer_id)
users[event.message.peer_id] = {"midnight": False}
update_users_json(users)
2020-05-11 18:24:34 +00:00
bot[event.message.peer_id].get_message(event.message.text, event.message.from_id)
2020-04-11 21:50:14 +00:00
except Exception as kek:
2020-04-27 11:48:20 +00:00
err = "Беды с ботом: " + str(kek)
log(True, err)
2020-04-13 18:25:48 +00:00
continue
2020-04-11 21:50:14 +00:00
2020-05-08 19:30:43 +00:00
def midnight():
while True:
current_time = time.time()+10800
if int(current_time) % 86400 == 0:
log(False, "Иницаилизация ивента \"Миднайт\"")
2020-05-08 19:30:43 +00:00
for i in users:
2020-05-09 18:40:11 +00:00
bot[int(i)].event("midnight")
2020-05-09 21:46:09 +00:00
log(False, "Ивент \"Миднайт\" завершён")
time.sleep(1)
else:
time.sleep(0.50)
2020-05-08 19:30:43 +00:00
log(False, "Скрипт запущен, чтение users.json для восстановления обьектов ботов")
load_users()
2020-05-08 19:30:43 +00:00
tread_bots = threading.Thread(target=bots)
tread_midnight = threading.Thread(target=midnight)
tread_bots.start()
tread_midnight.start()