当前位置: 首页>>代码示例>>Python>>正文


Python MessageEntity.MENTION属性代码示例

本文整理汇总了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.',
        ) 
开发者ID:Ambro17,项目名称:AmbroBot,代码行数:24,代码来源:all_tagger.py

示例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) 
开发者ID:skittles9823,项目名称:SkittBot,代码行数:30,代码来源:afk.py

示例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) 
开发者ID:AyraHikari,项目名称:EmiliaHikari,代码行数:35,代码来源:afk.py

示例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) 
开发者ID:TGExplore,项目名称:Marie-2.0-English,代码行数:29,代码来源:afk.py

示例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) 
开发者ID:PaulSonOfLars,项目名称:tgbot,代码行数:30,代码来源:afk.py


注:本文中的telegram.MessageEntity.MENTION属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。