Python telegram.MessageEntity.MENTION Examples
The following are 5
code examples of telegram.MessageEntity.MENTION().
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.MessageEntity
, or try the search function
.
![](https://www.programcreek.com/common/static/images/search.png)
Example #1
Source File: all_tagger.py From AmbroBot with GNU General Public License v3.0 | 6 votes |
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.', )
Example #2
Source File: afk.py From SkittBot with GNU General Public License v3.0 | 5 votes |
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)
Example #3
Source File: afk.py From EmiliaHikari with GNU General Public License v3.0 | 5 votes |
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)
Example #4
Source File: afk.py From Marie-2.0-English with GNU General Public License v3.0 | 5 votes |
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)
Example #5
Source File: afk.py From tgbot with GNU General Public License v3.0 | 5 votes |
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)