all repos — gif-escarbot @ ee6346e8b3bdbccc85a56a7d7888fb099792e410

Earthbound Café's custom delivery bot with other cool utilities built-in.

add feedback timeout
Marco Andronaco andronacomarco@gmail.com
Thu, 24 Aug 2023 15:40:53 +0200
commit

ee6346e8b3bdbccc85a56a7d7888fb099792e410

parent

57b5fda7ff40107b938dd90758a61bcda4866010

2 files changed, 10 insertions(+), 5 deletions(-)

jump to
M Config.pyConfig.py

@@ -5,9 +5,10 @@ load_dotenv()

logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) logging.getLogger("httpx").setLevel(logging.WARNING) - logger = logging.getLogger(__name__) + INLINE_SEP = 3 * "#" +FEEDBACK_TIMEOUT = getenv("feedback_timeout", 3) def config_error(): logger.error("Please create and fill the .env file.")
M Replacer.pyReplacer.py

@@ -1,6 +1,8 @@

from telegram import Update, InlineKeyboardMarkup, InlineKeyboardButton -from Config import INLINE_SEP +from telegram.constants import ParseMode +from Config import INLINE_SEP, FEEDBACK_TIMEOUT import logging, re, json +from asyncio import sleep logger = logging.getLogger(__name__) re_flags = re.I | re.M

@@ -16,7 +18,7 @@ "becomes": "https://fxtwitter.com/{}/status/{}",

}, ] -link_message = "[.]({})" +link_message = "Link di {}[\.]({})" def get_callback_data(feedback: bool) -> str: payload = { "feedback": feedback }

@@ -60,8 +62,10 @@ links = parse_text(update.message.caption)

for link in links: logger.info(link) - message = link_message.format(link) - await update.message.reply_text(message, parse_mode="markdown", reply_markup=get_message_markup()) + text = link_message.format(update.effective_user.mention_markdown_v2(), link) + message = await update.message.reply_text(text, parse_mode=ParseMode.MARKDOWN_V2) + await sleep(FEEDBACK_TIMEOUT) + await message.edit_reply_markup(reply_markup=get_message_markup()) async def feedback(update: Update, _, data_json: str) -> None: data = json.loads(data_json)