Spaces:
Running
Running
File size: 9,906 Bytes
29b5c59 1a1e2eb 1fa270a 3a67739 1fa270a 9a92ff5 746a920 3a67739 1a1e2eb 9a92ff5 1a1e2eb 8359204 9a92ff5 1a1e2eb 3a67739 1a1e2eb 9a92ff5 1fa270a 9a92ff5 d3ac0b2 9a92ff5 3a67739 1a1e2eb 7c1069f 1fa270a 1a1e2eb 3a67739 1a1e2eb d3ac0b2 1fa270a 1a1e2eb 3a67739 1a1e2eb 1fa270a 1a1e2eb 3a67739 1a1e2eb d3ac0b2 1fa270a 1a1e2eb 3a67739 1a1e2eb 1fa270a 1a1e2eb 3a67739 1a1e2eb 1fa270a 1a1e2eb d3ac0b2 1fa270a 1a1e2eb 7ff1595 1fa270a 7ff1595 1a1e2eb 3a67739 1fa270a 7ff1595 3a67739 7ff1595 3a67739 1fa270a 3a67739 1fa270a 1a1e2eb d3ac0b2 1fa270a 1a1e2eb 3a67739 1a1e2eb 1fa270a 1a1e2eb d3ac0b2 | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | # Thunder/bot/plugins/callbacks.py
import asyncio
from pyrogram import Client, filters
from pyrogram.errors import FloodWait, MessageNotModified, MessageDeleteForbidden
from pyrogram.types import (CallbackQuery, InlineKeyboardButton,
InlineKeyboardMarkup)
from Thunder.bot import StreamBot
from Thunder.utils.broadcast import broadcast_ids
from Thunder.utils.decorators import owner_only
from Thunder.utils.logger import logger
from Thunder.utils.messages import (
MSG_ABOUT, MSG_BROADCAST_CANCEL, MSG_BUTTON_ABOUT, MSG_BUTTON_CLOSE,
MSG_BUTTON_GET_HELP, MSG_BUTTON_GITHUB, MSG_BUTTON_JOIN_CHANNEL,
MSG_ERROR_BROADCAST_INSTRUCTION, MSG_ERROR_BROADCAST_RESTART,
MSG_ERROR_CALLBACK_UNSUPPORTED, MSG_HELP
)
from Thunder.vars import Var
async def get_force_channel_button(client: Client):
if not Var.FORCE_CHANNEL_ID:
return None
try:
try:
chat = await client.get_chat(Var.FORCE_CHANNEL_ID)
except FloodWait as e:
await asyncio.sleep(e.value)
chat = await client.get_chat(Var.FORCE_CHANNEL_ID)
if chat:
invite_link = chat.invite_link or (f"https://t.me/{chat.username}" if chat.username else None)
if invite_link:
return [InlineKeyboardButton(
MSG_BUTTON_JOIN_CHANNEL.format(channel_title=chat.title or "Channel"),
url=invite_link
)]
except Exception as e:
logger.error(f"Error getting force channel button: {e}", exc_info=True)
return None
@StreamBot.on_callback_query(filters.regex(r"^help_command$"))
async def help_callback(client: Client, callback_query: CallbackQuery):
try:
await callback_query.answer()
buttons = [[InlineKeyboardButton(MSG_BUTTON_ABOUT, callback_data="about_command")]]
force_button = await get_force_channel_button(client)
if force_button:
buttons.append(force_button)
buttons.append([InlineKeyboardButton(MSG_BUTTON_CLOSE, callback_data="close_panel")])
try:
await callback_query.message.edit_text(
text=MSG_HELP.format(max_files=Var.MAX_BATCH_FILES),
reply_markup=InlineKeyboardMarkup(buttons),
disable_web_page_preview=True
)
except FloodWait as e:
await asyncio.sleep(e.value)
await callback_query.message.edit_text(
text=MSG_HELP.format(max_files=Var.MAX_BATCH_FILES),
reply_markup=InlineKeyboardMarkup(buttons),
disable_web_page_preview=True
)
except MessageNotModified:
pass
except Exception as e:
logger.error(f"Error in help callback: {e}", exc_info=True)
try:
await callback_query.answer("An error occurred. Please try again.", show_alert=True)
except FloodWait as e:
await asyncio.sleep(e.value)
await callback_query.answer("An error occurred. Please try again.", show_alert=True)
@StreamBot.on_callback_query(filters.regex(r"^about_command$"))
async def about_callback(client: Client, callback_query: CallbackQuery):
try:
await callback_query.answer()
buttons = [
[InlineKeyboardButton(MSG_BUTTON_GET_HELP, callback_data="help_command")],
[
InlineKeyboardButton(MSG_BUTTON_GITHUB, url="https://github.com/fyaz05/FileToLink"),
InlineKeyboardButton(MSG_BUTTON_CLOSE, callback_data="close_panel")
]
]
try:
await callback_query.message.edit_text(
text=MSG_ABOUT,
reply_markup=InlineKeyboardMarkup(buttons),
disable_web_page_preview=True
)
except FloodWait as e:
await asyncio.sleep(e.value)
await callback_query.message.edit_text(
text=MSG_ABOUT,
reply_markup=InlineKeyboardMarkup(buttons),
disable_web_page_preview=True
)
except MessageNotModified:
pass
except Exception as e:
logger.error(f"Error in about callback: {e}", exc_info=True)
try:
await callback_query.answer("An error occurred. Please try again.", show_alert=True)
except FloodWait as e:
await asyncio.sleep(e.value)
await callback_query.answer("An error occurred. Please try again.", show_alert=True)
@StreamBot.on_callback_query(filters.regex(r"^restart_broadcast$"))
async def restart_broadcast_callback(client: Client, callback_query: CallbackQuery):
if not await owner_only(client, callback_query):
return
try:
try:
await callback_query.answer(MSG_ERROR_BROADCAST_RESTART, show_alert=True)
except FloodWait as e:
await asyncio.sleep(e.value)
await callback_query.answer(MSG_ERROR_BROADCAST_RESTART, show_alert=True)
buttons = [
[
InlineKeyboardButton(MSG_BUTTON_GET_HELP, callback_data="help_command"),
InlineKeyboardButton(MSG_BUTTON_CLOSE, callback_data="close_panel")
]
]
try:
await callback_query.message.edit_text(
MSG_ERROR_BROADCAST_INSTRUCTION,
reply_markup=InlineKeyboardMarkup(buttons),
disable_web_page_preview=True
)
except FloodWait as e:
await asyncio.sleep(e.value)
await callback_query.message.edit_text(
MSG_ERROR_BROADCAST_INSTRUCTION,
reply_markup=InlineKeyboardMarkup(buttons),
disable_web_page_preview=True
)
except Exception as e:
logger.error(f"Error in restart broadcast callback: {e}", exc_info=True)
try:
await callback_query.answer("An error occurred. Please try again.", show_alert=True)
except FloodWait as e:
await asyncio.sleep(e.value)
await callback_query.answer("An error occurred. Please try again.", show_alert=True)
@StreamBot.on_callback_query(filters.regex(r"^close_panel$"))
async def close_panel_callback(client: Client, callback_query: CallbackQuery):
try:
try:
await callback_query.answer()
except FloodWait as e:
await asyncio.sleep(e.value)
await callback_query.answer()
try:
try:
await callback_query.message.delete()
except FloodWait as e:
await asyncio.sleep(e.value)
await callback_query.message.delete()
except MessageDeleteForbidden:
logger.debug(f"Failed to delete callback query message due to permissions. Message ID: {callback_query.message.id}")
except Exception as e:
logger.error(f"Error deleting callback query message: {e}", exc_info=True)
if callback_query.message.reply_to_message:
try:
reply_msg = callback_query.message.reply_to_message
try:
await reply_msg.delete()
except FloodWait as e:
await asyncio.sleep(e.value)
await reply_msg.delete()
except MessageDeleteForbidden:
logger.debug(f"Failed to delete replied message due to permissions. Message ID: {reply_msg.id}")
except Exception as e:
logger.error(f"Error deleting replied message: {e}", exc_info=True)
except Exception as e:
logger.error(f"General error in close panel callback: {e}", exc_info=True)
@StreamBot.on_callback_query(filters.regex(r"^cancel_"))
async def cancel_broadcast(client: Client, callback_query: CallbackQuery):
try:
broadcast_id = callback_query.data.split("_")[1]
if broadcast_id in broadcast_ids:
broadcast_ids[broadcast_id]["cancelled"] = True
try:
await callback_query.message.edit_text(
MSG_BROADCAST_CANCEL.format(broadcast_id=broadcast_id)
)
except FloodWait as e:
await asyncio.sleep(e.value)
await callback_query.message.edit_text(
MSG_BROADCAST_CANCEL.format(broadcast_id=broadcast_id)
)
else:
try:
await callback_query.answer(
MSG_BROADCAST_CANCEL.format(broadcast_id=broadcast_id),
show_alert=True
)
except FloodWait as e:
await asyncio.sleep(e.value)
await callback_query.answer(
MSG_BROADCAST_CANCEL.format(broadcast_id=broadcast_id),
show_alert=True
)
except Exception as e:
logger.error(f"Error in cancel broadcast callback: {e}", exc_info=True)
try:
await callback_query.answer("An error occurred. Please try again.", show_alert=True)
except FloodWait as e:
await asyncio.sleep(e.value)
await callback_query.answer("An error occurred. Please try again.", show_alert=True)
@StreamBot.on_callback_query()
async def fallback_callback(client: Client, callback_query: CallbackQuery):
try:
try:
await callback_query.answer(MSG_ERROR_CALLBACK_UNSUPPORTED, show_alert=True)
except FloodWait as e:
await asyncio.sleep(e.value)
await callback_query.answer(MSG_ERROR_CALLBACK_UNSUPPORTED, show_alert=True)
except Exception as e:
logger.error(f"Error in fallback callback: {e}", exc_info=True)
|