-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandlers.py
More file actions
60 lines (49 loc) · 2.09 KB
/
handlers.py
File metadata and controls
60 lines (49 loc) · 2.09 KB
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
import logging
from aiogram import Router, Bot
from aiogram.filters import Command, ChatMemberUpdatedFilter, JOIN_TRANSITION
from aiogram.types import Message, ChatMemberUpdated
from filters import ChatTypeFilter
router = Router(name=__name__)
logger = logging.getLogger(__name__)
@router.channel_post(ChatTypeFilter('channel'))
async def repost_channel_message(message: Message, repost_chat_id: int):
logger.info('Message from channel %s forwarded to chat %s', message.chat.id, repost_chat_id)
await message.copy_to(repost_chat_id)
@router.message(Command('get_chat_id'))
async def get_chat_id(message: Message):
await message.answer(
'Chat id:\n'
f'<code>{message.chat.id}</code>'
)
@router.my_chat_member(
ChatMemberUpdatedFilter(member_status_changed=JOIN_TRANSITION),
ChatTypeFilter('channel')
)
async def added_groups(event: ChatMemberUpdated, bot: Bot, admin_id: int):
if event.from_user.id == admin_id:
logging.info(
"Bot has been successfully added to the channel '%s' with id %s by the admin with id %s.",
event.chat.title or "Unknown",
event.chat.id,
admin_id
)
await bot.send_message(chat_id=admin_id,
text=f"🎉 Бот был успешно добавлен в ваш канал: \n\n"
f"Канал: {f'@{event.chat.username}' or f'<b>event.chat.title</b>' or '<b>Неизвестно</b>'}\n"
f"ID: <code>{event.chat.id}</code>"
)
else:
logging.info(
"Unauthorized attempt: User '%s' with id %s tried to add bot to channel '%s' with id %s. Lefting channel...",
event.from_user.username or "Unknown",
event.from_user.id,
event.chat.title or "Unknown",
event.chat.id
)
await event.chat.leave()
logging.info(
"Bot has successfully left the channel '%s' with id %s.",
event.chat.title or "Unknown",
event.chat.id
)
return