65 lines
2.3 KiB
Python
65 lines
2.3 KiB
Python
|
import logging
|
||
|
|
||
|
from aiogram import types
|
||
|
from aiogram.dispatcher.filters import ChatTypeFilter
|
||
|
|
||
|
from load import dp, bot, config
|
||
|
from database import set_group_settings, get_group
|
||
|
from parser import get_about_replacements
|
||
|
from database import register
|
||
|
|
||
|
|
||
|
@dp.message_handler(ChatTypeFilter(['group', 'supergroup']), commands=['set'])
|
||
|
async def set_group(message: types.Message):
|
||
|
if (message.from_user.id not in [admin.user.id for admin in await bot.get_chat_administrators(message.chat.id)]) and (message.from_user.id not in config.admin_user):
|
||
|
await message.answer("Вы не являетесь администратором чата!")
|
||
|
return
|
||
|
args = message.text.split()
|
||
|
if len(args) < 2:
|
||
|
await message.answer(
|
||
|
("Вы не передали имя своей группы!\n"
|
||
|
"Пример: /set 221")
|
||
|
)
|
||
|
return
|
||
|
|
||
|
set_group_settings(message.chat.id, args[1])
|
||
|
await message.answer("Настройка завершена успешно!")
|
||
|
|
||
|
@dp.message_handler(ChatTypeFilter(['group', 'supergroup']), commands=['start', 'get'])
|
||
|
async def get_replace_on_chat(message: types.Message):
|
||
|
if config.logging_user:
|
||
|
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
|
||
|
)
|
||
|
|
||
|
logging.info("User: {user_id} - {username}".format(
|
||
|
user_id=str(message.from_user.id),
|
||
|
username=str(message.from_user.username)
|
||
|
))
|
||
|
|
||
|
data = get_about_replacements()
|
||
|
group = get_group(message.chat.id)
|
||
|
|
||
|
if group is not None:
|
||
|
if group in data['data']:
|
||
|
await message.answer(
|
||
|
(
|
||
|
"Группа: {group}\n"
|
||
|
"Замены {date}\n"
|
||
|
"{teacher}\n"
|
||
|
"Замены: {replace}\n"
|
||
|
).format(
|
||
|
group=str(group),
|
||
|
replace=data['data'][group],
|
||
|
date=data["date"].lower(),
|
||
|
teacher=data["another_teacher"]
|
||
|
)
|
||
|
)
|
||
|
else:
|
||
|
await message.answer("Похоже замен нет")
|
||
|
else:
|
||
|
await message.answer("Похоже администратор группы не настроил привязку")
|