Python telegram.utils.helpers.escape_markdown() Examples
The following are 30
code examples of telegram.utils.helpers.escape_markdown().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
telegram.utils.helpers
, or try the search function
.
Example #1
Source File: notes.py From tgbot with GNU General Public License v3.0 | 6 votes |
def list_notes(bot: Bot, update: Update): chat_id = update.effective_chat.id note_list = sql.get_all_chat_notes(chat_id) msg = "*Notes in chat:*\n" for note in note_list: note_name = escape_markdown(" - {}\n".format(note.name)) if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name if msg == "*Notes in chat:*\n": update.effective_message.reply_text("No notes in this chat!") elif len(msg) != 0: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN)
Example #2
Source File: userinfo.py From Marie-2.0-English with GNU General Public License v3.0 | 6 votes |
def about_bio(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id = extract_user(message, args) if user_id: user = bot.get_chat(user_id) else: user = message.from_user info = sql.get_user_bio(user.id) if info: update.effective_message.reply_text("*{}*:\n{}".format(user.first_name, escape_markdown(info)), parse_mode=ParseMode.MARKDOWN) elif message.reply_to_message: username = user.first_name update.effective_message.reply_text("{} No details about him have been added yet !".format(username)) else: update.effective_message.reply_text(" Your information about you has been added !")
Example #3
Source File: userinfo.py From tgbot with GNU General Public License v3.0 | 6 votes |
def about_bio(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id = extract_user(message, args) if user_id: user = bot.get_chat(user_id) else: user = message.from_user info = sql.get_user_bio(user.id) if info: update.effective_message.reply_text("*{}*:\n{}".format(user.first_name, escape_markdown(info)), parse_mode=ParseMode.MARKDOWN) elif message.reply_to_message: username = user.first_name update.effective_message.reply_text("{} hasn't had a message set about themselves yet!".format(username)) else: update.effective_message.reply_text("You haven't had a bio set about yourself yet!")
Example #4
Source File: userinfo.py From tgbot with GNU General Public License v3.0 | 6 votes |
def about_me(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id = extract_user(message, args) if user_id: user = bot.get_chat(user_id) else: user = message.from_user info = sql.get_user_me_info(user.id) if info: update.effective_message.reply_text("*{}*:\n{}".format(user.first_name, escape_markdown(info)), parse_mode=ParseMode.MARKDOWN) elif message.reply_to_message: username = message.reply_to_message.from_user.first_name update.effective_message.reply_text(username + " hasn't set an info message about themselves yet!") else: update.effective_message.reply_text("You haven't set an info message about yourself yet!")
Example #5
Source File: cust_filters.py From SkittBot with GNU General Public License v3.0 | 6 votes |
def list_handlers(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] all_handlers = sql.get_chat_triggers(chat.id) if not all_handlers: update.effective_message.reply_text("No filters are active here!") return filter_list = BASIC_FILTER_STRING for keyword in all_handlers: entry = " - {}\n".format(escape_markdown(keyword)) if len(entry) + len(filter_list) > telegram.MAX_MESSAGE_LENGTH: update.effective_message.reply_text(filter_list, parse_mode=telegram.ParseMode.MARKDOWN) filter_list = entry else: filter_list += entry if not filter_list == BASIC_FILTER_STRING: update.effective_message.reply_text(filter_list, parse_mode=telegram.ParseMode.MARKDOWN) # NOT ASYNC BECAUSE DISPATCHER HANDLER RAISED
Example #6
Source File: cust_filters.py From tgbot with GNU General Public License v3.0 | 6 votes |
def list_handlers(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] all_handlers = sql.get_chat_triggers(chat.id) if not all_handlers: update.effective_message.reply_text("No filters are active here!") return filter_list = BASIC_FILTER_STRING for keyword in all_handlers: entry = " - {}\n".format(escape_markdown(keyword)) if len(entry) + len(filter_list) > telegram.MAX_MESSAGE_LENGTH: update.effective_message.reply_text(filter_list, parse_mode=telegram.ParseMode.MARKDOWN) filter_list = entry else: filter_list += entry if not filter_list == BASIC_FILTER_STRING: update.effective_message.reply_text(filter_list, parse_mode=telegram.ParseMode.MARKDOWN) # NOT ASYNC BECAUSE DISPATCHER HANDLER RAISED
Example #7
Source File: userinfo.py From SkittBot with GNU General Public License v3.0 | 6 votes |
def about_me(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id = extract_user(message, args) if user_id: user = bot.get_chat(user_id) else: user = message.from_user info = sql.get_user_me_info(user.id) if info: update.effective_message.reply_text("*{}*:\n{}".format(user.first_name, escape_markdown(info)), parse_mode=ParseMode.MARKDOWN) elif message.reply_to_message: username = message.reply_to_message.from_user.first_name update.effective_message.reply_text(username + " hasn't set an info message about themselves yet!") else: update.effective_message.reply_text("You haven't set an info message about yourself yet!")
Example #8
Source File: userinfo.py From SkittBot with GNU General Public License v3.0 | 6 votes |
def about_bio(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id = extract_user(message, args) if user_id: user = bot.get_chat(user_id) else: user = message.from_user info = sql.get_user_bio(user.id) if info: update.effective_message.reply_text("*{}*:\n{}".format(user.first_name, escape_markdown(info)), parse_mode=ParseMode.MARKDOWN) elif message.reply_to_message: username = user.first_name update.effective_message.reply_text("{} hasn't had a message set about themselves yet!".format(username)) else: update.effective_message.reply_text("You haven't had a bio set about yourself yet!")
Example #9
Source File: userinfo.py From EmiliaHikari with GNU General Public License v3.0 | 6 votes |
def about_me(update, context): message = update.effective_message # type: Optional[Message] args = context.args user_id = extract_user(message, args) if user_id and user_id != "error": user = bot.get_chat(user_id) else: user = message.from_user info = sql.get_user_me_info(user.id) if info: send_message(update.effective_message, "*{}*:\n{}".format(user.first_name, escape_markdown(info)), parse_mode=ParseMode.MARKDOWN) elif message.reply_to_message: username = message.reply_to_message.from_user.first_name send_message(update.effective_message, username + tl(update.effective_message, " belum mengatur pesan info tentang diri mereka!")) else: send_message(update.effective_message, tl(update.effective_message, "Anda belum mengatur pesan info tentang diri Anda!"))
Example #10
Source File: misc.py From SkittBot with GNU General Public License v3.0 | 6 votes |
def get_id(bot: Bot, update: Update, args: List[str]): user_id = extract_user(update.effective_message, args) if user_id: if update.effective_message.reply_to_message and update.effective_message.reply_to_message.forward_from: user1 = update.effective_message.reply_to_message.from_user user2 = update.effective_message.reply_to_message.forward_from update.effective_message.reply_text( "The original sender, {}, has an ID of `{}`.\nThe forwarder, {}, has an ID of `{}`.".format( escape_markdown(user2.first_name), user2.id, escape_markdown(user1.first_name), user1.id), parse_mode=ParseMode.MARKDOWN) else: user = bot.get_chat(user_id) update.effective_message.reply_text("{}'s id is `{}`.".format(escape_markdown(user.first_name), user.id), parse_mode=ParseMode.MARKDOWN) else: chat = update.effective_chat # type: Optional[Chat] if chat.type == "private": update.effective_message.reply_text("Your id is `{}`.".format(chat.id), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text("This group's id is `{}`.".format(chat.id), parse_mode=ParseMode.MARKDOWN)
Example #11
Source File: userinfo.py From Marie-2.0-English with GNU General Public License v3.0 | 6 votes |
def about_me(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id = extract_user(message, args) if user_id: user = bot.get_chat(user_id) else: user = message.from_user info = sql.get_user_me_info(user.id) if info: update.effective_message.reply_text("*{}*:\n{}".format(user.first_name, escape_markdown(info)), parse_mode=ParseMode.MARKDOWN) elif message.reply_to_message: username = message.reply_to_message.from_user.first_name update.effective_message.reply_text(username + "Information about him is currently unavailable !") else: update.effective_message.reply_text("You have not added any information about yourself yet !")
Example #12
Source File: notes.py From SkittBot with GNU General Public License v3.0 | 6 votes |
def list_notes(bot: Bot, update: Update): chat_id = update.effective_chat.id note_list = sql.get_all_chat_notes(chat_id) msg = "*Notes in chat:*\n" for note in note_list: note_name = escape_markdown(" - {}\n".format(note.name)) if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name if msg == "*Notes in chat:*\n": update.effective_message.reply_text("No notes in this chat!") elif len(msg) != 0: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN)
Example #13
Source File: userinfo.py From EmiliaHikari with GNU General Public License v3.0 | 6 votes |
def about_bio(update, context): message = update.effective_message # type: Optional[Message] args = context.args user_id = extract_user(message, args) if user_id and user_id != "error": user = bot.get_chat(user_id) else: user = message.from_user info = sql.get_user_bio(user.id) if info: send_message(update.effective_message, "*{}*:\n{}".format(user.first_name, escape_markdown(info)), parse_mode=ParseMode.MARKDOWN) elif message.reply_to_message: username = user.first_name send_message(update.effective_message, tl(update.effective_message, "{} belum memiliki pesan tentang dirinya sendiri!").format(username)) else: send_message(update.effective_message, tl(update.effective_message, "Anda belum memiliki bio set tentang diri Anda!"))
Example #14
Source File: misc.py From Marie-2.0-English with GNU General Public License v3.0 | 5 votes |
def slap(bot: Bot, update: Update, args: List[str]): msg = update.effective_message # type: Optional[Message] # reply to correct message reply_text = msg.reply_to_message.reply_text if msg.reply_to_message else msg.reply_text # get user who sent message if msg.from_user.username: curr_user = "@" + escape_markdown(msg.from_user.username) else: curr_user = "[{}](tg://user?id={})".format(msg.from_user.first_name, msg.from_user.id) user_id = extract_user(update.effective_message, args) if user_id: slapped_user = bot.get_chat(user_id) user1 = curr_user if slapped_user.username: user2 = "@" + escape_markdown(slapped_user.username) else: user2 = "[{}](tg://user?id={})".format(slapped_user.first_name, slapped_user.id) # if no target found, bot targets the sender else: user1 = "[{}](tg://user?id={})".format(bot.first_name, bot.id) user2 = curr_user temp = random.choice(SLAP_TEMPLATES) item = random.choice(ITEMS) hit = random.choice(HIT) throw = random.choice(THROW) repl = temp.format(user1=user1, user2=user2, item=item, hits=hit, throws=throw) reply_text(repl, parse_mode=ParseMode.MARKDOWN)
Example #15
Source File: disable.py From Marie-2.0-English with GNU General Public License v3.0 | 5 votes |
def list_cmds(bot: Bot, update: Update): if DISABLE_CMDS + DISABLE_OTHER: result = "" for cmd in set(DISABLE_CMDS + DISABLE_OTHER): result += " - `{}`\n".format(escape_markdown(cmd)) update.effective_message.reply_text("The following commands are toggleable:\n{}".format(result), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text("No commands can be disabled.") # do not async
Example #16
Source File: cust_filters.py From Marie-2.0-English with GNU General Public License v3.0 | 5 votes |
def list_handlers(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id, need_admin=False) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title filter_list = "*Filters in {}:*\n" else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "local filters" filter_list = "*local filters:*\n" else: chat_name = chat.title filter_list = "*Filters in {}*:\n" all_handlers = sql.get_chat_triggers(chat_id) if not all_handlers: update.effective_message.reply_text("No filters in {}!".format(chat_name)) return for keyword in all_handlers: entry = " - {}\n".format(escape_markdown(keyword)) if len(entry) + len(filter_list) > telegram.MAX_MESSAGE_LENGTH: update.effective_message.reply_text(filter_list, parse_mode=telegram.ParseMode.MARKDOWN) filter_list = entry else: filter_list += entry if not filter_list == BASIC_FILTER_STRING: update.effective_message.reply_text(filter_list, parse_mode=telegram.ParseMode.MARKDOWN) # NOT ASYNC BECAUSE DISPATCHER HANDLER RAISED
Example #17
Source File: disable.py From Marie-2.0-English with GNU General Public License v3.0 | 5 votes |
def build_curr_disabled(chat_id: Union[str, int]) -> str: disabled = sql.get_all_disabled(chat_id) if not disabled: return "No commands are disabled!" result = "" for cmd in disabled: result += " - `{}`\n".format(escape_markdown(cmd)) return "The following commands are currently restricted:\n{}".format(result)
Example #18
Source File: __main__.py From SkittBot with GNU General Public License v3.0 | 5 votes |
def start(bot: Bot, update: Update, args: List[str]): if update.effective_chat.type == "private": if len(args) >= 1: if args[0].lower() == "help": send_help(update.effective_chat.id, HELP_STRINGS) elif args[0].lower().startswith("stngs_"): match = re.match("stngs_(.*)", args[0].lower()) chat = dispatcher.bot.getChat(match.group(1)) if is_user_admin(chat, update.effective_user.id): send_settings(match.group(1), update.effective_user.id, False) else: send_settings(match.group(1), update.effective_user.id, True) elif args[0][1:].isdigit() and "rules" in IMPORTED: IMPORTED["rules"].send_rules(update, args[0], from_pm=True) else: first_name = update.effective_user.first_name update.effective_message.reply_text( PM_START_TEXT.format(escape_markdown(first_name), escape_markdown(bot.first_name), OWNER_ID), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text("Heck, I'm alive :O") # for test purposes
Example #19
Source File: misc.py From Marie-2.0-English with GNU General Public License v3.0 | 5 votes |
def stickerid(bot: Bot, update: Update): msg = update.effective_message if msg.reply_to_message and msg.reply_to_message.sticker: update.effective_message.reply_text("Hello " + "[{}](tg://user?id={})".format(msg.from_user.first_name, msg.from_user.id) + ", The sticker id you are replying is :\n```" + escape_markdown(msg.reply_to_message.sticker.file_id) + "```", parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text("Hello " + "[{}](tg://user?id={})".format(msg.from_user.first_name, msg.from_user.id) + ", Please reply to sticker message to get id sticker", parse_mode=ParseMode.MARKDOWN)
Example #20
Source File: notes.py From Marie-2.0-English with GNU General Public License v3.0 | 5 votes |
def list_notes(bot: Bot, update: Update): chat_id = update.effective_chat.id chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id, need_admin=False) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title msg = "*Notes in {}:*\n" else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "" msg = "*Local Notes:*\n" else: chat_name = chat.title msg = "*Notes in {}:*\n" note_list = sql.get_all_chat_notes(chat_id) for note in note_list: note_name = escape_markdown(" - {}\n".format(note.name)) if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name if msg == "*Notes in chat:*\n": update.effective_message.reply_text("No notes in this chat!") elif len(msg) != 0: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN)
Example #21
Source File: __main__.py From tgbot with GNU General Public License v3.0 | 5 votes |
def start(bot: Bot, update: Update, args: List[str]): if update.effective_chat.type == "private": if len(args) >= 1: if args[0].lower() == "help": send_help(update.effective_chat.id, HELP_STRINGS) elif args[0].lower().startswith("stngs_"): match = re.match("stngs_(.*)", args[0].lower()) chat = dispatcher.bot.getChat(match.group(1)) if is_user_admin(chat, update.effective_user.id): send_settings(match.group(1), update.effective_user.id, False) else: send_settings(match.group(1), update.effective_user.id, True) elif args[0][1:].isdigit() and "rules" in IMPORTED: IMPORTED["rules"].send_rules(update, args[0], from_pm=True) else: first_name = update.effective_user.first_name update.effective_message.reply_text( PM_START_TEXT.format(escape_markdown(first_name), escape_markdown(bot.first_name), OWNER_ID), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text("Yo, whadup?") # for test purposes
Example #22
Source File: log_channel.py From tgbot with GNU General Public License v3.0 | 5 votes |
def logging(bot: Bot, update: Update): message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] log_channel = sql.get_chat_log_channel(chat.id) if log_channel: log_channel_info = bot.get_chat(log_channel) message.reply_text( "This group has all it's logs sent to: {} (`{}`)".format(escape_markdown(log_channel_info.title), log_channel), parse_mode=ParseMode.MARKDOWN) else: message.reply_text("No log channel has been set for this group!")
Example #23
Source File: log_channel.py From tgbot with GNU General Public License v3.0 | 5 votes |
def __chat_settings__(chat_id, user_id): log_channel = sql.get_chat_log_channel(chat_id) if log_channel: log_channel_info = dispatcher.bot.get_chat(log_channel) return "This group has all it's logs sent to: {} (`{}`)".format(escape_markdown(log_channel_info.title), log_channel) return "No log channel is set for this group!"
Example #24
Source File: disable.py From tgbot with GNU General Public License v3.0 | 5 votes |
def list_cmds(bot: Bot, update: Update): if DISABLE_CMDS + DISABLE_OTHER: result = "" for cmd in set(DISABLE_CMDS + DISABLE_OTHER): result += " - `{}`\n".format(escape_markdown(cmd)) update.effective_message.reply_text("The following commands are toggleable:\n{}".format(result), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text("No commands can be disabled.") # do not async
Example #25
Source File: disable.py From tgbot with GNU General Public License v3.0 | 5 votes |
def build_curr_disabled(chat_id: Union[str, int]) -> str: disabled = sql.get_all_disabled(chat_id) if not disabled: return "No commands are disabled!" result = "" for cmd in disabled: result += " - `{}`\n".format(escape_markdown(cmd)) return "The following commands are currently restricted:\n{}".format(result)
Example #26
Source File: misc.py From tgbot with GNU General Public License v3.0 | 5 votes |
def slap(bot: Bot, update: Update, args: List[str]): msg = update.effective_message # type: Optional[Message] # reply to correct message reply_text = msg.reply_to_message.reply_text if msg.reply_to_message else msg.reply_text # get user who sent message if msg.from_user.username: curr_user = "@" + escape_markdown(msg.from_user.username) else: curr_user = "[{}](tg://user?id={})".format(msg.from_user.first_name, msg.from_user.id) user_id = extract_user(update.effective_message, args) if user_id: slapped_user = bot.get_chat(user_id) user1 = curr_user if slapped_user.username: user2 = "@" + escape_markdown(slapped_user.username) else: user2 = "[{}](tg://user?id={})".format(slapped_user.first_name, slapped_user.id) # if no target found, bot targets the sender else: user1 = "[{}](tg://user?id={})".format(bot.first_name, bot.id) user2 = curr_user temp = random.choice(SLAP_TEMPLATES) item = random.choice(ITEMS) hit = random.choice(HIT) throw = random.choice(THROW) repl = temp.format(user1=user1, user2=user2, item=item, hits=hit, throws=throw) reply_text(repl, parse_mode=ParseMode.MARKDOWN)
Example #27
Source File: admin.py From tgbot with GNU General Public License v3.0 | 5 votes |
def adminlist(bot: Bot, update: Update): administrators = update.effective_chat.get_administrators() text = "Admins in *{}*:".format(update.effective_chat.title or "this chat") for admin in administrators: user = admin.user name = "[{}](tg://user?id={})".format(user.first_name + (user.last_name or ""), user.id) if user.username: name = escape_markdown("@" + user.username) text += "\n - {}".format(name) update.effective_message.reply_text(text, parse_mode=ParseMode.MARKDOWN)
Example #28
Source File: snippets.py From AmbroBot with GNU General Public License v3.0 | 5 votes |
def _article(id, title, text, parse_mode=ParseMode.MARKDOWN): reply_text = f"*» {title}*\n{escape_markdown(text)}" try: msg = InputTextMessageContent(reply_text, parse_mode=parse_mode) except Exception: logger.error(text) return InlineQueryResultArticle( id=id, title=f'{title}', description='Code snippets', input_message_content=msg, )
Example #29
Source File: inlinequeries.py From rules-bot with GNU Affero General Public License v3.0 | 5 votes |
def fuzzy_replacements_markdown(query, threshold=95, official_api_links=True): """ Replaces the enclosed characters in the query string with hyperlinks to the documentations """ symbols = re.findall(ENCLOSED_REGEX, query) if not symbols: return None, None replacements = list() for s in symbols: # Wiki first, cause with docs you can always prepend telegram. for better precision wiki = search.wiki(s.replace('_', ' '), amount=1, threshold=threshold) if wiki: name = wiki[0][0].split(ARROW_CHARACTER)[-1].strip() text = f'[{name}]({wiki[0][1]})' replacements.append((wiki[0][0], s, text)) continue doc = search.docs(s, threshold=threshold) if doc: text = f'[{doc.short_name}]({doc.url})' if doc.tg_url and official_api_links: text += f' [{TELEGRAM_SUPERSCRIPT}]({doc.tg_url})' replacements.append((doc.short_name, s, text)) continue # not found replacements.append((s + '❓', s, escape_markdown(s))) result = query for name, symbol, text in replacements: char = ENCLOSING_REPLACEMENT_CHARACTER result = result.replace(f'{char}{symbol}{char}', text) result_changed = [x[0] for x in replacements] return result_changed, result
Example #30
Source File: log_channel.py From SkittBot with GNU General Public License v3.0 | 5 votes |
def logging(bot: Bot, update: Update): message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] log_channel = sql.get_chat_log_channel(chat.id) if log_channel: log_channel_info = bot.get_chat(log_channel) message.reply_text( "This group has all it's logs sent to: {} (`{}`)".format(escape_markdown(log_channel_info.title), log_channel), parse_mode=ParseMode.MARKDOWN) else: message.reply_text("No log channel has been set for this group!")