2022-02-16 18:13:44 +03:00
|
|
|
|
import logging
|
2022-10-07 17:50:42 +03:00
|
|
|
|
import io
|
|
|
|
|
import base64
|
2022-02-16 18:13:44 +03:00
|
|
|
|
|
|
|
|
|
from aiogram import types
|
|
|
|
|
from aiogram.dispatcher.filters import ChatTypeFilter
|
2023-03-28 09:49:46 +03:00
|
|
|
|
from aiogram.dispatcher import FSMContext
|
2022-02-16 18:13:44 +03:00
|
|
|
|
|
|
|
|
|
from load import dp, bot, config
|
|
|
|
|
from keyboards.inline.keyboard import menu
|
|
|
|
|
from parser import get_about_replacements
|
2023-03-26 00:12:27 +03:00
|
|
|
|
from keyboards.inline.donate import donate
|
2023-03-28 09:49:46 +03:00
|
|
|
|
if config.enable_logging:
|
2022-02-16 18:13:44 +03:00
|
|
|
|
from database import register
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dp.message_handler(commands=["help"])
|
|
|
|
|
async def help_msg(message: types.Message):
|
|
|
|
|
await bot.send_message(
|
|
|
|
|
message.chat.id,
|
|
|
|
|
(
|
|
|
|
|
"Я всего-лишь небольшой помощник:3\n"
|
|
|
|
|
"Умею работать в чатах, для настройки попросите администратора чата указать группу с помощью команды /set\n"
|
|
|
|
|
"/set - Установить группу, для получения данных о заменах(Работает ТОЛЬКО в чатах)\n"
|
|
|
|
|
"/start /get - получить информацию о заменах\n"
|
2023-03-04 12:33:57 +03:00
|
|
|
|
"[Viber Bot](viber://pa?chatURI=tfk_replace)"
|
|
|
|
|
), parse_mode='Markdown'
|
2022-02-16 18:13:44 +03:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2023-03-28 09:49:46 +03:00
|
|
|
|
@dp.message_handler(ChatTypeFilter(['private']), commands=['start', 'get'], state="*")
|
|
|
|
|
async def get_replace(message: types.Message, state: FSMContext):
|
|
|
|
|
if message.from_user.id in [int(i) for i in config.admin_users.split(',')] and str(message.get_args()).isdigit():
|
|
|
|
|
await bot.send_message(message.chat.id, "Напишите ответ")
|
|
|
|
|
await state.update_data(u=message.get_args())
|
|
|
|
|
await state.set_state(state="answer_support")
|
|
|
|
|
return
|
|
|
|
|
if config.enable_logging:
|
2022-02-16 18:13:44 +03:00
|
|
|
|
register(
|
|
|
|
|
user_id=message.from_user.id,
|
|
|
|
|
username=message.from_user.username,
|
|
|
|
|
first_name=str(message.from_user.first_name),
|
|
|
|
|
last_name=message.from_user.last_name
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
link = (
|
|
|
|
|
'<a href="{}">Проверьте замены тут</a>'
|
|
|
|
|
.format(config.bot("link"))
|
|
|
|
|
)
|
|
|
|
|
logging.info("User: {user_id} - {username}".format(
|
|
|
|
|
user_id=str(message.from_user.id),
|
|
|
|
|
username=str(message.from_user.username)
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
data = get_about_replacements()
|
2022-10-07 17:50:42 +03:00
|
|
|
|
if 'image' in data:
|
|
|
|
|
await bot.send_photo(
|
|
|
|
|
message.chat.id,
|
|
|
|
|
io.BytesIO(
|
|
|
|
|
base64.b64decode(
|
|
|
|
|
data["data"]['all']
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
parse_mode="Markdown",
|
2023-03-26 00:12:27 +03:00
|
|
|
|
reply_markup=donate
|
2022-10-07 17:50:42 +03:00
|
|
|
|
)
|
|
|
|
|
return
|
2022-02-16 18:13:44 +03:00
|
|
|
|
await bot.send_message(
|
|
|
|
|
message.chat.id,
|
|
|
|
|
"Замены {date}\n{teacher}\nВыберите свою группу"
|
|
|
|
|
.format(
|
|
|
|
|
date=data["date"].lower(),
|
|
|
|
|
teacher=str(data["another_teacher"]).title()
|
|
|
|
|
),
|
|
|
|
|
reply_markup=menu(data["data"])
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logging.error(str(e))
|
|
|
|
|
err_msg = (
|
|
|
|
|
"Техничиские шоколадки... "
|
|
|
|
|
f"Скорее всего структура файла была изменена\n{link}"
|
|
|
|
|
)
|
|
|
|
|
await bot.send_message(
|
|
|
|
|
message.chat.id,
|
|
|
|
|
err_msg,
|
|
|
|
|
parse_mode='HTML',
|
|
|
|
|
disable_web_page_preview=True
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dp.message_handler(commands=['link'])
|
|
|
|
|
async def get_link(message: types.Message):
|
|
|
|
|
msg = (
|
|
|
|
|
'<a href="{}">Проверьте замены тут</a>'
|
|
|
|
|
.format(config.bot("link"))
|
|
|
|
|
)
|
|
|
|
|
await bot.send_message(
|
|
|
|
|
message.chat.id,
|
|
|
|
|
msg,
|
|
|
|
|
parse_mode='HTML',
|
|
|
|
|
disable_web_page_preview=True
|
|
|
|
|
)
|