本文整理匯總了Python中telegram.utils.helpers.escape_markdown方法的典型用法代碼示例。如果您正苦於以下問題:Python helpers.escape_markdown方法的具體用法?Python helpers.escape_markdown怎麽用?Python helpers.escape_markdown使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類telegram.utils.helpers
的用法示例。
在下文中一共展示了helpers.escape_markdown方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: list_handlers
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import escape_markdown [as 別名]
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
示例2: about_me
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import escape_markdown [as 別名]
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!")
示例3: about_bio
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import escape_markdown [as 別名]
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!")
示例4: list_notes
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import escape_markdown [as 別名]
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)
示例5: about_me
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import escape_markdown [as 別名]
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!"))
示例6: about_bio
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import escape_markdown [as 別名]
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!"))
示例7: about_me
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import escape_markdown [as 別名]
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 !")
示例8: about_bio
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import escape_markdown [as 別名]
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 !")
示例9: fuzzy_replacements_markdown
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import escape_markdown [as 別名]
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
示例10: start
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import escape_markdown [as 別名]
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
示例11: logging
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import escape_markdown [as 別名]
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!")
示例12: __chat_settings__
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import escape_markdown [as 別名]
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!"
示例13: list_cmds
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import escape_markdown [as 別名]
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
示例14: build_curr_disabled
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import escape_markdown [as 別名]
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)
示例15: get_paste_content
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import escape_markdown [as 別名]
def get_paste_content(bot: Bot, update: Update, args: List[str]):
message = update.effective_message
if len(args) >= 1:
key = args[0]
else:
message.reply_text("Please supply a paste key!")
return
format_normal = f'{BASE_URL}/'
format_view = f'{BASE_URL}/v/'
if key.startswith(format_view):
key = key[len(format_view):]
elif key.startswith(format_normal):
key = key[len(format_normal):]
r = requests.get(f'{BASE_URL}/raw/{key}')
if r.status_code != 200:
try:
res = r.json()
update.effective_message.reply_text(res['message'])
except Exception:
if r.status_code == 404:
update.effective_message.reply_text('Failed to reach dogbin')
else:
update.effective_message.reply_text('Unknown error occured')
r.raise_for_status()
update.effective_message.reply_text('```' + escape_markdown(r.text) + '```', parse_mode=ParseMode.MARKDOWN)