kb Posted May 9 Share Posted May 9 Use this script however you want. Source code of main.py import config, re from aiogram import Bot, Dispatcher, executor from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton num_regex = r"\d+" regex = r"\[\d+\]" bot = Bot(config.BOT_TOKEN) dp = Dispatcher(bot) watch_board = InlineKeyboardMarkup() watch_board.add(InlineKeyboardButton(text=config.BUTTON_TEXT, callback_data="to_watch")) async def add_user(calldata): text_list = calldata.message.text.split("\n") calldata.message.text = "" for i in text_list: is_user = bool(len(re.findall(regex, i))) if is_user: calldata.message.text += f'<a href="tg://user?id={re.findall(num_regex, re.findall(regex, i)[-1])[0]}">{i}</a>' + "\n" else: calldata.message.text += i + "\n" calldata.message.text += f'<a href="tg://user?id={calldata.from_user.id}">@{calldata.from_user.first_name}[{calldata.from_user.id}]</a>' + "\n" return calldata async def remove_user(calldata): text_list = calldata.message.text.split("\n") calldata.message.text = "" if len(text_list) > 4: for i in text_list: if str(calldata.from_user.id) not in i: is_user = bool(len(re.findall(regex, i))) if is_user: calldata.message.text += f'<a href="tg://user?id={re.findall(num_regex, re.findall(regex, i)[-1])[0]}">{i}</a>' + "\n" else: calldata.message.text += i + "\n" else: calldata.message.text = text_list[0] return calldata @dp.callback_query_handler() async def query_handler(calldata): if calldata.data == "to_watch": if config.TEXT_APPEND not in calldata.message.text: calldata.message.text = f"""{config.TEXT} {config.TEXT_APPEND}""" if str(calldata.from_user.id) not in calldata.message.text: calldata = await add_user(calldata) await calldata.message.edit_text(calldata.message.text, parse_mode="html", reply_markup=watch_board) else: calldata = await remove_user(calldata) await calldata.message.edit_text(calldata.message.text, parse_mode="html", reply_markup=watch_board) executor.start_polling(dp) hour_message.py for cron import telebot, config, asyncio from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton watch_board = InlineKeyboardMarkup() watch_board.add(InlineKeyboardButton(text=config.BUTTON_TEXT, callback_data="to_watch")) bot = telebot.TeleBot(config.BOT_TOKEN) bot.send_message(config.CHAT_ID, config.TEXT, reply_markup=watch_board) And config.py BOT_TOKEN = "" CHAT_ID = -1001881205544 TEXT = "Your custom text for message default edit" TEXT_APPEND = "First click on button (first edit) text" BUTTON_TEXT = "Inline button text" ## DO NOT TOUCH for i in [[BOT_TOKEN, "Bot Token"], [CHAT_ID, "Chat ID"], [TEXT, "Text"], [TEXT_APPEND, "Text Append"], [BUTTON_TEXT, "Button Text"]]: if i[0] == None: raise Exception(f"{i[1]} is not defined.") proj.rar 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts