Python telegram.utils.helpers.mention_markdown() Examples
The following are 13
code examples of telegram.utils.helpers.mention_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: welcome.py From EmiliaHikari with GNU General Public License v3.0 | 6 votes |
def check_cas(bot: Bot, user_id, user, message): json = requests.get(CAS_URL, params={"user_id": str(user_id)}, timeout=(2, 5)).json() if json.get("ok"): if json["result"]["offenses"] > 0: is_success = False try: context.bot.kickChatMember(message.chat.id, user_id) is_success = True except: context.bot.sendMessage(message.chat.id, "*⚠️ WARNING!*\n{} is a spammer from [CAS ban](https://combot.org/cas/query?u={}) and has been added to fedban list of *Team Nusantara Disciplinary Circle*!\n\nIt's recommended to banned him/her!".format(mention_markdown(user_id, user.first_name), user_id), parse_mode="markdown", disable_web_page_preview=True) if is_success: context.bot.sendMessage(message.chat.id, "{} has been banned and added to fedban list of *Team Nusantara Disciplinary Circle*!\nReason: [CAS ban](https://combot.org/cas/query?u={}).".format(mention_markdown(user_id, user.first_name), user_id), parse_mode="markdown", disable_web_page_preview=True) fed_id = fedsql.get_fed_info("TeamNusantaraDevs") if fed_id: x = fedsql.fban_user("TeamNusantaraDevs", user_id, user.first_name, user.last_name, user.username, "CAS-Banned", int(time.time())) if not x: LOGGER.warning("Cannot fban spammer user!") return text = "*New FedBan*\n*Fed:* `TeamNusantaraDevs`\n*FedAdmin*: {}\n*User:* {}\n*User ID:* `{}`\n*Reason:* [CAS ban](https://combot.org/cas/query?u={})".format(mention_markdown(692882995, "Emilia"), mention_markdown(user_id, user.first_name + (" " + user.last_name if user.last_name != None else "")), user_id, user_id) context.bot.sendMessage(-1001338861977, text, parse_mode="markdown", disable_web_page_preview=True) print(">>> NEW FBAN CAS: {} {} in {}".format(user.first_name, user_id, message.chat.title))
Example #2
Source File: welcome.py From EmiliaHikari with GNU General Public License v3.0 | 6 votes |
def check_sw(bot: Bot, user_id, user, message): try: SWT = SPAMWATCH_TOKEN except: return False json = requests.get(SPAMWATCH_URL + str(user_id), headers={"Authorization": "Bearer {}".format(SWT)}).json() if json.get('code') == 404: return False is_success = False try: context.bot.kickChatMember(message.chat.id, user_id) is_success = True except: context.bot.sendMessage(message.chat.id, "*⚠️ WARNING!*\n{} is a spammer from SpamWatch and has been added to fedban list of *Team Nusantara Disciplinary Circle*!\n\nIt's recommended to banned him/her!".format(mention_markdown(user_id, user.first_name)), parse_mode="markdown", disable_web_page_preview=True) if is_success: context.bot.sendMessage(message.chat.id, "{} has been banned and added to fedban list of *Team Nusantara Disciplinary Circle*!\nReason: {}.".format(mention_markdown(user_id, user.first_name), json.get('reason') if json.get('reason') else "Unknown reason"), parse_mode="markdown", disable_web_page_preview=True) fed_id = fedsql.get_fed_info("TeamNusantaraDevs") if fed_id: x = fedsql.fban_user("TeamNusantaraDevs", user_id, user.first_name, user.last_name, user.username, json.get('reason') if json.get('reason') else "Unknown reason", int(time.time())) if not x: LOGGER.warning("Cannot fban spammer user!") return text = "*New FedBan*\n*Fed:* `TeamNusantaraDevs`\n*FedAdmin*: {}\n*User:* {}\n*User ID:* `{}`\n*Reason:* [SpamWatch] {}".format(mention_markdown(692882995, "Emilia"), mention_markdown(user_id, user.first_name + (" " + user.last_name if user.last_name != None else "")), user_id, json.get('reason') if json.get('reason') else "Unknown reason") context.bot.sendMessage(-1001338861977, text, parse_mode="markdown", disable_web_page_preview=True) print(">>> NEW FBAN SW: {} {} in {}".format(user.first_name, user_id, message.chat.title))
Example #3
Source File: misc.py From EmiliaHikari with GNU General Public License v3.0 | 5 votes |
def slap(update, context): args = context.args 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 = "{}".format(mention_markdown(msg.from_user.id, msg.from_user.first_name)) user_id = extract_user(update.effective_message, args) if user_id and user_id != "error": slapped_user = context.bot.get_chat(user_id) user1 = curr_user #if slapped_user.username: # user2 = "@" + escape_markdown(slapped_user.username) #else: user2 = "{}".format(mention_markdown(slapped_user.id, slapped_user.first_name)) # if no target found, bot targets the sender else: user1 = "{}".format(mention_markdown(context.bot.id, context.bot.first_name)) user2 = curr_user temp = random.choice(tl(update.effective_message, "SLAP_TEMPLATES")) item = random.choice(tl(update.effective_message, "ITEMS")) hit = random.choice(tl(update.effective_message, "HIT")) throw = random.choice(tl(update.effective_message, "THROW")) repl = temp.format(user1=user1, user2=user2, item=item, hits=hit, throws=throw) send_message(update.effective_message, repl, parse_mode=ParseMode.MARKDOWN)
Example #4
Source File: special.py From EmiliaHikari with GNU General Public License v3.0 | 5 votes |
def stickerid(update, context): msg = update.effective_message if msg.reply_to_message and msg.reply_to_message.sticker: send_message(update.effective_message, tl(update.effective_message, "Hai {}, Id stiker yang anda balas adalah :\n```{}```").format(mention_markdown(msg.from_user.id, msg.from_user.first_name), msg.reply_to_message.sticker.file_id), parse_mode=ParseMode.MARKDOWN) else: send_message(update.effective_message, tl(update.effective_message, "Tolong balas pesan stiker untuk mendapatkan id stiker"), parse_mode=ParseMode.MARKDOWN)
Example #5
Source File: user.py From telegram-robot-rss with Mozilla Public License 2.0 | 5 votes |
def mention_markdown(self, name=None): """ Args: name (:obj:`str`): If provided, will overwrite the user's name. Returns: :obj:`str`: The inline mention for the user as markdown. """ if not name: return util_mention_markdown(self.id, self.name) else: return util_mention_markdown(self.id, name)
Example #6
Source File: welcome.py From SkittBot with GNU General Public License v3.0 | 4 votes |
def left_member(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] should_goodbye, cust_goodbye, goodbye_type = sql.get_gdbye_pref(chat.id) if should_goodbye: left_mem = update.effective_message.left_chat_member if left_mem: # Ignore bot being kicked if left_mem.id == bot.id: return # Give the owner a special goodbye if left_mem.id == OWNER_ID: update.effective_message.reply_text("Cya Skittles!") return # if media goodbye, use appropriate function for it if goodbye_type != sql.Types.TEXT and goodbye_type != sql.Types.BUTTON_TEXT: ENUM_FUNC_MAP[goodbye_type](chat.id, cust_goodbye) return first_name = left_mem.first_name or "PersonWithNoName" # edge case of empty name - occurs for some bugs. if cust_goodbye: if left_mem.last_name: fullname = "{} {}".format(first_name, left_mem.last_name) else: fullname = first_name count = chat.get_members_count() mention = mention_markdown(left_mem.id, first_name) if left_mem.username: username = "@" + escape_markdown(left_mem.username) else: username = mention valid_format = escape_invalid_curly_brackets(cust_goodbye, VALID_WELCOME_FORMATTERS) res = valid_format.format(first=escape_markdown(first_name), last=escape_markdown(left_mem.last_name or first_name), fullname=escape_markdown(fullname), username=username, mention=mention, count=count, chatname=escape_markdown(chat.title), id=left_mem.id) buttons = sql.get_gdbye_buttons(chat.id) keyb = build_keyboard(buttons) else: res = sql.DEFAULT_GOODBYE keyb = [] keyboard = InlineKeyboardMarkup(keyb) send(update, res, keyboard, sql.DEFAULT_GOODBYE)
Example #7
Source File: blacklist.py From EmiliaHikari with GNU General Public License v3.0 | 4 votes |
def del_blacklist(update, context): chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] user = update.effective_user bot = context.bot to_match = extract_text(message) if not to_match: return getmode, value = sql.get_blacklist_setting(chat.id) chat_filters = sql.get_chat_blacklist(chat.id) for trigger in chat_filters: pattern = r"( |^|[^\w])" + re.escape(trigger) + r"( |$|[^\w])" if re.search(pattern, to_match, flags=re.IGNORECASE): try: if getmode == 0: return elif getmode == 1: message.delete() elif getmode == 2: message.delete() warn(update.effective_user, chat, tl(update.effective_message, "Mengatakan kata '{}' yang ada di daftar hitam").format(trigger), message, update.effective_user, conn=False) return elif getmode == 3: message.delete() bot.restrict_chat_member(chat.id, update.effective_user.id, can_send_messages=False) bot.sendMessage(chat.id, tl(update.effective_message, "{} di bisukan karena mengatakan kata '{}' yang ada di daftar hitam").format(mention_markdown(user.id, user.first_name), trigger), parse_mode="markdown") return elif getmode == 4: message.delete() res = chat.unban_member(update.effective_user.id) if res: bot.sendMessage(chat.id, tl(update.effective_message, "{} di tendang karena mengatakan kata '{}' yang ada di daftar hitam").format(mention_markdown(user.id, user.first_name), trigger), parse_mode="markdown") return elif getmode == 5: message.delete() chat.kick_member(user.id) bot.sendMessage(chat.id, tl(update.effective_message, "{} di blokir karena mengatakan kata '{}' yang ada di daftar hitam").format(mention_markdown(user.id, user.first_name), trigger), parse_mode="markdown") return elif getmode == 6: message.delete() bantime = extract_time(message, value) chat.kick_member(user.id, until_date=bantime) bot.sendMessage(chat.id, tl(update.effective_message, "{} di blokir selama {} karena mengatakan kata '{}' yang ada di daftar hitam").format(mention_markdown(user.id, user.first_name), value, trigger), parse_mode="markdown") return elif getmode == 7: message.delete() mutetime = extract_time(message, value) bot.restrict_chat_member(chat.id, user.id, until_date=mutetime, can_send_messages=False) bot.sendMessage(chat.id, tl(update.effective_message, "{} di bisukan selama {} karena mengatakan kata '{}' yang ada di daftar hitam").format(mention_markdown(user.id, user.first_name), value, trigger), parse_mode="markdown") return except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("Error while deleting blacklist message.") break
Example #8
Source File: reporting.py From EmiliaHikari with GNU General Public License v3.0 | 4 votes |
def buttonask(bot, update): query = update.callback_query splitter = query.data.replace("ak_", "").split("+") isyes = splitter[1].split('|')[0] report_chat = splitter[1].split('|')[1].split('=')[0] report_target = splitter[1].split('|')[1].split('=')[1] chat = update.effective_chat msg = CURRENT_REPORT.get(str(report_chat)) userinfo = CURRENT_REPORT.get(str(report_chat)+"user") key = CURRENT_REPORT.get(str(report_chat)+"key") if isyes == "y": a, b = user_protection_checker(context.bot, report_target) if not a: context.bot.edit_message_text(text=msg + b, chat_id=query.message.chat_id, message_id=query.message.message_id, parse_mode=ParseMode.HTML) return if splitter[0] == "1": try: context.bot.unbanChatMember(report_chat, report_target) context.bot.sendMessage(report_chat, text=tl(update.effective_message, "{} telah di tendang!\nOleh: {}").format(\ mention_markdown(userinfo['id'], userinfo['name']), mention_markdown(chat.id, chat.first_name)), \ parse_mode=ParseMode.MARKDOWN) context.bot.edit_message_text(text=msg + tl(update.effective_message, "\n\n{} telah di tendang!").format(mention_html(userinfo['id'], userinfo['name'])), chat_id=query.message.chat_id, message_id=query.message.message_id, parse_mode=ParseMode.HTML) except Exception as err: context.bot.edit_message_text(text=msg + "\n\nError: {}".format(err), chat_id=query.message.chat_id, message_id=query.message.message_id, parse_mode=ParseMode.HTML) elif splitter[0] == "2": try: context.bot.kickChatMember(report_chat, report_target) context.bot.sendMessage(report_chat, text=tl(update.effective_message, "{} telah di banned!\nOleh: {}").format(\ mention_markdown(userinfo['id'], userinfo['name']), mention_markdown(chat.id, chat.first_name)), \ parse_mode=ParseMode.MARKDOWN) context.bot.edit_message_text(text=msg + tl(update.effective_message, "\n\n{} telah di banned!").format(mention_html(userinfo['id'], userinfo['name'])), chat_id=query.message.chat_id, message_id=query.message.message_id, parse_mode=ParseMode.HTML) except Exception as err: context.bot.edit_message_text(text=msg + "\n\nError: {}".format(err), chat_id=query.message.chat_id, message_id=query.message.message_id, parse_mode=ParseMode.HTML) elif splitter[0] == "3": try: context.bot.deleteMessage(report_chat, report_target) context.bot.edit_message_text(text=msg + tl(update.effective_message, "\n\nPesan dihapus!"), chat_id=query.message.chat_id, message_id=query.message.message_id, parse_mode=ParseMode.HTML) except Exception as err: context.bot.edit_message_text(text=msg + "\n\nError: {}".format(err), chat_id=query.message.chat_id, message_id=query.message.message_id, parse_mode=ParseMode.HTML) elif isyes == "n": context.bot.edit_message_text(text=msg, chat_id=query.message.chat_id, message_id=query.message.message_id, parse_mode=ParseMode.HTML, reply_markup=key)
Example #9
Source File: feds.py From EmiliaHikari with GNU General Public License v3.0 | 4 votes |
def fed_broadcast(update, context): msg = update.effective_message # type: Optional[Message] user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] args = context.args if chat.type == 'private': send_message(update.effective_message, tl(update.effective_message, "Perintah ini di khususkan untuk grup, bukan pada PM!")) return if args: chat = update.effective_chat # type: Optional[Chat] fed_id = sql.get_fed_id(chat.id) fedinfo = sql.get_fed_info(fed_id) # Parsing md raw_text = msg.text args = raw_text.split(None, 1) # use python's maxsplit to separate cmd and args txt = args[1] offset = len(txt) - len(raw_text) # set correct offset relative to command text_parser = markdown_parser(txt, entities=msg.parse_entities(), offset=offset) text = text_parser try: broadcaster = user.first_name except: broadcaster = user.first_name + " " + user.last_name text += "\n\n- {}".format(mention_markdown(user.id, broadcaster)) chat_list = sql.all_fed_chats(fed_id) failed = 0 for chat in chat_list: title = tl(chat, "*Siaran baru dari Federasi {}*\n").format(fedinfo['fname']) try: context.bot.sendMessage(chat, title + text, parse_mode="markdown") except TelegramError: try: dispatcher.bot.getChat(chat) except Unauthorized: failed += 1 sql.chat_leave_fed(chat) LOGGER.info("Chat {} has leave fed {} because bot is kicked".format(chat, fedinfo['fname'])) continue failed += 1 LOGGER.warning("Couldn't send broadcast to {}".format(str(chat))) send_text = tl(update.effective_message, "Siaran Federasi selesai.") if failed >= 1: send_text += tl(update.effective_message, "{} grup gagal menerima pesan, mungkin karena meninggalkan federasi.").format(failed) send_message(update.effective_message, send_text)
Example #10
Source File: blstickers.py From EmiliaHikari with GNU General Public License v3.0 | 4 votes |
def del_blackliststicker(update, context): chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] user = update.effective_user to_match = message.sticker if not to_match: return getmode, value = sql.get_blacklist_setting(chat.id) chat_filters = sql.get_chat_stickers(chat.id) for trigger in chat_filters: if to_match.set_name.lower() == trigger.lower(): try: if getmode == 0: return elif getmode == 1: message.delete() elif getmode == 2: message.delete() warn(update.effective_user, chat, tl(update.effective_message, "Menggunakan stiker '{}' yang ada di daftar hitam stiker").format(trigger), message, update.effective_user, conn=False) return elif getmode == 3: message.delete() bot.restrict_chat_member(chat.id, update.effective_user.id, can_send_messages=False) bot.sendMessage(chat.id, tl(update.effective_message, "{} di bisukan karena menggunakan stiker '{}' yang ada di daftar hitam stiker").format(mention_markdown(user.id, user.first_name), trigger), parse_mode="markdown") return elif getmode == 4: message.delete() res = chat.unban_member(update.effective_user.id) if res: bot.sendMessage(chat.id, tl(update.effective_message, "{} di tendang karena menggunakan stiker '{}' yang ada di daftar hitam stiker").format(mention_markdown(user.id, user.first_name), trigger), parse_mode="markdown") return elif getmode == 5: message.delete() chat.kick_member(user.id) bot.sendMessage(chat.id, tl(update.effective_message, "{} di blokir karena menggunakan stiker '{}' yang ada di daftar hitam stiker").format(mention_markdown(user.id, user.first_name), trigger), parse_mode="markdown") return elif getmode == 6: message.delete() bantime = extract_time(message, value) chat.kick_member(user.id, until_date=bantime) bot.sendMessage(chat.id, tl(update.effective_message, "{} di blokir selama {} karena menggunakan stiker '{}' yang ada di daftar hitam stiker").format(mention_markdown(user.id, user.first_name), value, trigger), parse_mode="markdown") return elif getmode == 7: message.delete() mutetime = extract_time(message, value) bot.restrict_chat_member(chat.id, user.id, until_date=mutetime, can_send_messages=False) bot.sendMessage(chat.id, tl(update.effective_message, "{} di bisukan selama {} karena menggunakan stiker '{}' yang ada di daftar hitam stiker").format(mention_markdown(user.id, user.first_name), value, trigger), parse_mode="markdown") return except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("Error while deleting blacklist message.") break
Example #11
Source File: welcome.py From Marie-2.0-English with GNU General Public License v3.0 | 4 votes |
def left_member(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] should_goodbye, cust_goodbye, goodbye_type = sql.get_gdbye_pref(chat.id) if should_goodbye: left_mem = update.effective_message.left_chat_member if left_mem: # Ignore bot being kicked if left_mem.id == bot.id: return # Give the owner a special goodbye if left_mem.id == OWNER_ID: update.effective_message.reply_text("RIP Master") return # if media goodbye, use appropriate function for it if goodbye_type != sql.Types.TEXT and goodbye_type != sql.Types.BUTTON_TEXT: ENUM_FUNC_MAP[goodbye_type](chat.id, cust_goodbye) return first_name = left_mem.first_name or "PersonWithNoName" # edge case of empty name - occurs for some bugs. if cust_goodbye: if left_mem.last_name: fullname = "{} {}".format(first_name, left_mem.last_name) else: fullname = first_name count = chat.get_members_count() mention = mention_markdown(left_mem.id, first_name) if left_mem.username: username = "@" + escape_markdown(left_mem.username) else: username = mention valid_format = escape_invalid_curly_brackets(cust_goodbye, VALID_WELCOME_FORMATTERS) res = valid_format.format(first=escape_markdown(first_name), last=escape_markdown(left_mem.last_name or first_name), fullname=escape_markdown(fullname), username=username, mention=mention, count=count, chatname=escape_markdown(chat.title), id=left_mem.id) buttons = sql.get_gdbye_buttons(chat.id) keyb = build_keyboard(buttons) else: res = sql.DEFAULT_GOODBYE keyb = [] keyboard = InlineKeyboardMarkup(keyb) send(update, res, keyboard, sql.DEFAULT_GOODBYE) delete_join(bot, update)
Example #12
Source File: welcome.py From tgbot with GNU General Public License v3.0 | 4 votes |
def left_member(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] should_goodbye, cust_goodbye, goodbye_type = sql.get_gdbye_pref(chat.id) if should_goodbye: left_mem = update.effective_message.left_chat_member if left_mem: # Ignore bot being kicked if left_mem.id == bot.id: return # Give the owner a special goodbye if left_mem.id == OWNER_ID: update.effective_message.reply_text("RIP Master") return # if media goodbye, use appropriate function for it if goodbye_type != sql.Types.TEXT and goodbye_type != sql.Types.BUTTON_TEXT: ENUM_FUNC_MAP[goodbye_type](chat.id, cust_goodbye) return first_name = left_mem.first_name or "PersonWithNoName" # edge case of empty name - occurs for some bugs. if cust_goodbye: if left_mem.last_name: fullname = "{} {}".format(first_name, left_mem.last_name) else: fullname = first_name count = chat.get_members_count() mention = mention_markdown(left_mem.id, first_name) if left_mem.username: username = "@" + escape_markdown(left_mem.username) else: username = mention valid_format = escape_invalid_curly_brackets(cust_goodbye, VALID_WELCOME_FORMATTERS) res = valid_format.format(first=escape_markdown(first_name), last=escape_markdown(left_mem.last_name or first_name), fullname=escape_markdown(fullname), username=username, mention=mention, count=count, chatname=escape_markdown(chat.title), id=left_mem.id) buttons = sql.get_gdbye_buttons(chat.id) keyb = build_keyboard(buttons) else: res = sql.DEFAULT_GOODBYE keyb = [] keyboard = InlineKeyboardMarkup(keyb) send(update, res, keyboard, sql.DEFAULT_GOODBYE)
Example #13
Source File: main.py From telegram-group-easyauth with GNU General Public License v3.0 | 4 votes |
def admin(update, context): callback_query = update.callback_query user = callback_query.from_user message = callback_query.message chat = message.chat if user.id not in get_chat_admins( context.bot, chat.id, extra_user=context.bot_data.get("config").get("SUPER_ADMIN"), ): callback_query.answer( text=context.bot_data.get("config").get("OTHER"), show_alert=True, ) return result, user_id = parse_callback(context, callback_query.data) cqconf = ( context.bot_data.get("config").get("PASS_BTN") if result else context.bot_data.get("config").get("KICK_BTN") ) conf = ( context.bot_data.get("config").get("ADMIN_PASS") if result else context.bot_data.get("config").get("ADMIN_KICK") ) callback_query.answer( text=cqconf, show_alert=False, ) if result: restore(context, chat.id, user_id) for job in context.job_queue.get_jobs_by_name( f"{chat.id}|{user_id}|clean_join" ): job.schedule_removal() else: kick(context, chat.id, user_id) message.edit_text( escape_markdown(conf).format( admin=user.mention_markdown_v2(), user=mention_markdown(user_id, str(user_id), version=2), ), parse_mode=ParseMode.MARKDOWN_V2, ) for job in context.job_queue.get_jobs_by_name(f"{chat.id}|{user_id}|kick"): job.schedule_removal()