本文整理匯總了Python中telegram.utils.helpers.mention_html方法的典型用法代碼示例。如果您正苦於以下問題:Python helpers.mention_html方法的具體用法?Python helpers.mention_html怎麽用?Python helpers.mention_html使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類telegram.utils.helpers
的用法示例。
在下文中一共展示了helpers.mention_html方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: set_warn_limit
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import mention_html [as 別名]
def set_warn_limit(bot: Bot, update: Update, args: List[str]) -> str:
chat = update.effective_chat # type: Optional[Chat]
user = update.effective_user # type: Optional[User]
msg = update.effective_message # type: Optional[Message]
if args:
if args[0].isdigit():
if int(args[0]) < 3:
msg.reply_text("The minimum warn limit is 3!")
else:
sql.set_warn_limit(chat.id, int(args[0]))
msg.reply_text("Updated the warn limit to {}".format(args[0]))
return "<b>{}:</b>" \
"\n#SET_WARN_LIMIT" \
"\n<b>Admin:</b> {}" \
"\nSet the warn limit to <code>{}</code>".format(html.escape(chat.title),
mention_html(user.id, user.first_name), args[0])
else:
msg.reply_text("Give me a number as an arg!")
else:
limit, soft_warn = sql.get_warn_setting(chat.id)
msg.reply_text("The current warn limit is {}".format(limit))
return ""
示例2: pin
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import mention_html [as 別名]
def pin(bot: Bot, update: Update, args: List[str]) -> str:
user = update.effective_user # type: Optional[User]
chat = update.effective_chat # type: Optional[Chat]
is_group = chat.type != "private" and chat.type != "channel"
prev_message = update.effective_message.reply_to_message
is_silent = True
if len(args) >= 1:
is_silent = not (args[0].lower() == 'notify' or args[0].lower() == 'loud' or args[0].lower() == 'violent')
if prev_message and is_group:
try:
bot.pinChatMessage(chat.id, prev_message.message_id, disable_notification=is_silent)
except BadRequest as excp:
if excp.message == "Chat_not_modified":
pass
else:
raise
return "<b>{}:</b>" \
"\n#PINNED" \
"\n<b>Admin:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name))
return ""
示例3: unpin
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import mention_html [as 別名]
def unpin(bot: Bot, update: Update) -> str:
chat = update.effective_chat
user = update.effective_user # type: Optional[User]
try:
bot.unpinChatMessage(chat.id)
except BadRequest as excp:
if excp.message == "Chat_not_modified":
pass
else:
raise
return "<b>{}:</b>" \
"\n#UNPINNED" \
"\n<b>Admin:</b> {}".format(html.escape(chat.title),
mention_html(user.id, user.first_name))
示例4: button
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import mention_html [as 別名]
def button(bot: Bot, update: Update) -> str:
query = update.callback_query # type: Optional[CallbackQuery]
user = update.effective_user # type: Optional[User]
match = re.match(r"rm_warn\((.+?)\)", query.data)
if match:
user_id = match.group(1)
chat = update.effective_chat # type: Optional[Chat]
res = sql.remove_warn(user_id, chat.id)
if res:
update.effective_message.edit_text(
"Warn removed by {}.".format(mention_html(user.id, user.first_name)),
parse_mode=ParseMode.HTML)
user_member = chat.get_member(user_id)
return "<b>{}:</b>" \
"\n#UNWARN" \
"\n<b>Admin:</b> {}" \
"\n<b>User:</b> {}".format(html.escape(chat.title),
mention_html(user.id, user.first_name),
mention_html(user_member.user.id, user_member.user.first_name))
else:
update.effective_message.edit_text(
"User has already has no warns.".format(mention_html(user.id, user.first_name)),
parse_mode=ParseMode.HTML)
return ""
示例5: reset_warns
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import mention_html [as 別名]
def reset_warns(bot: Bot, update: Update, args: List[str]) -> str:
message = update.effective_message # type: Optional[Message]
chat = update.effective_chat # type: Optional[Chat]
user = update.effective_user # type: Optional[User]
user_id = extract_user(message, args)
if user_id:
sql.reset_warns(user_id, chat.id)
message.reply_text("Warnings have been reset!")
warned = chat.get_member(user_id).user
return "<b>{}:</b>" \
"\n#RESETWARNS" \
"\n<b>Admin:</b> {}" \
"\n<b>User:</b> {}".format(html.escape(chat.title),
mention_html(user.id, user.first_name),
mention_html(warned.id, warned.first_name))
else:
message.reply_text("No user has been designated!")
return ""
示例6: reset_warns
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import mention_html [as 別名]
def reset_warns(bot: Bot, update: Update, args: List[str]) -> str:
message = update.effective_message # type: Optional[Message]
chat = update.effective_chat # type: Optional[Chat]
user = update.effective_user # type: Optional[User]
user_id = extract_user(message, args)
if user_id:
sql.reset_warns(user_id, chat.id)
message.reply_text("Warnings have been reset!")
warned = chat.get_member(user_id).user
return "<b>{}:</b>" \
"\n#RESETWARNS" \
"\n<b>Admin:</b> {}" \
"\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title),
mention_html(user.id, user.first_name),
mention_html(warned.id, warned.first_name),
warned.id)
else:
message.reply_text("No user has been designated!")
return ""
示例7: mute
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import mention_html [as 別名]
def mute(bot: Bot, update: Update, args: List[str]) -> str:
chat = update.effective_chat # type: Optional[Chat]
user = update.effective_user # type: Optional[User]
message = update.effective_message # type: Optional[Message]
user_id = extract_user(message, args)
if not user_id:
message.reply_text("You'll need to either give me a username to mute, or reply to someone to be muted.")
return ""
if user_id == bot.id:
message.reply_text("I'm not muting myself!")
return ""
member = chat.get_member(int(user_id))
if member:
if is_user_admin(chat, user_id, member=member):
message.reply_text("Afraid I can't stop an admin from talking!")
elif member.can_send_messages is None or member.can_send_messages:
bot.restrict_chat_member(chat.id, user_id, can_send_messages=False)
message.reply_text("Shush!")
return "<b>{}:</b>" \
"\n#MUTE" \
"\n<b>Admin:</b> {}" \
"\n<b>User:</b> {}".format(html.escape(chat.title),
mention_html(user.id, user.first_name),
mention_html(member.user.id, member.user.first_name))
else:
message.reply_text("This user is already muted!")
else:
message.reply_text("This user isn't in the chat!")
return ""
示例8: unmute
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import mention_html [as 別名]
def unmute(bot: Bot, update: Update, args: List[str]) -> str:
chat = update.effective_chat # type: Optional[Chat]
user = update.effective_user # type: Optional[User]
message = update.effective_message # type: Optional[Message]
user_id = extract_user(message, args)
if not user_id:
message.reply_text("You'll need to either give me a username to unmute, or reply to someone to be unmuted.")
return ""
member = chat.get_member(int(user_id))
if member:
if is_user_admin(chat, user_id, member=member):
message.reply_text("This is an admin, what do you expect me to do?")
return ""
elif member.status != 'kicked' and member.status != 'left':
if member.can_send_messages and member.can_send_media_messages \
and member.can_send_other_messages and member.can_add_web_page_previews:
message.reply_text("This user already has the right to speak.")
return ""
else:
bot.restrict_chat_member(chat.id, int(user_id),
can_send_messages=True,
can_send_media_messages=True,
can_send_other_messages=True,
can_add_web_page_previews=True)
message.reply_text("Unmuted!")
return "<b>{}:</b>" \
"\n#UNMUTE" \
"\n<b>Admin:</b> {}" \
"\n<b>User:</b> {}".format(html.escape(chat.title),
mention_html(user.id, user.first_name),
mention_html(member.user.id, member.user.first_name))
else:
message.reply_text("This user isn't even in the chat, unmuting them won't make them talk more than they "
"already do!")
return ""
示例9: button
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import mention_html [as 別名]
def button(bot: Bot, update: Update) -> str:
query = update.callback_query # type: Optional[CallbackQuery]
user = update.effective_user # type: Optional[User]
match = re.match(r"rm_warn\((.+?)\)", query.data)
if match:
user_id = match.group(1)
chat = update.effective_chat # type: Optional[Chat]
res = sql.remove_warn(user_id, chat.id)
if res:
update.effective_message.edit_text(
"Warn removed by {}.".format(mention_html(user.id, user.first_name)),
parse_mode=ParseMode.HTML)
user_member = chat.get_member(user_id)
return "<b>{}:</b>" \
"\n#UNWARN" \
"\n<b>Admin:</b> {}" \
"\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title),
mention_html(user.id, user.first_name),
mention_html(user_member.user.id, user_member.user.first_name),
user_member.user.id)
else:
update.effective_message.edit_text(
"User has already has no warns.".format(mention_html(user.id, user.first_name)),
parse_mode=ParseMode.HTML)
return ""
示例10: set_warn_strength
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import mention_html [as 別名]
def set_warn_strength(bot: Bot, update: Update, args: List[str]):
chat = update.effective_chat # type: Optional[Chat]
user = update.effective_user # type: Optional[User]
msg = update.effective_message # type: Optional[Message]
if args:
if args[0].lower() in ("on", "yes"):
sql.set_warn_strength(chat.id, False)
msg.reply_text("Too many warns will now result in a ban!")
return "<b>{}:</b>\n" \
"<b>Admin:</b> {}\n" \
"Has enabled strong warns. Users will be banned.".format(html.escape(chat.title),
mention_html(user.id, user.first_name))
elif args[0].lower() in ("off", "no"):
sql.set_warn_strength(chat.id, True)
msg.reply_text("Too many warns will now result in a kick! Users will be able to join again after.")
return "<b>{}:</b>\n" \
"<b>Admin:</b> {}\n" \
"Has disabled strong warns. Users will only be kicked.".format(html.escape(chat.title),
mention_html(user.id,
user.first_name))
else:
msg.reply_text("I only understand on/yes/no/off!")
else:
limit, soft_warn = sql.get_warn_setting(chat.id)
if soft_warn:
msg.reply_text("Warns are currently set to *kick* users when they exceed the limits.",
parse_mode=ParseMode.MARKDOWN)
else:
msg.reply_text("Warns are currently set to *ban* users when they exceed the limits.",
parse_mode=ParseMode.MARKDOWN)
return ""
示例11: check_flood
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import mention_html [as 別名]
def check_flood(bot: Bot, update: Update) -> str:
user = update.effective_user # type: Optional[User]
chat = update.effective_chat # type: Optional[Chat]
msg = update.effective_message # type: Optional[Message]
if not user: # ignore channels
return ""
# ignore admins
if is_user_admin(chat, user.id):
sql.update_flood(chat.id, None)
return ""
should_ban = sql.update_flood(chat.id, user.id)
if not should_ban:
return ""
try:
chat.kick_member(user.id)
msg.reply_text("I like to leave the flooding to natural disasters. But you, you were just a "
"disappointment. Get out.")
return "<b>{}:</b>" \
"\n#BANNED" \
"\n<b>User:</b> {}" \
"\nFlooded the group.".format(html.escape(chat.title),
mention_html(user.id, user.first_name))
except BadRequest:
msg.reply_text("I can't kick people here, give me permissions first! Until then, I'll disable antiflood.")
sql.set_flood(chat.id, 0)
return "<b>{}:</b>" \
"\n#INFO" \
"\nDon't have kick permissions, so automatically disabled antiflood.".format(chat.title)
示例12: set_flood
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import mention_html [as 別名]
def set_flood(bot: Bot, update: Update, args: List[str]) -> str:
chat = update.effective_chat # type: Optional[Chat]
user = update.effective_user # type: Optional[User]
message = update.effective_message # type: Optional[Message]
if len(args) >= 1:
val = args[0].lower()
if val == "off" or val == "no" or val == "0":
sql.set_flood(chat.id, 0)
message.reply_text("Antiflood has been disabled.")
elif val.isdigit():
amount = int(val)
if amount <= 0:
sql.set_flood(chat.id, 0)
message.reply_text("Antiflood has been disabled.")
return "<b>{}:</b>" \
"\n#SETFLOOD" \
"\n<b>Admin:</b> {}" \
"\nDisabled antiflood.".format(html.escape(chat.title), mention_html(user.id, user.first_name))
elif amount < 3:
message.reply_text("Antiflood has to be either 0 (disabled), or a number bigger than 3!")
return ""
else:
sql.set_flood(chat.id, amount)
message.reply_text("Antiflood has been updated and set to {}".format(amount))
return "<b>{}:</b>" \
"\n#SETFLOOD" \
"\n<b>Admin:</b> {}" \
"\nSet antiflood to <code>{}</code>.".format(html.escape(chat.title),
mention_html(user.id, user.first_name), amount)
else:
message.reply_text("Unrecognised argument - please use a number, 'off', or 'no'.")
return ""
示例13: promote
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import mention_html [as 別名]
def promote(bot: Bot, update: Update, args: List[str]) -> str:
chat_id = update.effective_chat.id
message = update.effective_message # type: Optional[Message]
chat = update.effective_chat # type: Optional[Chat]
user = update.effective_user # type: Optional[User]
user_id = extract_user(message, args)
if not user_id:
message.reply_text("This user is ded mate.")
return ""
user_member = chat.get_member(user_id)
if user_member.status == 'administrator' or user_member.status == 'creator':
message.reply_text("Am I supposed to give them a second star or something?")
return ""
if user_id == bot.id:
message.reply_text("If only I could do this to myself ;_;")
return ""
# set same perms as bot - bot can't assign higher perms than itself!
bot_member = chat.get_member(bot.id)
bot.promoteChatMember(chat_id, user_id,
can_change_info=bot_member.can_change_info,
can_post_messages=bot_member.can_post_messages,
can_edit_messages=bot_member.can_edit_messages,
can_delete_messages=bot_member.can_delete_messages,
can_invite_users=bot_member.can_invite_users,
can_restrict_members=bot_member.can_restrict_members,
can_pin_messages=bot_member.can_pin_messages,
can_promote_members=bot_member.can_promote_members)
message.reply_text("Successfully promoted!")
return "<b>{}:</b>" \
"\n#PROMOTED" \
"\n<b>Admin:</b> {}" \
"\n<b>User:</b> {}".format(html.escape(chat.title),
mention_html(user.id, user.first_name),
mention_html(user_member.user.id, user_member.user.first_name))
示例14: report_alt
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import mention_html [as 別名]
def report_alt(update, context) -> str:
message = update.effective_message # type: Optional[Message]
chat = update.effective_chat # type: Optional[Chat]
user = update.effective_user # type: Optional[User]
if chat and message.reply_to_message and sql.chat_should_report(chat.id):
reported_user = message.reply_to_message.from_user # type: Optional[User]
chat_name = chat.title or chat.first or chat.username
admin_list = chat.get_administrators()
msg = tl(update.effective_message, "<b>{}:</b>" \
"\n<b>Pengguna yang dilaporkan:</b> {} (<code>{}</code>)" \
"\n<b>Dilaporkan oleh:</b> {} (<code>{}</code>)").format(html.escape(chat.title),
mention_html(
reported_user.id,
reported_user.first_name),
reported_user.id,
mention_html(user.id,
user.first_name),
user.id)
all_admins = []
for admin in admin_list:
if admin.user.is_bot: # don't tag bot
continue
if sql.user_should_report(admin.user.id):
all_admins.append("<a href='tg://user?id={}'></a>".format(admin.user.id))
context.bot.send_message(chat.id, tl(update.effective_message, "⚠️ {} <b>telah di laporkan ke admin!</b>{}").format(
mention_html(reported_user.id, reported_user.first_name),
"".join(all_admins)), parse_mode=ParseMode.HTML, reply_to_message_id=message.reply_to_message.message_id)
return msg
return ""
示例15: fed_info
# 需要導入模塊: from telegram.utils import helpers [as 別名]
# 或者: from telegram.utils.helpers import mention_html [as 別名]
def fed_info(update, context):
chat = update.effective_chat # type: Optional[Chat]
user = update.effective_user # type: Optional[User]
args = context.args
if args:
fed_id = args[0]
info = sql.get_fed_info(fed_id)
else:
fed_id = sql.get_fed_id(chat.id)
if not fed_id:
send_message(update.effective_message, tl(update.effective_message, "Grup ini tidak dalam federasi apa pun!"))
return
info = sql.get_fed_info(fed_id)
owner = context.bot.get_chat(info['owner'])
try:
owner_name = owner.first_name + " " + owner.last_name
except:
owner_name = owner.first_name
FEDADMIN = sql.all_fed_users(fed_id)
FEDADMIN.append(int(owner.id))
TotalAdminFed = len(FEDADMIN)
user = update.effective_user # type: Optional[Chat]
chat = update.effective_chat # type: Optional[Chat]
info = sql.get_fed_info(fed_id)
text = tl(update.effective_message, "<b>ℹ️ Info federasi:</b>")
text += "\nFedID: <code>{}</code>".format(fed_id)
text += tl(update.effective_message, "\nNama: {}").format(info['fname'])
text += tl(update.effective_message, "\nPembuat: {}").format(mention_html(owner.id, owner_name))
text += tl(update.effective_message, "\nSeluruh admin: <code>{}</code>").format(TotalAdminFed)
getfban = sql.get_all_fban_users(fed_id)
text += tl(update.effective_message, "\nTotal yang di banned: <code>{}</code>").format(len(getfban))
getfchat = sql.all_fed_chats(fed_id)
text += tl(update.effective_message, "\nTotal grup yang terkoneksi: <code>{}</code>").format(len(getfchat))
send_message(update.effective_message, text, parse_mode=ParseMode.HTML)