-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandlers.py
35 lines (29 loc) · 1.75 KB
/
handlers.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
import requests
from main import bot, dp
from aiogram.types import Message
from config import question_no_content, COMMENT_BOT_TOKEN, channel_id, group_id, ask_in_group
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
@dp.message_handler()
async def echo(message: Message):
if group_id == message["chat"]["username"]:
content = message.text.strip()
if content.startswith("#سوال"):
if len(content) > 5:
question = content.replace("#سوال", "")
id = message["from"]["id"]
base_url = f"https://api.comments.bot/createPost?api_key={COMMENT_BOT_TOKEN}&owner_id={id}&type=text&text={question}"
result = requests.get(base_url)
result = result.json()
username = message["from"]["username"]
question = question + f"\n\nسوال پرسیده شده توسط @{username}"
await bot.delete_message(chat_id = message.chat.id, message_id = message.message_id)
channel_post = await bot.send_message(chat_id=channel_id,
text= question,
reply_markup = InlineKeyboardMarkup(inline_keyboard=[[InlineKeyboardButton(text="پاسخ ها", url= result["result"]["link"]),]],resize_keyboard=True) )
await bot.forward_message(chat_id=message.chat.id,
from_chat_id = channel_post["chat"]["id"],
message_id = channel_post["message_id"])
else:
await bot.send_message(chat_id=message.chat.id, text=question_no_content)
else:
await bot.send_message(chat_id=message.chat.id, text=ask_in_group)