Update fastapi_app.py
Browse files- fastapi_app.py +1085 -0
fastapi_app.py
CHANGED
@@ -1614,3 +1614,1088 @@ async def send_poll_endpoint(chat_id: int, question: str, options: list, is_anon
|
|
1614 |
await bot_instance.send_chat_action(chat_id, action_enum)
|
1615 |
return {"status": "Chat action sent successfully"}
|
1616 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1614 |
await bot_instance.send_chat_action(chat_id, action_enum)
|
1615 |
return {"status": "Chat action sent successfully"}
|
1616 |
|
1617 |
+
async def send_chat_action_endpoint(chat_id: int, action: str):
|
1618 |
+
actions = {
|
1619 |
+
"typing": enums.ChatAction.TYPING,
|
1620 |
+
"upload_photo": enums.ChatAction.UPLOAD_PHOTO,
|
1621 |
+
"record_video": enums.ChatAction.RECORD_VIDEO,
|
1622 |
+
"upload_video": enums.ChatAction.UPLOAD_VIDEO,
|
1623 |
+
"record_voice": enums.ChatAction.RECORD_VOICE,
|
1624 |
+
"upload_voice": enums.ChatAction.UPLOAD_VOICE,
|
1625 |
+
"upload_document": enums.ChatAction.UPLOAD_DOCUMENT,
|
1626 |
+
"find_location": enums.ChatAction.FIND_LOCATION,
|
1627 |
+
"record_video_note": enums.ChatAction.RECORD_VIDEO_NOTE,
|
1628 |
+
"upload_video_note": enums.ChatAction.UPLOAD_VIDEO_NOTE,
|
1629 |
+
"playing": enums.ChatAction.PLAYING
|
1630 |
+
}
|
1631 |
+
action_enum = actions.get(action)
|
1632 |
+
if not action_enum:
|
1633 |
+
return {"error": "Invalid action"}
|
1634 |
+
await bot_instance.send_chat_action(chat_id, action_enum)
|
1635 |
+
return {"status": "Chat action sent successfully"}
|
1636 |
+
|
1637 |
+
@app.post("/get_chat")
|
1638 |
+
async def get_chat_endpoint(chat_id: int):
|
1639 |
+
chat = await bot_instance.get_chat(chat_id)
|
1640 |
+
return {"chat": chat.dict()}
|
1641 |
+
|
1642 |
+
@app.post("/get_chat_member")
|
1643 |
+
async def get_chat_member_endpoint(chat_id: int, user_id: int):
|
1644 |
+
chat_member = await bot_instance.get_chat_member(chat_id, user_id)
|
1645 |
+
return {"chat_member": chat_member.dict()}
|
1646 |
+
|
1647 |
+
@app.post("/get_chat_members_count")
|
1648 |
+
async def get_chat_members_count_endpoint(chat_id: int):
|
1649 |
+
count = await bot_instance.get_chat_members_count(chat_id)
|
1650 |
+
return {"members_count": count}
|
1651 |
+
|
1652 |
+
@app.post("/kick_chat_member")
|
1653 |
+
async def kick_chat_member_endpoint(chat_id: int, user_id: int):
|
1654 |
+
await bot_instance.kick_chat_member(chat_id, user_id)
|
1655 |
+
return {"status": "Chat member kicked successfully"}
|
1656 |
+
|
1657 |
+
@app.post("/unban_chat_member")
|
1658 |
+
async def unban_chat_member_endpoint(chat_id: int, user_id: int):
|
1659 |
+
await bot_instance.unban_chat_member(chat_id, user_id)
|
1660 |
+
return {"status": "Chat member unbanned successfully"}
|
1661 |
+
|
1662 |
+
@app.post("/promote_chat_member")
|
1663 |
+
async def promote_chat_member_endpoint(chat_id: int, user_id: int, can_change_info: bool = False, can_post_messages: bool = False, can_edit_messages: bool = False, can_delete_messages: bool = False, can_manage_video_chats: bool = False, can_restrict_members: bool = False, can_promote_members: bool = False, can_invite_users: bool = False, can_pin_messages: bool = False, can_manage_chat: bool = False):
|
1664 |
+
await bot_instance.promote_chat_member(
|
1665 |
+
chat_id,
|
1666 |
+
user_id,
|
1667 |
+
can_change_info=can_change_info,
|
1668 |
+
can_post_messages=can_post_messages,
|
1669 |
+
can_edit_messages=can_edit_messages,
|
1670 |
+
can_delete_messages=can_delete_messages,
|
1671 |
+
can_manage_video_chats=can_manage_video_chats,
|
1672 |
+
can_restrict_members=can_restrict_members,
|
1673 |
+
can_promote_members=can_promote_members,
|
1674 |
+
can_invite_users=can_invite_users,
|
1675 |
+
can_pin_messages=can_pin_messages,
|
1676 |
+
can_manage_chat=can_manage_chat
|
1677 |
+
)
|
1678 |
+
return {"status": "Chat member promoted successfully"}
|
1679 |
+
|
1680 |
+
@app.post("/set_chat_permissions")
|
1681 |
+
async def set_chat_permissions_endpoint(chat_id: int, permissions: dict):
|
1682 |
+
chat_permissions = enums.ChatPermissions(**permissions)
|
1683 |
+
await bot_instance.set_chat_permissions(chat_id, chat_permissions)
|
1684 |
+
return {"status": "Chat permissions set successfully"}
|
1685 |
+
|
1686 |
+
@app.post("/set_chat_photo")
|
1687 |
+
async def set_chat_photo_endpoint(chat_id: int, photo_url: str):
|
1688 |
+
response = requests.get(photo_url)
|
1689 |
+
photo = BytesIO(response.content)
|
1690 |
+
photo.name = "photo.jpg"
|
1691 |
+
await bot_instance.set_chat_photo(chat_id, photo)
|
1692 |
+
return {"status": "Chat photo set successfully"}
|
1693 |
+
|
1694 |
+
@app.post("/delete_chat_photo")
|
1695 |
+
async def delete_chat_photo_endpoint(chat_id: int):
|
1696 |
+
await bot_instance.delete_chat_photo(chat_id)
|
1697 |
+
return {"status": "Chat photo deleted successfully"}
|
1698 |
+
|
1699 |
+
@app.post("/set_chat_title")
|
1700 |
+
async def set_chat_title_endpoint(chat_id: int, title: str):
|
1701 |
+
await bot_instance.set_chat_title(chat_id, title)
|
1702 |
+
return {"status": "Chat title set successfully"}
|
1703 |
+
|
1704 |
+
@app.post("/set_chat_description")
|
1705 |
+
async def set_chat_description_endpoint(chat_id: int, description: str):
|
1706 |
+
await bot_instance.set_chat_description(chat_id, description)
|
1707 |
+
return {"status": "Chat description set successfully"}
|
1708 |
+
|
1709 |
+
@app.post("/pin_chat_message")
|
1710 |
+
async def pin_chat_message_endpoint(chat_id: int, message_id: int, disable_notification: bool = False):
|
1711 |
+
await bot_instance.pin_chat_message(chat_id, message_id, disable_notification=disable_notification)
|
1712 |
+
return {"status": "Message pinned successfully"}
|
1713 |
+
|
1714 |
+
@app.post("/unpin_chat_message")
|
1715 |
+
async def unpin_chat_message_endpoint(chat_id: int, message_id: int):
|
1716 |
+
await bot_instance.unpin_chat_message(chat_id, message_id)
|
1717 |
+
return {"status": "Message unpinned successfully"}
|
1718 |
+
|
1719 |
+
@app.post("/unpin_all_chat_messages")
|
1720 |
+
async def unpin_all_chat_messages_endpoint(chat_id: int):
|
1721 |
+
await bot_instance.unpin_all_chat_messages(chat_id)
|
1722 |
+
return {"status": "All messages unpinned successfully"}
|
1723 |
+
|
1724 |
+
@app.post("/answer_callback_query")
|
1725 |
+
async def answer_callback_query_endpoint(callback_query_id: str, text: str = None, show_alert: bool = False, url: str = None, cache_time: int = 0):
|
1726 |
+
await bot_instance.answer_callback_query(callback_query_id, text=text, show_alert=show_alert, url=url, cache_time=cache_time)
|
1727 |
+
return {"status": "Callback query answered successfully"}
|
1728 |
+
|
1729 |
+
@app.post("/copy_message")
|
1730 |
+
async def copy_message_endpoint(chat_id: int, from_chat_id: int, message_id: int, caption: str = None, parse_mode: str = None, caption_entities: list = None, reply_to_message_id: int = None, allow_sending_without_reply: bool = False, reply_markup: dict = None):
|
1731 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
1732 |
+
message = await bot_instance.copy_message(
|
1733 |
+
chat_id,
|
1734 |
+
from_chat_id,
|
1735 |
+
message_id,
|
1736 |
+
caption=caption,
|
1737 |
+
parse_mode=parse_mode,
|
1738 |
+
caption_entities=caption_entities,
|
1739 |
+
reply_to_message_id=reply_to_message_id,
|
1740 |
+
allow_sending_without_reply=allow_sending_without_reply,
|
1741 |
+
reply_markup=reply_markup_obj
|
1742 |
+
)
|
1743 |
+
return {"message_id": message.id}
|
1744 |
+
|
1745 |
+
@app.post("/forward_messages")
|
1746 |
+
async def forward_messages_endpoint(chat_id: int, from_chat_id: int, message_ids: list, disable_notification: bool = False):
|
1747 |
+
messages = await bot_instance.forward_messages(
|
1748 |
+
chat_id,
|
1749 |
+
from_chat_id,
|
1750 |
+
message_ids,
|
1751 |
+
disable_notification=disable_notification
|
1752 |
+
)
|
1753 |
+
return {"messages": [msg.id for msg in messages]}
|
1754 |
+
|
1755 |
+
@app.post("/send_poll")
|
1756 |
+
async def send_poll_endpoint(chat_id: int, question: str, options: list, is_anonymous: bool = False, type: str = "regular", allows_multiple_answers: bool = False, correct_option_id: int = None, explanation: str = None, explanation_parse_mode: str = None, open_period: int = None, close_date: int = None, is_closed: bool = False):
|
1757 |
+
message = await bot_instance.send_poll(
|
1758 |
+
chat_id,
|
1759 |
+
question,
|
1760 |
+
options,
|
1761 |
+
is_anonymous=is_anonymous,
|
1762 |
+
type=type,
|
1763 |
+
allows_multiple_answers=allows_multiple_answers,
|
1764 |
+
correct_option_id=correct_option_id,
|
1765 |
+
explanation=explanation,
|
1766 |
+
explanation_parse_mode=explanation_parse_mode,
|
1767 |
+
open_period=open_period,
|
1768 |
+
close_date=close_date,
|
1769 |
+
is_closed=is_closed
|
1770 |
+
)
|
1771 |
+
return {"message_id": message.id}
|
1772 |
+
|
1773 |
+
@app.post("/send_dice")
|
1774 |
+
async def send_dice_endpoint(chat_id: int, reply_to_message_id: int = None, reply_markup: dict = None):
|
1775 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
1776 |
+
message = await bot_instance.send_dice(
|
1777 |
+
chat_id,
|
1778 |
+
reply_to_message_id=reply_to_message_id,
|
1779 |
+
reply_markup=reply_markup_obj
|
1780 |
+
)
|
1781 |
+
return {"message_id": message.id}
|
1782 |
+
|
1783 |
+
@app.post("/send_game")
|
1784 |
+
async def send_game_endpoint(chat_id: int, game_short_name: str, reply_to_message_id: int = None, reply_markup: dict = None):
|
1785 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
1786 |
+
message = await bot_instance.send_game(
|
1787 |
+
chat_id,
|
1788 |
+
game_short_name,
|
1789 |
+
reply_to_message_id=reply_to_message_id,
|
1790 |
+
reply_markup=reply_markup_obj
|
1791 |
+
)
|
1792 |
+
return {"message_id": message.id}
|
1793 |
+
|
1794 |
+
@app.post("/send_media_group")
|
1795 |
+
async def send_media_group_endpoint(chat_id: int, media: list, reply_to_message_id: int = None, reply_markup: dict = None):
|
1796 |
+
media_group = [types.InputMediaPhoto(media=media_item["media"]) if media_item["type"] == "photo" else types.InputMediaVideo(media=media_item["media"]) for media_item in media]
|
1797 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
1798 |
+
messages = await bot_instance.send_media_group(
|
1799 |
+
chat_id,
|
1800 |
+
media_group,
|
1801 |
+
reply_to_message_id=reply_to_message_id,
|
1802 |
+
reply_markup=reply_markup_obj
|
1803 |
+
)
|
1804 |
+
return {"messages": [msg.id for msg in messages]}
|
1805 |
+
|
1806 |
+
@app.post("/send_invoice")
|
1807 |
+
async def send_invoice_endpoint(chat_id: int, title: str, description: str, payload: str, provider_token: str, currency: str, prices: list, start_parameter: str = None, provider_data: str = None, photo_url: str = None, photo_size: int = None, photo_width: int = None, photo_height: int = None, need_name: bool = False, need_phone_number: bool = False, need_email: bool = False, need_shipping_address: bool = False, send_phone_number_to_provider: bool = False, send_email_to_provider: bool = False, is_flexible: bool = False, disable_notification: bool = False, protect_content: bool = False, reply_to_message_id: int = None, allow_sending_without_reply: bool = False, reply_markup: dict = None):
|
1808 |
+
prices_obj = [types.LabeledPrice(label=price["label"], amount=price["amount"]) for price in prices]
|
1809 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
1810 |
+
message = await bot_instance.send_invoice(
|
1811 |
+
chat_id,
|
1812 |
+
title,
|
1813 |
+
description,
|
1814 |
+
payload,
|
1815 |
+
provider_token,
|
1816 |
+
currency,
|
1817 |
+
prices_obj,
|
1818 |
+
start_parameter=start_parameter,
|
1819 |
+
provider_data=provider_data,
|
1820 |
+
photo_url=photo_url,
|
1821 |
+
photo_size=photo_size,
|
1822 |
+
photo_width=photo_width,
|
1823 |
+
photo_height=photo_height,
|
1824 |
+
need_name=need_name,
|
1825 |
+
need_phone_number=need_phone_number,
|
1826 |
+
need_email=need_email,
|
1827 |
+
need_shipping_address=need_shipping_address,
|
1828 |
+
send_phone_number_to_provider=send_phone_number_to_provider,
|
1829 |
+
send_email_to_provider=send_email_to_provider,
|
1830 |
+
is_flexible=is_flexible,
|
1831 |
+
disable_notification=disable_notification,
|
1832 |
+
protect_content=protect_content,
|
1833 |
+
reply_to_message_id=reply_to_message_id,
|
1834 |
+
allow_sending_without_reply=allow_sending_without_reply,
|
1835 |
+
reply_markup=reply_markup_obj
|
1836 |
+
)
|
1837 |
+
return {"message_id": message.id}
|
1838 |
+
|
1839 |
+
@app.post("/send_location")
|
1840 |
+
async def send_location_endpoint(chat_id: int, latitude: float, longitude: float, reply_to_message_id: int = None, reply_markup: dict = None):
|
1841 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
1842 |
+
message = await bot_instance.send_location(
|
1843 |
+
chat_id,
|
1844 |
+
latitude,
|
1845 |
+
longitude,
|
1846 |
+
reply_to_message_id=reply_to_message_id,
|
1847 |
+
reply_markup=reply_markup_obj
|
1848 |
+
)
|
1849 |
+
return {"message_id": message.id}
|
1850 |
+
|
1851 |
+
@app.post("/send_contact")
|
1852 |
+
async def send_contact_endpoint(chat_id: int, phone_number: str, first_name: str, last_name: str = None, reply_to_message_id: int = None, reply_markup: dict = None):
|
1853 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
1854 |
+
message = await bot_instance.send_contact(
|
1855 |
+
chat_id,
|
1856 |
+
phone_number,
|
1857 |
+
first_name,
|
1858 |
+
last_name=last_name,
|
1859 |
+
reply_to_message_id=reply_to_message_id,
|
1860 |
+
reply_markup=reply_markup_obj
|
1861 |
+
)
|
1862 |
+
return {"message_id": message.id}
|
1863 |
+
|
1864 |
+
@app.post("/send_animation")
|
1865 |
+
async def send_animation_endpoint(chat_id: int, animation_url: str, reply_to_message_id: int = None, reply_markup: dict = None):
|
1866 |
+
response = requests.get(animation_url)
|
1867 |
+
animation = BytesIO(response.content)
|
1868 |
+
animation.name = "animation.gif"
|
1869 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
1870 |
+
message = await bot_instance.send_animation(
|
1871 |
+
chat_id,
|
1872 |
+
animation,
|
1873 |
+
reply_to_message_id=reply_to_message_id,
|
1874 |
+
reply_markup=reply_markup_obj
|
1875 |
+
)
|
1876 |
+
return {"message_id": message.id}
|
1877 |
+
|
1878 |
+
@app.post("/send_video_note")
|
1879 |
+
async def send_video_note_endpoint(chat_id: int, video_note_url: str, reply_to_message_id: int = None, reply_markup: dict = None):
|
1880 |
+
response = requests.get(video_note_url)
|
1881 |
+
video_note = BytesIO(response.content)
|
1882 |
+
video_note.name = "video_note.mp4"
|
1883 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
1884 |
+
message = await bot_instance.send_video_note(
|
1885 |
+
chat_id,
|
1886 |
+
video_note,
|
1887 |
+
reply_to_message_id=reply_to_message_id,
|
1888 |
+
reply_markup=reply_markup_obj
|
1889 |
+
)
|
1890 |
+
return {"message_id": message.id}
|
1891 |
+
|
1892 |
+
@app.post("/send_voice")
|
1893 |
+
async def send_voice_endpoint(chat_id: int, voice_url: str, reply_to_message_id: int = None, reply_markup: dict = None):
|
1894 |
+
response = requests.get(voice_url)
|
1895 |
+
voice = BytesIO(response.content)
|
1896 |
+
voice.name = "voice.ogg"
|
1897 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
1898 |
+
message = await bot_instance.send_voice(
|
1899 |
+
chat_id,
|
1900 |
+
voice,
|
1901 |
+
reply_to_message_id=reply_to_message_id,
|
1902 |
+
reply_markup=reply_markup_obj
|
1903 |
+
)
|
1904 |
+
return {"message_id": message.id}
|
1905 |
+
|
1906 |
+
@app.post("/send_video")
|
1907 |
+
async def send_video_endpoint(chat_id: int, video_url: str, reply_to_message_id: int = None, reply_markup: dict = None):
|
1908 |
+
response = requests.get(video_url)
|
1909 |
+
video = BytesIO(response.content)
|
1910 |
+
video.name = "video.mp4"
|
1911 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
1912 |
+
message = await bot_instance.send_video(
|
1913 |
+
chat_id,
|
1914 |
+
video,
|
1915 |
+
reply_to_message_id=reply_to_message_id,
|
1916 |
+
reply_markup=reply_markup_obj
|
1917 |
+
)
|
1918 |
+
return {"message_id": message.id}
|
1919 |
+
|
1920 |
+
@app.post("/send_document")
|
1921 |
+
async def send_document_endpoint(chat_id: int, document_url: str, reply_to_message_id: int = None, reply_markup: dict = None):
|
1922 |
+
response = requests.get(document_url)
|
1923 |
+
document = BytesIO(response.content)
|
1924 |
+
document.name = "document.pdf"
|
1925 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
1926 |
+
message = await bot_instance.send_document(
|
1927 |
+
chat_id,
|
1928 |
+
document,
|
1929 |
+
reply_to_message_id=reply_to_message_id,
|
1930 |
+
reply_markup=reply_markup_obj
|
1931 |
+
)
|
1932 |
+
return {"message_id": message.id}
|
1933 |
+
|
1934 |
+
@app.post("/send_photo")
|
1935 |
+
async def send_photo_endpoint(chat_id: int, photo_url: str, reply_to_message_id: int = None, reply_markup: dict = None):
|
1936 |
+
response = requests.get(photo_url)
|
1937 |
+
photo = BytesIO(response.content)
|
1938 |
+
photo.name = "photo.jpg"
|
1939 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
1940 |
+
message = await bot_instance.send_photo(
|
1941 |
+
chat_id,
|
1942 |
+
photo,
|
1943 |
+
reply_to_message_id=reply_to_message_id,
|
1944 |
+
reply_markup=reply_markup_obj
|
1945 |
+
)
|
1946 |
+
return {"message_id": message.id}
|
1947 |
+
|
1948 |
+
@app.post("/send_audio")
|
1949 |
+
async def send_audio_endpoint(chat_id: int, audio_url: str, reply_to_message_id: int = None, reply_markup: dict = None):
|
1950 |
+
response = requests.get(audio_url)
|
1951 |
+
audio = BytesIO(response.content)
|
1952 |
+
audio.name = "audio.mp3"
|
1953 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
1954 |
+
message = await bot_instance.send_audio(
|
1955 |
+
chat_id,
|
1956 |
+
audio,
|
1957 |
+
reply_to_message_id=reply_to_message_id,
|
1958 |
+
reply_markup=reply_markup_obj
|
1959 |
+
)
|
1960 |
+
return {"message_id": message.id}
|
1961 |
+
|
1962 |
+
@app.post("/send_sticker")
|
1963 |
+
async def send_sticker_endpoint(chat_id: int, sticker_url: str, reply_to_message_id: int = None, reply_markup: dict = None):
|
1964 |
+
response = requests.get(sticker_url)
|
1965 |
+
sticker = BytesIO(response.content)
|
1966 |
+
sticker.name = "sticker.webp"
|
1967 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
1968 |
+
message = await bot_instance.send_sticker(
|
1969 |
+
chat_id,
|
1970 |
+
sticker,
|
1971 |
+
reply_to_message_id=reply_to_message_id,
|
1972 |
+
reply_markup=reply_markup_obj
|
1973 |
+
)
|
1974 |
+
return {"message_id": message.id}
|
1975 |
+
|
1976 |
+
@app.post("/send_video_note")
|
1977 |
+
async def send_video_note_endpoint(chat_id: int, video_note_url: str, reply_to_message_id: int = None, reply_markup: dict = None):
|
1978 |
+
response = requests.get(video_note_url)
|
1979 |
+
video_note = BytesIO(response.content)
|
1980 |
+
video_note.name = "video_note.mp4"
|
1981 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
1982 |
+
message = await bot_instance.send_video_note(
|
1983 |
+
chat_id,
|
1984 |
+
video_note,
|
1985 |
+
reply_to_message_id=reply_to_message_id,
|
1986 |
+
reply_markup=reply_markup_obj
|
1987 |
+
)
|
1988 |
+
return {"message_id": message.id}
|
1989 |
+
|
1990 |
+
@app.post("/send_voice")
|
1991 |
+
async def send_voice_endpoint(chat_id: int, voice_url: str, reply_to_message_id: int = None, reply_markup: dict = None):
|
1992 |
+
response = requests.get(voice_url)
|
1993 |
+
voice = BytesIO(response.content)
|
1994 |
+
voice.name = "voice.ogg"
|
1995 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
1996 |
+
message = await bot_instance.send_voice(
|
1997 |
+
chat_id,
|
1998 |
+
voice,
|
1999 |
+
reply_to_message_id=reply_to_message_id,
|
2000 |
+
reply_markup=reply_markup_obj
|
2001 |
+
)
|
2002 |
+
return {"message_id": message.id}
|
2003 |
+
|
2004 |
+
@app.post("/send_video")
|
2005 |
+
async def send_video_endpoint(chat_id: int, video_url: str, reply_to_message_id: int = None, reply_markup: dict = None):
|
2006 |
+
response = requests.get(video_url)
|
2007 |
+
video = BytesIO(response.content)
|
2008 |
+
video.name = "video.mp4"
|
2009 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
2010 |
+
message = await bot_instance.send_video(
|
2011 |
+
chat_id,
|
2012 |
+
video,
|
2013 |
+
reply_to_message_id=reply_to_message_id,
|
2014 |
+
reply_markup=reply_markup_obj
|
2015 |
+
)
|
2016 |
+
return {"message_id": message.id}
|
2017 |
+
|
2018 |
+
@app.post("/send_document")
|
2019 |
+
async def send_document_endpoint(chat_id: int, document_url: str, reply_to_message_id: int = None, reply_markup: dict = None):
|
2020 |
+
response = requests.get(document_url)
|
2021 |
+
document = BytesIO(response.content)
|
2022 |
+
document.name = "document.pdf"
|
2023 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
2024 |
+
message = await bot_instance.send_document(
|
2025 |
+
chat_id,
|
2026 |
+
document,
|
2027 |
+
reply_to_message_id=reply_to_message_id,
|
2028 |
+
reply_markup=reply_markup_obj
|
2029 |
+
)
|
2030 |
+
return {"message_id": message.id}
|
2031 |
+
|
2032 |
+
@app.post("/send_photo")
|
2033 |
+
async def send_photo_endpoint(chat_id: int, photo_url: str, reply_to_message_id: int = None, reply_markup: dict = None):
|
2034 |
+
response = requests.get(photo_url)
|
2035 |
+
photo = BytesIO(response.content)
|
2036 |
+
photo.name = "photo.jpg"
|
2037 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
2038 |
+
message = await bot_instance.send_photo(
|
2039 |
+
chat_id,
|
2040 |
+
photo,
|
2041 |
+
reply_to_message_id=reply_to_message_id,
|
2042 |
+
reply_markup=reply_markup_obj
|
2043 |
+
)
|
2044 |
+
return {"message_id": message.id}
|
2045 |
+
|
2046 |
+
@app.post("/send_audio")
|
2047 |
+
async def send_audio_endpoint(chat_id: int, audio_url: str, reply_to_message_id: int = None, reply_markup: dict = None):
|
2048 |
+
response = requests.get(audio_url)
|
2049 |
+
audio = BytesIO(response.content)
|
2050 |
+
audio.name = "audio.mp3"
|
2051 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
2052 |
+
message = await bot_instance.send_audio(
|
2053 |
+
chat_id,
|
2054 |
+
audio,
|
2055 |
+
reply_to_message_id=reply_to_message_id,
|
2056 |
+
reply_markup=reply_markup_obj
|
2057 |
+
)
|
2058 |
+
return {"message_id": message.id}
|
2059 |
+
|
2060 |
+
@app.post("/send_location")
|
2061 |
+
async def send_location_endpoint(chat_id: int, latitude: float, longitude: float, reply_to_message_id: int = None, reply_markup: dict = None):
|
2062 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
2063 |
+
message = await bot_instance.send_location(
|
2064 |
+
chat_id,
|
2065 |
+
latitude,
|
2066 |
+
longitude,
|
2067 |
+
reply_to_message_id=reply_to_message_id,
|
2068 |
+
reply_markup=reply_markup_obj
|
2069 |
+
)
|
2070 |
+
return {"message_id": message.id}
|
2071 |
+
|
2072 |
+
@app.post("/send_contact")
|
2073 |
+
async def send_contact_endpoint(chat_id: int, phone_number: str, first_name: str, last_name: str = None, reply_to_message_id: int = None, reply_markup: dict = None):
|
2074 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
2075 |
+
message = await bot_instance.send_contact(
|
2076 |
+
chat_id,
|
2077 |
+
phone_number,
|
2078 |
+
first_name,
|
2079 |
+
last_name=last_name,
|
2080 |
+
reply_to_message_id=reply_to_message_id,
|
2081 |
+
reply_markup=reply_markup_obj
|
2082 |
+
)
|
2083 |
+
return {"message_id": message.id}
|
2084 |
+
|
2085 |
+
@app.post("/send_dice")
|
2086 |
+
async def send_dice_endpoint(chat_id: int, reply_to_message_id: int = None, reply_markup: dict = None):
|
2087 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
2088 |
+
message = await bot_instance.send_dice(
|
2089 |
+
chat_id,
|
2090 |
+
reply_to_message_id=reply_to_message_id,
|
2091 |
+
reply_markup=reply_markup_obj
|
2092 |
+
)
|
2093 |
+
return {"message_id": message.id}
|
2094 |
+
|
2095 |
+
@app.post("/send_game")
|
2096 |
+
async def send_game_endpoint(chat_id: int, game_short_name: str, reply_to_message_id: int = None, reply_markup: dict = None):
|
2097 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
2098 |
+
message = await bot_instance.send_game(
|
2099 |
+
chat_id,
|
2100 |
+
game_short_name,
|
2101 |
+
reply_to_message_id=reply_to_message_id,
|
2102 |
+
reply_markup=reply_markup_obj
|
2103 |
+
)
|
2104 |
+
return {"message_id": message.id}
|
2105 |
+
|
2106 |
+
@app.post("/send_media_group")
|
2107 |
+
async def send_media_group_endpoint(chat_id: int, media: list, reply_to_message_id: int = None, reply_markup: dict = None):
|
2108 |
+
media_group = [types.InputMediaPhoto(media=media_item["media"]) if media_item["type"] == "photo" else types.InputMediaVideo(media=media_item["media"]) for media_item in media]
|
2109 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
2110 |
+
messages = await bot_instance.send_media_group(
|
2111 |
+
chat_id,
|
2112 |
+
media_group,
|
2113 |
+
reply_to_message_id=reply_to_message_id,
|
2114 |
+
reply_markup=reply_markup_obj
|
2115 |
+
)
|
2116 |
+
return {"messages": [msg.id for msg in messages]}
|
2117 |
+
|
2118 |
+
@app.post("/send_invoice")
|
2119 |
+
async def send_invoice_endpoint(chat_id: int, title: str, description: str, payload: str, provider_token: str, currency: str, prices: list, start_parameter: str = None, provider_data: str = None, photo_url: str = None, photo_size: int = None, photo_width: int = None, photo_height: int = None, need_name: bool = False, need_phone_number: bool = False, need_email: bool = False, need_shipping_address: bool = False, send_phone_number_to_provider: bool = False, send_email_to_provider: bool = False, is_flexible: bool = False, disable_notification: bool = False, protect_content: bool = False, reply_to_message_id: int = None, allow_sending_without_reply: bool = False, reply_markup: dict = None):
|
2120 |
+
prices_obj = [types.LabeledPrice(label=price["label"], amount=price["amount"]) for price in prices]
|
2121 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
2122 |
+
message = await bot_instance.send_invoice(
|
2123 |
+
chat_id,
|
2124 |
+
title,
|
2125 |
+
description,
|
2126 |
+
payload,
|
2127 |
+
provider_token,
|
2128 |
+
currency,
|
2129 |
+
prices_obj,
|
2130 |
+
start_parameter=start_parameter,
|
2131 |
+
provider_data=provider_data,
|
2132 |
+
photo_url=photo_url,
|
2133 |
+
photo_size=photo_size,
|
2134 |
+
photo_width=photo_width,
|
2135 |
+
photo_height=photo_height,
|
2136 |
+
need_name=need_name,
|
2137 |
+
need_phone_number=need_phone_number,
|
2138 |
+
need_email=need_email,
|
2139 |
+
need_shipping_address=need_shipping_address,
|
2140 |
+
send_phone_number_to_provider=send_phone_number_to_provider,
|
2141 |
+
send_email_to_provider=send_email_to_provider,
|
2142 |
+
is_flexible=is_flexible,
|
2143 |
+
disable_notification=disable_notification,
|
2144 |
+
protect_content=protect_content,
|
2145 |
+
reply_to_message_id=reply_to_message_id,
|
2146 |
+
allow_sending_without_reply=allow_sending_without_reply,
|
2147 |
+
reply_markup=reply_markup_obj
|
2148 |
+
)
|
2149 |
+
return {"message_id": message.id}
|
2150 |
+
|
2151 |
+
@app.post("/send_poll")
|
2152 |
+
async def send_poll_endpoint(chat_id: int, question: str, options: list, is_anonymous: bool = False, type: str = "regular", allows_multiple_answers: bool = False, correct_option_id: int = None, explanation: str = None, explanation_parse_mode: str = None, open_period: int = None, close_date: int = None, is_closed: bool = False):
|
2153 |
+
message = await bot_instance.send_poll(
|
2154 |
+
chat_id,
|
2155 |
+
question,
|
2156 |
+
options,
|
2157 |
+
is_anonymous=is_anonymous,
|
2158 |
+
type=type,
|
2159 |
+
allows_multiple_answers=allows_multiple_answers,
|
2160 |
+
correct_option_id=correct_option_id,
|
2161 |
+
explanation=explanation,
|
2162 |
+
explanation_parse_mode=explanation_parse_mode,
|
2163 |
+
open_period=open_period,
|
2164 |
+
close_date=close_date,
|
2165 |
+
is_closed=is_closed
|
2166 |
+
)
|
2167 |
+
return {"message_id": message.id}
|
2168 |
+
|
2169 |
+
@app.post("/send_dice")
|
2170 |
+
async def send_dice_endpoint(chat_id: int, reply_to_message_id: int = None, reply_markup: dict = None):
|
2171 |
+
reply_markup_obj = InlineKeyboardMarkup(**reply_markup) if reply_markup else None
|
2172 |
+
message = await bot_instance.send_dice(
|
2173 |
+
chat_id,
|
2174 |
+
reply_to_message_id=reply_to_message_id,
|
2175 |
+
reply_markup=reply_markup_obj
|
2176 |
+
)
|
2177 |
+
return {"message_id": message.id}
|
2178 |
+
|
2179 |
+
@app.post("/send_chat_action")
|
2180 |
+
async def send_chat_action_endpoint(chat_id: int, action: str):
|
2181 |
+
actions = {
|
2182 |
+
"typing": enums.ChatAction.TYPING,
|
2183 |
+
"upload_photo": enums.ChatAction.UPLOAD_PHOTO,
|
2184 |
+
"record_video": enums.ChatAction.RECORD_VIDEO,
|
2185 |
+
"upload_video": enums.ChatAction.UPLOAD_VIDEO,
|
2186 |
+
"record_voice": enums.ChatAction.RECORD_VOICE,
|
2187 |
+
"upload_voice": enums.ChatAction.UPLOAD_VOICE,
|
2188 |
+
"upload_document": enums.ChatAction.UPLOAD_DOCUMENT,
|
2189 |
+
"find_location": enums.ChatAction.FIND_LOCATION,
|
2190 |
+
"record_video_note": enums.ChatAction.RECORD_VIDEO_NOTE,
|
2191 |
+
"upload_video_note": enums.ChatAction.UPLOAD_VIDEO_NOTE,
|
2192 |
+
"playing": enums.ChatAction.PLAYING
|
2193 |
+
}
|
2194 |
+
action_enum = actions.get(action)
|
2195 |
+
if not action_enum:
|
2196 |
+
return {"error": "Invalid action"}
|
2197 |
+
await bot_instance.send_chat_action(chat_id, action_enum)
|
2198 |
+
return {"status": "Chat action sent successfully"}
|
2199 |
+
|
2200 |
+
@app.post("/text_to_speech")
|
2201 |
+
async def text_to_speech_endpoint(tts_request: TextToSpeechRequest):
|
2202 |
+
audio = await convert(tts_request.text)
|
2203 |
+
return {"audio_url": audio.name}
|
2204 |
+
|
2205 |
+
async def convert(text):
|
2206 |
+
audio = BytesIO()
|
2207 |
+
i = Translator().translate(text, dest="en")
|
2208 |
+
lang = i.src
|
2209 |
+
tts = gTTS(text, lang=lang)
|
2210 |
+
audio.name = lang + ".mp3"
|
2211 |
+
tts.write_to_fp(audio)
|
2212 |
+
return audio
|
2213 |
+
|
2214 |
+
@app.post("/download_youtube_song")
|
2215 |
+
async def download_youtube_song_endpoint(yt_request: YouTubeDownloadRequest):
|
2216 |
+
try:
|
2217 |
+
results = YoutubeSearch(yt_request.url, max_results=1).to_dict()
|
2218 |
+
link = f"https://youtube.com{results[0]['url_suffix']}"
|
2219 |
+
title = results[0]["title"][:40]
|
2220 |
+
thumbnail = results[0]["thumbnails"][0]
|
2221 |
+
thumb_name = f'thumb{title}.jpg'
|
2222 |
+
thumb = requests.get(thumbnail, allow_redirects=True)
|
2223 |
+
open(thumb_name, 'wb').write(thumb.content)
|
2224 |
+
performer = f"[Mᴋɴ Bᴏᴛᴢ™]"
|
2225 |
+
duration = results[0]["duration"]
|
2226 |
+
url_suffix = results[0]["url_suffix"]
|
2227 |
+
views = results[0]["views"]
|
2228 |
+
except Exception as e:
|
2229 |
+
logger.error(f"Error downloading YouTube song: {e}")
|
2230 |
+
return {"error": str(e)}
|
2231 |
+
|
2232 |
+
ydl_opts = {"format": "bestaudio[ext=m4a]"}
|
2233 |
+
try:
|
2234 |
+
with YoutubeDL(ydl_opts) as ydl:
|
2235 |
+
info_dict = ydl.extract_info(link, download=False)
|
2236 |
+
audio_file = ydl.prepare_filename(info_dict)
|
2237 |
+
ydl.process_info(info_dict)
|
2238 |
+
except Exception as e:
|
2239 |
+
logger.error(f"Error processing YouTube song: {e}")
|
2240 |
+
return {"error": str(e)}
|
2241 |
+
|
2242 |
+
cap = "**BY›› [Mᴋɴ Bᴏᴛᴢ™](https://t.me/mkn_bots_updates)**"
|
2243 |
+
secmul, dur, dur_arr = 1, 0, duration.split(':')
|
2244 |
+
for i in range(len(dur_arr) - 1, -1, -1):
|
2245 |
+
dur += (int(dur_arr[i]) * secmul)
|
2246 |
+
secmul *= 60
|
2247 |
+
|
2248 |
+
return {"audio_file": audio_file, "caption": cap, "title": title, "duration": dur, "performer": performer, "thumb": thumb_name}
|
2249 |
+
|
2250 |
+
@app.post("/download_youtube_video")
|
2251 |
+
async def download_youtube_video_endpoint(yt_request: YouTubeDownloadRequest):
|
2252 |
+
url = yt_request.url
|
2253 |
+
try:
|
2254 |
+
search = SearchVideos(f"{url}", offset=1, mode="dict", max_results=1)
|
2255 |
+
mi = search.result()
|
2256 |
+
mio = mi["search_result"]
|
2257 |
+
mo = mio[0]["link"]
|
2258 |
+
thum = mio[0]["title"]
|
2259 |
+
fridayz = mio[0]["id"]
|
2260 |
+
mio[0]["channel"]
|
2261 |
+
kekme = f"https://img.youtube.com/vi/{fridayz}/hqdefault.jpg"
|
2262 |
+
await asyncio.sleep(0.6)
|
2263 |
+
url = mo
|
2264 |
+
sedlyf = wget.download(kekme)
|
2265 |
+
opts = {
|
2266 |
+
"format": "best",
|
2267 |
+
"addmetadata": True,
|
2268 |
+
"key": "FFmpegMetadata",
|
2269 |
+
"prefer_ffmpeg": True,
|
2270 |
+
"geo_bypass": True,
|
2271 |
+
"nocheckcertificate": True,
|
2272 |
+
"postprocessors": [{"key": "FFmpegVideoConvertor", "preferedformat": "mp4"}],
|
2273 |
+
"outtmpl": "%(id)s.mp4",
|
2274 |
+
"logtostderr": False,
|
2275 |
+
"quiet": True,
|
2276 |
+
}
|
2277 |
+
with YoutubeDL(opts) as ytdl:
|
2278 |
+
ytdl_data = ytdl.extract_info(url, download=True)
|
2279 |
+
except Exception as e:
|
2280 |
+
logger.error(f"Error downloading YouTube video: {e}")
|
2281 |
+
return {"error": str(e)}
|
2282 |
+
|
2283 |
+
file_stark = f"{ytdl_data['id']}.mp4"
|
2284 |
+
capy = f"""**𝚃𝙸𝚃𝙻𝙴 :** [{thum}]({mo})\n**𝚁𝙴𝚀𝚄𝙴𝚂𝚃𝙴𝙳 𝙱𝚈 :** {await bot_instance.get_me().mention}"""
|
2285 |
+
|
2286 |
+
return {"video_file": file_stark, "caption": capy, "title": ytdl_data["title"], "duration": int(ytdl_data["duration"]), "thumb": sedlyf}
|
2287 |
+
|
2288 |
+
@app.post("/carbon")
|
2289 |
+
async def carbon_endpoint(carbon_request: CarbonRequest):
|
2290 |
+
carbon_image = await make_carbon(carbon_request.text, True)
|
2291 |
+
return {"carbon_url": carbon_image}
|
2292 |
+
|
2293 |
+
async def make_carbon(text, tele=False):
|
2294 |
+
url = "https://carbonara.solopov.dev/api/cook"
|
2295 |
+
async with aiohttp.ClientSession() as session:
|
2296 |
+
async with session.post(url, json={"code": text}) as resp:
|
2297 |
+
image = BytesIO(await resp.read())
|
2298 |
+
image.name = "carbon.png"
|
2299 |
+
if tele:
|
2300 |
+
uf = upload_file(image)
|
2301 |
+
image.close()
|
2302 |
+
return f"https://graph.org{uf[0]}"
|
2303 |
+
return image
|
2304 |
+
|
2305 |
+
@app.post("/font")
|
2306 |
+
async def font_endpoint(font_request: FontRequest):
|
2307 |
+
fonts = {
|
2308 |
+
"typewriter": Fonts.typewriter,
|
2309 |
+
"outline": Fonts.outline,
|
2310 |
+
"serif": Fonts.serief,
|
2311 |
+
"bold_cool": Fonts.bold_cool,
|
2312 |
+
"cool": Fonts.cool,
|
2313 |
+
"small_cap": Fonts.smallcap,
|
2314 |
+
"script": Fonts.script,
|
2315 |
+
"bold_script": Fonts.bold_script,
|
2316 |
+
"tiny": Fonts.tiny,
|
2317 |
+
"comic": Fonts.comic,
|
2318 |
+
"san": Fonts.san,
|
2319 |
+
"slant_san": Fonts.slant_san,
|
2320 |
+
"slant": Fonts.slant,
|
2321 |
+
"sim": Fonts.sim,
|
2322 |
+
"circles": Fonts.circles,
|
2323 |
+
"dark_circle": Fonts.dark_circle,
|
2324 |
+
"gothic": Fonts.gothic,
|
2325 |
+
"bold_gothic": Fonts.bold_gothic,
|
2326 |
+
"cloud": Fonts.cloud,
|
2327 |
+
"happy": Fonts.happy,
|
2328 |
+
"sad": Fonts.sad,
|
2329 |
+
"special": Fonts.special,
|
2330 |
+
"square": Fonts.square,
|
2331 |
+
"dark_square": Fonts.dark_square,
|
2332 |
+
"andalucia": Fonts.andalucia,
|
2333 |
+
"manga": Fonts.manga,
|
2334 |
+
"stinky": Fonts.stinky,
|
2335 |
+
"bubbles": Fonts.bubbles,
|
2336 |
+
"underline": Fonts.underline,
|
2337 |
+
"ladybug": Fonts.ladybug,
|
2338 |
+
"rays": Fonts.rays,
|
2339 |
+
"birds": Fonts.birds,
|
2340 |
+
"slash": Fonts.slash,
|
2341 |
+
"stop": Fonts.stop,
|
2342 |
+
"skyline": Fonts.skyline,
|
2343 |
+
"arrows": Fonts.arrows,
|
2344 |
+
"rvnes": Fonts.rvnes,
|
2345 |
+
"strike": Fonts.strike,
|
2346 |
+
"frozen": Fonts.frozen
|
2347 |
+
}
|
2348 |
+
cls = fonts.get(font_request.style)
|
2349 |
+
if not cls:
|
2350 |
+
return {"error": "Invalid style"}
|
2351 |
+
new_text = cls(font_request.text)
|
2352 |
+
return {"new_text": new_text}
|
2353 |
+
|
2354 |
+
@app.post("/paste")
|
2355 |
+
async def paste_endpoint(paste_request: PasteRequest):
|
2356 |
+
paste_response = await p_paste(paste_request.text)
|
2357 |
+
return paste_response
|
2358 |
+
|
2359 |
+
async def p_paste(code, extension=None):
|
2360 |
+
siteurl = "https://pasty.lus.pm/api/v1/pastes"
|
2361 |
+
data = {"content": code}
|
2362 |
+
try:
|
2363 |
+
response = requests.post(url=siteurl, data=json.dumps(data), headers={"User-Agent": "Mozilla/5.0", "content-type": "application/json"})
|
2364 |
+
except Exception as e:
|
2365 |
+
return {"error": str(e)}
|
2366 |
+
if response.ok:
|
2367 |
+
response = response.json()
|
2368 |
+
purl = (
|
2369 |
+
f"https://pasty.lus.pm/{response['id']}.{extension}"
|
2370 |
+
if extension
|
2371 |
+
else f"https://pasty.lus.pm/{response['id']}.txt"
|
2372 |
+
)
|
2373 |
+
return {
|
2374 |
+
"url": purl,
|
2375 |
+
"raw": f"https://pasty.lus.pm/{response['id']}/raw",
|
2376 |
+
"bin": "Pasty",
|
2377 |
+
}
|
2378 |
+
return {"error": "Unable to reach pasty.lus.pm"}
|
2379 |
+
|
2380 |
+
@app.post("/share_text")
|
2381 |
+
async def share_text_endpoint(share_request: ShareTextRequest):
|
2382 |
+
share_url = f"https://t.me/share/url?url={quote(share_request.text)}"
|
2383 |
+
return {"share_url": share_url}
|
2384 |
+
|
2385 |
+
@app.post("/telegraph_upload")
|
2386 |
+
async def telegraph_upload_endpoint(upload_request: TelegraphUploadRequest):
|
2387 |
+
try:
|
2388 |
+
response = upload_file(upload_request.file_path)
|
2389 |
+
except Exception as e:
|
2390 |
+
logger.error(f"Error uploading to Telegraph: {e}")
|
2391 |
+
return {"error": str(e)}
|
2392 |
+
telegraph_url = f"https://graph.org{response[0]}"
|
2393 |
+
return {"telegraph_url": telegraph_url}
|
2394 |
+
|
2395 |
+
@app.post("/group_manager_action")
|
2396 |
+
async def group_manager_action_endpoint(action_request: GroupManagerAction):
|
2397 |
+
chat_id = action_request.group_id
|
2398 |
+
action = action_request.action
|
2399 |
+
user_id = action_request.user_id
|
2400 |
+
time_val = action_request.time
|
2401 |
+
|
2402 |
+
if action == "ban":
|
2403 |
+
await bot_instance.ban_chat_member(chat_id, user_id)
|
2404 |
+
return {"status": "User banned successfully"}
|
2405 |
+
elif action == "unban":
|
2406 |
+
await bot_instance.unban_chat_member(chat_id, user_id)
|
2407 |
+
return {"status": "User unbanned successfully"}
|
2408 |
+
elif action == "tban":
|
2409 |
+
until_date_val = extract_time(time_val)
|
2410 |
+
if until_date_val is None:
|
2411 |
+
return {"error": "Invalid time type specified. Expected m, h, or d, Got it: {time_val[-1]}"}
|
2412 |
+
await bot_instance.ban_chat_member(chat_id, user_id, until_date=until_date_val)
|
2413 |
+
return {"status": "User temporarily banned successfully"}
|
2414 |
+
elif action == "mute":
|
2415 |
+
|
2416 |
+
|
2417 |
+
|
2418 |
+
|
2419 |
+
|
2420 |
+
|
2421 |
+
|
2422 |
+
|
2423 |
+
|
2424 |
+
|
2425 |
+
|
2426 |
+
|
2427 |
+
|
2428 |
+
await bot_instance.restrict_chat_member(chat_id, user_id, permissions=enums.ChatPermissions())
|
2429 |
+
return {"status": "User muted successfully"}
|
2430 |
+
elif action == "unmute":
|
2431 |
+
await bot_instance.restrict_chat_member(chat_id, user_id, permissions=enums.ChatPermissions(can_send_messages=True))
|
2432 |
+
return {"status": "User unmuted successfully"}
|
2433 |
+
elif action == "tmute":
|
2434 |
+
until_date_val = extract_time(time_val)
|
2435 |
+
if until_date_val is None:
|
2436 |
+
return {"error": "Invalid time type specified. Expected m, h, or d, Got it: {time_val[-1]}"}
|
2437 |
+
await bot_instance.restrict_chat_member(chat_id, user_id, permissions=enums.ChatPermissions(), until_date=until_date_val)
|
2438 |
+
return {"status": "User temporarily muted successfully"}
|
2439 |
+
elif action == "pin":
|
2440 |
+
await bot_instance.pin_chat_message(chat_id, action_request.message_id)
|
2441 |
+
return {"status": "Message pinned successfully"}
|
2442 |
+
elif action == "unpin":
|
2443 |
+
await bot_instance.unpin_chat_message(chat_id, action_request.message_id)
|
2444 |
+
return {"status": "Message unpinned successfully"}
|
2445 |
+
elif action == "purge":
|
2446 |
+
if action_request.message_id:
|
2447 |
+
await purge_messages(bot_instance, chat_id, action_request.message_id)
|
2448 |
+
return {"status": "Messages purged successfully"}
|
2449 |
+
else:
|
2450 |
+
return {"error": "Message ID is required for purge action"}
|
2451 |
+
else:
|
2452 |
+
return {"error": "Invalid action"}
|
2453 |
+
|
2454 |
+
async def purge_messages(client, chat_id, message_id):
|
2455 |
+
try:
|
2456 |
+
message_ids = []
|
2457 |
+
count_del_etion_s = 0
|
2458 |
+
if message_id:
|
2459 |
+
for a_s_message_id in range(message_id, message_id + 100):
|
2460 |
+
message_ids.append(a_s_message_id)
|
2461 |
+
if len(message_ids) == 100:
|
2462 |
+
await client.delete_messages(chat_id=chat_id, message_ids=message_ids, revoke=True)
|
2463 |
+
count_del_etion_s += len(message_ids)
|
2464 |
+
message_ids = []
|
2465 |
+
if len(message_ids) > 0:
|
2466 |
+
await client.delete_messages(chat_id=chat_id, message_ids=message_ids, revoke=True)
|
2467 |
+
count_del_etion_s += len(message_ids)
|
2468 |
+
except Exception as e:
|
2469 |
+
logger.error(f"Error purging messages: {e}")
|
2470 |
+
return {"error": str(e)}
|
2471 |
+
|
2472 |
+
@app.post("/broadcast_messages")
|
2473 |
+
async def broadcast_messages_endpoint(user_id: int, message_id: int):
|
2474 |
+
b_msg = await bot_instance.get_messages(user_id, message_id)
|
2475 |
+
sts = await send_message(bot_instance, user_id, "Broadcasting your messages...")
|
2476 |
+
start_time = time.time()
|
2477 |
+
total_users = await db.total_users_count()
|
2478 |
+
done = 0
|
2479 |
+
blocked = 0
|
2480 |
+
deleted = 0
|
2481 |
+
failed = 0
|
2482 |
+
success = 0
|
2483 |
+
async for user in db.get_all_users():
|
2484 |
+
pti, sh = await broadcast_messages(int(user['id']), b_msg)
|
2485 |
+
if pti:
|
2486 |
+
success += 1
|
2487 |
+
elif pti == False:
|
2488 |
+
if sh == "Blocked":
|
2489 |
+
blocked += 1
|
2490 |
+
elif sh == "Deleted":
|
2491 |
+
deleted += 1
|
2492 |
+
elif sh == "Error":
|
2493 |
+
failed += 1
|
2494 |
+
done += 1
|
2495 |
+
if not done % 20:
|
2496 |
+
await edit_message(bot_instance, sts, f"Broadcast in progress:\n\nTotal Users {total_users}\nCompleted: {done} / {total_users}\nSuccess: {success}\nBlocked: {blocked}\nDeleted: {deleted}")
|
2497 |
+
time_taken = datetime.timedelta(seconds=int(time.time() - start_time))
|
2498 |
+
await delete_message(bot_instance, sts)
|
2499 |
+
await send_message(bot_instance, user_id, f"Broadcast completed:\nTime taken: {time_taken}\n\nTotal Users: {total_users}\nCompleted: {done} / {total_users}\nSuccess: {success}\nBlocked: {blocked}\nDeleted: {deleted}")
|
2500 |
+
return {"status": "Broadcast completed"}
|
2501 |
+
|
2502 |
+
async def broadcast_messages(user_id, message):
|
2503 |
+
try:
|
2504 |
+
await message.copy(chat_id=user_id)
|
2505 |
+
return True, "Success"
|
2506 |
+
except FloodWait as e:
|
2507 |
+
await asyncio.sleep(e.value)
|
2508 |
+
return await broadcast_messages(user_id, message)
|
2509 |
+
except InputUserDeactivated:
|
2510 |
+
await db.delete_user(int(user_id))
|
2511 |
+
logger.info(f"{user_id}-Removed from Database, since deleted account.")
|
2512 |
+
return False, "Deleted"
|
2513 |
+
except UserIsBlocked:
|
2514 |
+
logger.info(f"{user_id} -Blocked the bot.")
|
2515 |
+
return False, "Blocked"
|
2516 |
+
except PeerIdInvalid:
|
2517 |
+
await db.delete_user(int(user_id))
|
2518 |
+
logger.info(f"{user_id} - PeerIdInvalid")
|
2519 |
+
return False, "Error"
|
2520 |
+
except Exception as e:
|
2521 |
+
return False, "Error"
|
2522 |
+
|
2523 |
+
@app.post("/clear_junk")
|
2524 |
+
async def clear_junk_endpoint(user_id: int):
|
2525 |
+
sts = await send_message(bot_instance, user_id, "Clearing junk users...")
|
2526 |
+
start_time = time.time()
|
2527 |
+
total_users = await db.total_users_count()
|
2528 |
+
blocked = 0
|
2529 |
+
deleted = 0
|
2530 |
+
failed = 0
|
2531 |
+
done = 0
|
2532 |
+
async for user in db.get_all_users():
|
2533 |
+
pti, sh = await clear_junk(int(user['id']), None)
|
2534 |
+
if pti == False:
|
2535 |
+
if sh == "Blocked":
|
2536 |
+
blocked += 1
|
2537 |
+
elif sh == "Deleted":
|
2538 |
+
deleted += 1
|
2539 |
+
elif sh == "Error":
|
2540 |
+
failed += 1
|
2541 |
+
done += 1
|
2542 |
+
if not done % 20:
|
2543 |
+
await edit_message(bot_instance, sts, f"Clearing junk in progress:\n\nTotal Users {total_users}\nCompleted: {done} / {total_users}\nBlocked: {blocked}\nDeleted: {deleted}")
|
2544 |
+
time_taken = datetime.timedelta(seconds=int(time.time() - start_time))
|
2545 |
+
await delete_message(bot_instance, sts)
|
2546 |
+
await send_message(bot_instance, user_id, f"Clearing junk completed:\nTime taken: {time_taken}\n\nTotal Users: {total_users}\nCompleted: {done} / {total_users}\nBlocked: {blocked}\nDeleted: {deleted}")
|
2547 |
+
return {"status": "Junk clearing completed"}
|
2548 |
+
|
2549 |
+
async def clear_junk(user_id, message):
|
2550 |
+
try:
|
2551 |
+
key = await message.copy(chat_id=user_id)
|
2552 |
+
await key.delete(True)
|
2553 |
+
return True, "Success"
|
2554 |
+
except FloodWait as e:
|
2555 |
+
await asyncio.sleep(e.value)
|
2556 |
+
return await clear_junk(user_id, message)
|
2557 |
+
except InputUserDeactivated:
|
2558 |
+
await db.delete_user(int(user_id))
|
2559 |
+
logger.info(f"{user_id}-Removed from Database, since deleted account.")
|
2560 |
+
return False, "Deleted"
|
2561 |
+
except UserIsBlocked:
|
2562 |
+
logger.info(f"{user_id} -Blocked the bot.")
|
2563 |
+
return False, "Blocked"
|
2564 |
+
except PeerIdInvalid:
|
2565 |
+
await db.delete_user(int(user_id))
|
2566 |
+
logger.info(f"{user_id} - PeerIdInvalid")
|
2567 |
+
return False, "Error"
|
2568 |
+
except Exception as e:
|
2569 |
+
return False, "Error"
|
2570 |
+
|
2571 |
+
@app.post("/group_broadcast")
|
2572 |
+
async def group_broadcast_endpoint(user_id: int, message_id: int):
|
2573 |
+
groups = await db.get_all_chats()
|
2574 |
+
b_msg = await bot_instance.get_messages(user_id, message_id)
|
2575 |
+
sts = await send_message(bot_instance, user_id, "Broadcasting to groups...")
|
2576 |
+
start_time = time.time()
|
2577 |
+
total_groups = await db.total_chat_count()
|
2578 |
+
done = 0
|
2579 |
+
failed = ""
|
2580 |
+
success = 0
|
2581 |
+
deleted = 0
|
2582 |
+
async for group in groups:
|
2583 |
+
pti, sh, ex = await broadcast_messages_group(int(group['id']), b_msg)
|
2584 |
+
if pti == True:
|
2585 |
+
if sh == "Success":
|
2586 |
+
success += 1
|
2587 |
+
elif pti == False:
|
2588 |
+
if sh == "deleted":
|
2589 |
+
deleted += 1
|
2590 |
+
failed += ex
|
2591 |
+
try:
|
2592 |
+
await bot_instance.leave_chat(int(group['id']))
|
2593 |
+
except Exception as e:
|
2594 |
+
logger.error(f"{e} > {group['id']}")
|
2595 |
+
done += 1
|
2596 |
+
if not done % 20:
|
2597 |
+
await edit_message(bot_instance, sts, f"Broadcast in progress:\n\nTotal Groups {total_groups}\nCompleted: {done} / {total_groups}\nSuccess: {success}\nDeleted: {deleted}")
|
2598 |
+
time_taken = datetime.timedelta(seconds=int(time.time() - start_time))
|
2599 |
+
await delete_message(bot_instance, sts)
|
2600 |
+
await send_message(bot_instance, user_id, f"Broadcast completed:\nTime taken: {time_taken}\n\nTotal Groups: {total_groups}\nCompleted: {done} / {total_groups}\nSuccess: {success}\nDeleted: {deleted}\n\nFailed reasons: {failed}")
|
2601 |
+
return {"status": "Group broadcast completed"}
|
2602 |
+
|
2603 |
+
async def broadcast_messages_group(chat_id, message):
|
2604 |
+
try:
|
2605 |
+
await message.copy(chat_id=chat_id)
|
2606 |
+
return True, "Success", 'mm'
|
2607 |
+
except FloodWait as e:
|
2608 |
+
await asyncio.sleep(e.value)
|
2609 |
+
return await broadcast_messages_group(chat_id, message)
|
2610 |
+
except Exception as e:
|
2611 |
+
await db.delete_chat(int(chat_id))
|
2612 |
+
logger.info(f"{chat_id} - PeerIdInvalid")
|
2613 |
+
return False, "deleted", f'{e}\n\n'
|
2614 |
+
|
2615 |
+
@app.post("/junk_group")
|
2616 |
+
async def junk_group_endpoint(user_id: int):
|
2617 |
+
groups = await db.get_all_chats()
|
2618 |
+
sts = await send_message(bot_instance, user_id, "Clearing junk groups...")
|
2619 |
+
start_time = time.time()
|
2620 |
+
total_groups = await db.total_chat_count()
|
2621 |
+
done = 0
|
2622 |
+
failed = ""
|
2623 |
+
deleted = 0
|
2624 |
+
async for group in groups:
|
2625 |
+
pti, sh, ex = await junk_group(int(group['id']), None)
|
2626 |
+
if pti == False:
|
2627 |
+
if sh == "deleted":
|
2628 |
+
deleted += 1
|
2629 |
+
failed += ex
|
2630 |
+
try:
|
2631 |
+
await bot_instance.leave_chat(int(group['id']))
|
2632 |
+
except Exception as e:
|
2633 |
+
logger.error(f"{e} > {group['id']}")
|
2634 |
+
done += 1
|
2635 |
+
if not done % 20:
|
2636 |
+
await edit_message(bot_instance, sts, f"Clearing junk in progress:\n\nTotal Groups {total_groups}\nCompleted: {done} / {total_groups}\nDeleted: {deleted}")
|
2637 |
+
time_taken = datetime.timedelta(seconds=int(time.time() - start_time))
|
2638 |
+
await delete_message(bot_instance, sts)
|
2639 |
+
await send_message(bot_instance, user_id, f"Clearing junk completed:\nTime taken: {time_taken}\n\nTotal Groups: {total_groups}\nCompleted: {done} / {total_groups}\nDeleted: {deleted}\n\nFailed reasons: {failed}")
|
2640 |
+
return {"status": "Junk group clearing completed"}
|
2641 |
+
|
2642 |
+
async def junk_group(chat_id, message):
|
2643 |
+
try:
|
2644 |
+
kk = await message.copy(chat_id=chat_id)
|
2645 |
+
await kk.delete(True)
|
2646 |
+
return True, "Success", 'mm'
|
2647 |
+
except FloodWait as e:
|
2648 |
+
await asyncio.sleep(e.value)
|
2649 |
+
return await junk_group(chat_id, message)
|
2650 |
+
except Exception as e:
|
2651 |
+
await db.delete_chat(int(chat_id))
|
2652 |
+
logger.info(f"{chat_id} - PeerIdInvalid")
|
2653 |
+
return False, "deleted", f'{e}\n\n'
|
2654 |
+
|
2655 |
+
@app.post("/group_leave")
|
2656 |
+
async def group_leave_endpoint(chat_id: int):
|
2657 |
+
await bot_instance.leave_chat(chat_id)
|
2658 |
+
return {"status": "Left the group successfully"}
|
2659 |
+
|
2660 |
+
@app.post("/group_disable")
|
2661 |
+
async def group_disable_endpoint(chat_id: int, reason: str = "No Reason"):
|
2662 |
+
await db.disable_chat(chat_id, reason)
|
2663 |
+
temp.BANNED_CHATS.append(chat_id)
|
2664 |
+
return {"status": "Group disabled successfully"}
|
2665 |
+
|
2666 |
+
@app.post("/group_enable")
|
2667 |
+
async def group_enable_endpoint(chat_id: int):
|
2668 |
+
await db.re_enable_chat(chat_id)
|
2669 |
+
temp.BANNED_CHATS.remove(chat_id)
|
2670 |
+
return {"status": "Group enabled successfully"}
|
2671 |
+
|
2672 |
+
@app.post("/get_user_info")
|
2673 |
+
async def get_user_info_endpoint(user_id: int):
|
2674 |
+
user_info = await bot_instance.get_users(user_id)
|
2675 |
+
return {"user_info": user_info.dict()}
|
2676 |
+
|
2677 |
+
@app.post("/get_chat_info")
|
2678 |
+
async def get_chat_info_endpoint(chat_id: int):
|
2679 |
+
chat_info = await bot_instance.get_chat(chat_id)
|
2680 |
+
return {"chat_info": chat_info.dict()}
|
2681 |
+
|
2682 |
+
@app.post("/send_telegram_message")
|
2683 |
+
async def send_telegram_message_endpoint(chat_id: int, text: str):
|
2684 |
+
message = await send_message(bot_instance, chat_id, text)
|
2685 |
+
return {"message_id": message.id}
|
2686 |
+
|
2687 |
+
@app.post("/edit_telegram_message")
|
2688 |
+
async def edit_telegram_message_endpoint(chat_id: int, message_id: int, text: str):
|
2689 |
+
message = await bot_instance.get_messages(chat_id, message_id)
|
2690 |
+
edited_message = await edit_message(bot_instance, message, text)
|
2691 |
+
return {"edited_message_id": edited_message.id}
|
2692 |
+
|
2693 |
+
@app.post("/delete_telegram_message")
|
2694 |
+
async def delete_telegram_message_endpoint(chat_id: int, message_id: int):
|
2695 |
+
message = await bot_instance.get_messages(chat_id, message_id)
|
2696 |
+
await delete_message(bot_instance, message)
|
2697 |
+
return {"status": "Message deleted successfully"}
|
2698 |
+
|
2699 |
+
if __name__ == "__main__":
|
2700 |
+
import uvicorn
|
2701 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|