|
|
@@ -1,7 +1,8 @@
|
|
|
|
|
|
|
|
import html
|
|
|
|
from functools import wraps
|
|
|
|
from functools import wraps
|
|
|
|
|
|
|
|
|
|
|
|
from aiohttp import ClientSession
|
|
|
|
from aiohttp import ClientSession
|
|
|
|
from telegram import Update, Chat, InlineKeyboardMarkup, InlineKeyboardButton, ForceReply, Message
|
|
|
|
from telegram import Update, Chat, InlineKeyboardMarkup, InlineKeyboardButton, Message
|
|
|
|
from telegram.constants import ParseMode, ChatAction, ChatType
|
|
|
|
from telegram.constants import ParseMode, ChatAction, ChatType
|
|
|
|
from telegram.ext import (
|
|
|
|
from telegram.ext import (
|
|
|
|
Application,
|
|
|
|
Application,
|
|
|
@@ -55,8 +56,10 @@ async def url_media(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
|
|
|
url = tweet.url
|
|
|
|
url = tweet.url
|
|
|
|
if context.user_data.get('edit_before_forward', False):
|
|
|
|
if context.user_data.get('edit_before_forward', False):
|
|
|
|
message_reply = await update.effective_message.reply_text(
|
|
|
|
message_reply = await update.effective_message.reply_text(
|
|
|
|
"Reply to edit message.",
|
|
|
|
"Reply to edit message. [URL]",
|
|
|
|
reply_markup=ForceReply(selective=True, input_field_placeholder="{URL}"),
|
|
|
|
reply_markup=InlineKeyboardMarkup.from_button(
|
|
|
|
|
|
|
|
InlineKeyboardButton("↩️ Confirm", callback_data="forward")
|
|
|
|
|
|
|
|
),
|
|
|
|
reply_to_message_id=update.message.message_id,
|
|
|
|
reply_to_message_id=update.message.message_id,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
context.user_data['message_reply'] = message_reply
|
|
|
|
context.user_data['message_reply'] = message_reply
|
|
|
@@ -86,7 +89,7 @@ async def edit_message(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
|
|
|
|
return
|
|
|
|
return
|
|
|
|
if update.message.reply_to_message != context.user_data['message_reply']:
|
|
|
|
if update.message.reply_to_message != context.user_data['message_reply']:
|
|
|
|
return
|
|
|
|
return
|
|
|
|
update_text = update.message.text
|
|
|
|
update_text = html.escape(update.message.text)
|
|
|
|
match = common.message_url_regex.search(update_text)
|
|
|
|
match = common.message_url_regex.search(update_text)
|
|
|
|
if match:
|
|
|
|
if match:
|
|
|
|
match = match.span()
|
|
|
|
match = match.span()
|
|
|
@@ -94,19 +97,14 @@ async def edit_message(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
|
|
|
|
context.user_data['message_url'], update_text[match[0] + 1:match[1] - 1]
|
|
|
|
context.user_data['message_url'], update_text[match[0] + 1:match[1] - 1]
|
|
|
|
) + update_text[match[1]:]
|
|
|
|
) + update_text[match[1]:]
|
|
|
|
message_to_send = context.user_data['message_to_send']
|
|
|
|
message_to_send = context.user_data['message_to_send']
|
|
|
|
await message_to_send[0].edit_caption(
|
|
|
|
await message_to_send[0].edit_caption(update_text)
|
|
|
|
update_text,
|
|
|
|
|
|
|
|
reply_markup=InlineKeyboardMarkup.from_button(
|
|
|
|
|
|
|
|
InlineKeyboardButton("↩️ Confirm", callback_data="forward")
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def query_forward_message(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
|
|
|
async def query_forward_message(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
|
|
|
message_to_send = context.user_data['message_to_send']
|
|
|
|
message_to_send = context.user_data['message_to_send']
|
|
|
|
await forward_message(update, context, message_to_send)
|
|
|
|
await forward_message(update, context, message_to_send)
|
|
|
|
await update.callback_query.answer('✅ Forwarded')
|
|
|
|
await update.callback_query.answer('✅ Forwarded')
|
|
|
|
await update.callback_query.edit_message_reply_markup()
|
|
|
|
await update.callback_query.delete_message()
|
|
|
|
del context.user_data['message_reply']
|
|
|
|
del context.user_data['message_reply']
|
|
|
|
del context.user_data['message_to_send']
|
|
|
|
del context.user_data['message_to_send']
|
|
|
|
del context.user_data['message_url']
|
|
|
|
del context.user_data['message_url']
|
|
|
@@ -155,12 +153,20 @@ async def cmd_edit_before_forward(update: Update, context: ContextTypes.DEFAULT_
|
|
|
|
ebf_status = context.user_data.get('edit_before_forward', False)
|
|
|
|
ebf_status = context.user_data.get('edit_before_forward', False)
|
|
|
|
if ebf_status:
|
|
|
|
if ebf_status:
|
|
|
|
context.user_data['edit_before_forward'] = False
|
|
|
|
context.user_data['edit_before_forward'] = False
|
|
|
|
|
|
|
|
context.user_data.pop('message_reply', None)
|
|
|
|
|
|
|
|
context.user_data.pop('message_to_send', None)
|
|
|
|
|
|
|
|
context.user_data.pop('message_url', None)
|
|
|
|
await update.effective_message.reply_text("Disable edit before forward.")
|
|
|
|
await update.effective_message.reply_text("Disable edit before forward.")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
context.user_data['edit_before_forward'] = True
|
|
|
|
context.user_data['edit_before_forward'] = True
|
|
|
|
await update.effective_message.reply_text("Enable edit before forward.")
|
|
|
|
await update.effective_message.reply_text("Enable edit before forward.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@send_action(ChatAction.TYPING)
|
|
|
|
|
|
|
|
async def cmd_user_dict(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
|
|
|
|
|
|
|
await update.effective_message.reply_text(str(context.user_data))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def post_init(application: Application) -> None:
|
|
|
|
async def post_init(application: Application) -> None:
|
|
|
|
# commands = [
|
|
|
|
# commands = [
|
|
|
|
# BotCommand('start', CMD_START),
|
|
|
|
# BotCommand('start', CMD_START),
|
|
|
@@ -193,8 +199,8 @@ def main():
|
|
|
|
.build()
|
|
|
|
.build()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# user_filter = filters.User()
|
|
|
|
user_filter = filters.User()
|
|
|
|
# user_filter.add_user_ids(common.admin)
|
|
|
|
user_filter.add_user_ids(common.ADMIN)
|
|
|
|
|
|
|
|
|
|
|
|
handlers = [
|
|
|
|
handlers = [
|
|
|
|
MessageHandler(filters.Regex(common.x_url_regex) & filters.ChatType.PRIVATE, url_media),
|
|
|
|
MessageHandler(filters.Regex(common.x_url_regex) & filters.ChatType.PRIVATE, url_media),
|
|
|
@@ -204,6 +210,7 @@ def main():
|
|
|
|
CommandHandler("edit_before_forward", cmd_edit_before_forward),
|
|
|
|
CommandHandler("edit_before_forward", cmd_edit_before_forward),
|
|
|
|
MessageHandler(~filters.COMMAND & filters.ChatType.PRIVATE, edit_message),
|
|
|
|
MessageHandler(~filters.COMMAND & filters.ChatType.PRIVATE, edit_message),
|
|
|
|
CallbackQueryHandler(query_forward_message, pattern="forward"),
|
|
|
|
CallbackQueryHandler(query_forward_message, pattern="forward"),
|
|
|
|
|
|
|
|
CommandHandler("bot_dict", cmd_user_dict, filters=user_filter),
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
application.add_handlers(handlers)
|
|
|
|
application.add_handlers(handlers)
|
|
|
|