本文整理汇总了Python中telegram.MessageEntity.MENTION属性的典型用法代码示例。如果您正苦于以下问题:Python MessageEntity.MENTION属性的具体用法?Python MessageEntity.MENTION怎么用?Python MessageEntity.MENTION使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类telegram.MessageEntity
的用法示例。
在下文中一共展示了MessageEntity.MENTION属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_all_members
# 需要导入模块: from telegram import MessageEntity [as 别名]
# 或者: from telegram.MessageEntity import MENTION [as 别名]
def set_all_members(bot, update, **kwargs):
"""Set members to be tagged when @all keyword is used."""
msg = kwargs.get('args')
if not msg:
logger.info(
"No users passed to set_all_members function. kwargs: %s", kwargs)
return
user_entities = update.message.parse_entities(
[MessageEntity.MENTION, MessageEntity.TEXT_MENTION]
)
updated = update_all_users(user_entities)
if updated:
bot.send_message(
chat_id=update.message.chat_id, text='Users added to the @all tag'
)
else:
pass
bot.send_message(
chat_id=update.message.chat_id,
text='Algo pasó. Hablale a @BoedoCrow y pedile que vea los logs.',
)
示例2: reply_afk
# 需要导入模块: from telegram import MessageEntity [as 别名]
# 或者: from telegram.MessageEntity import MENTION [as 别名]
def reply_afk(bot: Bot, update: Update):
message = update.effective_message # type: Optional[Message]
entities = message.parse_entities([MessageEntity.TEXT_MENTION, MessageEntity.MENTION])
if message.entities and entities:
for ent in entities:
if ent.type == MessageEntity.TEXT_MENTION:
user_id = ent.user.id
fst_name = ent.user.first_name
elif ent.type == MessageEntity.MENTION:
user_id = get_user_id(message.text[ent.offset:ent.offset + ent.length])
if not user_id:
# Should never happen, since for a user to become AFK they must have spoken. Maybe changed username?
return
chat = bot.get_chat(user_id)
fst_name = chat.first_name
else:
return
if sql.is_afk(user_id):
valid, reason = sql.check_afk_status(user_id)
if valid:
if not reason:
res = "{} isn't here bud.".format(fst_name)
else:
res = "{} is AFK! says its because of:\n{}".format(fst_name, reason)
message.reply_text(res)
示例3: reply_afk
# 需要导入模块: from telegram import MessageEntity [as 别名]
# 或者: from telegram.MessageEntity import MENTION [as 别名]
def reply_afk(update, context):
message = update.effective_message # type: Optional[Message]
entities = message.parse_entities([MessageEntity.TEXT_MENTION, MessageEntity.MENTION])
if message.entities and entities:
for ent in entities:
if ent.type == MessageEntity.TEXT_MENTION:
user_id = ent.user.id
fst_name = ent.user.first_name
elif ent.type == MessageEntity.MENTION:
user_id = get_user_id(message.text[ent.offset:ent.offset + ent.length])
if not user_id:
# Should never happen, since for a user to become AFK they must have spoken. Maybe changed username?
return
try:
chat = context.bot.get_chat(user_id)
except BadRequest:
print("Error: Could not fetch userid {} for AFK module".format(user_id))
return
fst_name = chat.first_name
else:
return
if sql.is_afk(user_id):
valid, reason = sql.check_afk_status(user_id)
if valid:
if not reason:
res = tl(update.effective_message, "{} sedang AFK!").format(fst_name)
else:
res = tl(update.effective_message, "{} sedang AFK!\nKarena : {}").format(fst_name, reason)
send_message(update.effective_message, res)
示例4: reply_afk
# 需要导入模块: from telegram import MessageEntity [as 别名]
# 或者: from telegram.MessageEntity import MENTION [as 别名]
def reply_afk(bot: Bot, update: Update):
message = update.effective_message # type: Optional[Message]
if message.entities and message.parse_entities([MessageEntity.TEXT_MENTION, MessageEntity.MENTION]):
entities = message.parse_entities([MessageEntity.TEXT_MENTION, MessageEntity.MENTION])
for ent in entities:
if ent.type == MessageEntity.TEXT_MENTION:
user_id = ent.user.id
fst_name = ent.user.first_name
elif ent.type == MessageEntity.MENTION:
user_id = get_user_id(message.text[ent.offset:ent.offset + ent.length])
if not user_id:
# Should never happen, since for a user to become AFK they must have spoken. Maybe changed username?
return
chat = bot.get_chat(user_id)
fst_name = chat.first_name
else:
return
if sql.is_afk(user_id):
user = sql.check_afk_status(user_id)
if not user.reason:
res = "{} is away from the keyboard ! reason :\n{} ".format(fst_name)
else:
res = "{} is away from the keyboard ! reason :\n{}. ".format(fst_name, user.reason)
message.reply_text(res)
示例5: reply_afk
# 需要导入模块: from telegram import MessageEntity [as 别名]
# 或者: from telegram.MessageEntity import MENTION [as 别名]
def reply_afk(bot: Bot, update: Update):
message = update.effective_message # type: Optional[Message]
entities = message.parse_entities([MessageEntity.TEXT_MENTION, MessageEntity.MENTION])
if message.entities and entities:
for ent in entities:
if ent.type == MessageEntity.TEXT_MENTION:
user_id = ent.user.id
fst_name = ent.user.first_name
elif ent.type == MessageEntity.MENTION:
user_id = get_user_id(message.text[ent.offset:ent.offset + ent.length])
if not user_id:
# Should never happen, since for a user to become AFK they must have spoken. Maybe changed username?
return
chat = bot.get_chat(user_id)
fst_name = chat.first_name
else:
return
if sql.is_afk(user_id):
valid, reason = sql.check_afk_status(user_id)
if valid:
if not reason:
res = "{} is AFK!".format(fst_name)
else:
res = "{} is AFK! says its because of:\n{}".format(fst_name, reason)
message.reply_text(res)