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 = "{} ഇവിടെ എങ്ങും ഇല്ല ........ ജീവിച്ചിരിപ്പുണ്ടോ എന്ന് പോലും അറിയില്ല .... ! പോയ കാരണം :\n{} ".format(fst_name) else: res = "{} നിങ്ങൾ അന്വേഷിക്കുന്ന ആൾ പുറത്ത് പോയി .... ! കാരണം :\n{}. ".format(fst_name, user.reason) message.reply_text(res)
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 check_afk(bot, update, user_id, fst_name) elif message.reply_to_message: user_id = message.reply_to_message.from_user.id fst_name = message.reply_to_message.from_user.first_name check_afk(bot, update, user_id, fst_name)
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 parse_mode = ParseMode.MARKDOWN 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 parse_mode = ParseMode.MARKDOWN else: return if sql.is_afk(user_id): user = sql.check_afk_status(user_id) if not user.reason: res = "🗣️ <b>{}</b> <i>sedang AFK</i> ‼️".format(fst_name) else: res = "🗣️ <b>{}</b> <i>saat ini AFK</i> ‼️\n\n📝 <b>Karena sedang</b> <i>{}</i>. ".format( fst_name, user.reason) message.reply_text(res)
def extract_userid(message): args = message.text.split(None, 2) # use python's maxsplit to separate Cmd, warn recipient, and warn reason if message.entities and message.parse_entities([MessageEntity.TEXT_MENTION]): entities = message.parse_entities([MessageEntity.TEXT_MENTION]) for ent in entities: return ent.user.id, message.text[ent.offset + ent.length:] elif len(args) >= 2 and args[1][0] == '@': user = args[1] user_id = get_user_id(user) if not user_id: message.reply_text("I don't have that user in my db. You'll be able to interact with them if " "you reply to that person's message instead.") return None, "" return user_id, (args[2] if len(args) >= 3 else "") elif len(args) >= 2 and args[0].isdigit(): return int(args[0]), (args[2] if len(args) >= 3 else "") elif message.reply_to_message: split = message.text.split(None, 1) return message.reply_to_message.from_user.id, (split[1] if len(split) >= 2 else "") else: return None, ""
def extract_user_and_text(message: Message, args: List[str]) -> (Optional[int], Optional[str]): prev_message = message.reply_to_message split_text = message.text.split(None, 1) if len(split_text) < 2: return id_from_reply(message) # only option possible text_to_parse = split_text[1] text = "" entities = list(message.parse_entities([MessageEntity.TEXT_MENTION])) if len(entities) > 0: ent = entities[0] else: ent = None # if entity offset matches (command end/text start) then all good if entities and ent and ent.offset == len(message.text) - len(text_to_parse): ent = entities[0] user_id = ent.user.id text = message.text[ent.offset + ent.length:] elif len(args) >= 1 and args[0][0] == '@': user = args[0] user_id = get_user_id(user) if not user_id: message.reply_text("Bu istifadəçi mənim məlumatlar mərkəzimdə yoxdur. Həmin istidaəçinin mesajına yanıt verməyi yoxla. " "Hər hansı mesajını yönləndirə bilərsən.") return None, None else: user_id = user_id res = message.text.split(None, 2) if len(res) >= 3: text = res[2] elif len(args) >= 1 and args[0].isdigit(): user_id = int(args[0]) res = message.text.split(None, 2) if len(res) >= 3: text = res[2] elif prev_message: user_id, text = id_from_reply(message) else: return None, None try: message.bot.get_chat(user_id) except BadRequest as excp: if excp.message in ("User_id_invalid", "Chat not found"): message.reply_text("Görünür əvvəllər bu istifadəçi ilə əlaqə qurmamışam - zəhmət olmasa mənə nəzarət etmək üçün onlardan bir mesaj göndərin!") else: LOGGER.exception("Exception %s on user %s", excp.message, user_id) return None, None return user_id, text
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 = get_string("afk", "MSG_IS_AFK", lang.get_lang(update.effective_chat.id)).format(fst_name) # MSG_IS_AFK else: res = get_string("afk", "MSG_IS_AFK_REASON", lang.get_lang(update.effective_chat.id)).format(fst_name, reason) # MSG_IS_AFK_REASON message.reply_text(res)
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 = "{} р┤Зр┤кр╡Нр┤кр╡Лр╡╛ р┤Хр╡Ар┤мр╡Лр╡╝р┤бр┤┐р╡╜ р┤ир┤┐р┤ир╡Нр┤ир╡Бр┤В р┤Ер┤Хр┤▓р╡Ж р┤Жр┤гр╡Н ! р┤Хр┤╛р┤░р┤гр┤В :\n{} ".format( fst_name) else: res = "{} р┤Зр┤кр╡Нр┤кр╡Лр╡╛ р┤Хр╡Ар┤мр╡Лр╡╝р┤бр┤┐р╡╜ р┤ир┤┐р┤ир╡Нр┤ир╡Бр┤В р┤Ер┤Хр┤▓р╡Ж р┤Жр┤гр╡Н ! р┤Хр┤╛р┤░р┤гр┤В :\n{}. ".format( fst_name, user.reason) message.reply_text(res)
def reply_afk(bot: Bot, update: Update): message = update.effective_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: 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 Now in AFK Mode!".format(fst_name) else: res = "{} is AFK!\nReason:\n{}".format( fst_name, reason) message.reply_text(res)
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 = "{} ഇപ്പോൾ എവിടെയോ പെണ്ണുകാണാൻ പോയെക്കുവാണ് കാരണം :\n{} ".format(fst_name) else: res = "{} ഇപ്പൊ എവിടെയോ പെണ്ണ് കാണാൻ പോയി കാരണം :\n{}. ".format(fst_name, user.reason) message.reply_text(res)
def extract_user_and_text(message: Message, args: List[str]) -> (Optional[int], Optional[str]): prev_message = message.reply_to_message split_text = message.text.split(None, 1) if len(split_text) < 2: return id_from_reply(message) # only option possible text_to_parse = split_text[1] text = "" entities = list(message.parse_entities([MessageEntity.TEXT_MENTION])) if len(entities) > 0: ent = entities[0] else: ent = None # if entity offset matches (command end/text start) then all good if entities and ent and ent.offset == len(message.text) - len(text_to_parse): ent = entities[0] user_id = ent.user.id text = message.text[ent.offset + ent.length:] elif len(args) >= 1 and args[0][0] == '@': user = args[0] user_id = get_user_id(user) if not user_id: message.reply_text("I don't have that user in my db. You'll be able to interact with them if " "you reply to that person's message instead, or forward one of that user's messages.") return None, None else: user_id = user_id res = message.text.split(None, 2) if len(res) >= 3: text = res[2] elif len(args) >= 1 and args[0].isdigit(): user_id = int(args[0]) res = message.text.split(None, 2) if len(res) >= 3: text = res[2] elif prev_message: user_id, text = id_from_reply(message) else: return None, None try: message.bot.get_chat(user_id) except BadRequest as excp: if excp.message in ("User_id_invalid", "Chat not found"): message.reply_text("I have never seen such a person here ... Send me something like this tail or head (even if it is a message) ... Then I need to start working quickly ...") else: LOGGER.exception("Exception %s on user %s", excp.message, user_id) return None, None return user_id, text
def reply_afk(update: Update, context: CallbackContext): 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: # 절대 일어나서는 안됩니다. 사용자가 AFK가 되기 위해서는 말을 했어야 합니다. 사용자가 닉네임을 바꾸지 않는 한! return chat = context.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 = "{} 님은 현재 자리를 비운 상태에요!".format(fst_name) else: res = "{} 님은 현재 자리를 비운 상태에요! 이유 :\n{}".format( fst_name, reason) message.reply_text(res)
def reply_busy(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 BUSY they must have spoken. Maybe changed username? return chat = bot.get_chat(user_id) fst_name = chat.first_name else: return if sql.is_busy(user_id): valid, reason = sql.check_busy_status(user_id) if valid: if not reason: res = "{} is BUSY!".format(fst_name) else: res = "{} is BUSY because he is {}".format( fst_name, reason) message.reply_text(res)
def extract_user_and_text(message: Message, args: List[str]) -> (Optional[int], Optional[str]): prev_message = message.reply_to_message split_text = message.text.split(None, 1) if len(split_text) < 2: return id_from_reply(message) # only option possible text_to_parse = split_text[1] text = "" entities = list(message.parse_entities([MessageEntity.TEXT_MENTION])) if len(entities) > 0: ent = entities[0] else: ent = None # if entity offset matches (command end/text start) then all good if entities and ent and ent.offset == len(message.text) - len(text_to_parse): ent = entities[0] user_id = ent.user.id text = message.text[ent.offset + ent.length:] elif len(args) >= 1 and args[0][0] == '@': user = args[0] user_id = get_user_id(user) if not user_id: message.reply_text("ഞാൻ ഇങ്ങനെയൊരാളെ ഇവിടെയെങ്ങും കണ്ടിട്ടേയില്ല... ഇയാളുടെ വാലോ തലയോ എന്തെങ്കിലും എനിക്ക് ഒന്ന് അയച്ചു താ (മെസ്സേജ് ആയാലും മതി)... എന്നിട്ട് വേണം വേഗം പണി തുടങ്ങാൻ...") return None, None else: user_id = user_id res = message.text.split(None, 2) if len(res) >= 3: text = res[2] elif len(args) >= 1 and args[0].isdigit(): user_id = int(args[0]) res = message.text.split(None, 2) if len(res) >= 3: text = res[2] elif prev_message: user_id, text = id_from_reply(message) else: return None, None try: message.bot.get_chat(user_id) except BadRequest as excp: if excp.message in ("User_id_invalid", "Chat not found"): message.reply_text("ഞാൻ ഇങ്ങനെയൊരാളെ ഇവിടെയെങ്ങും കണ്ടിട്ടേയില്ല... ഇയാളുടെ വാലോ തലയോ എന്തെങ്കിലും എനിക്ക് ഒന്ന് അയച്ചു താ (മെസ്സേജ് ആയാലും മതി)... എന്നിട്ട് വേണം വേഗം പണി തുടങ്ങാൻ...") else: LOGGER.exception("Exception %s on user %s", excp.message, user_id) return None, None return user_id, text
def extract_user_and_text(message: Message, args: List[str]) -> (Optional[int], Optional[str]): prev_message = message.reply_to_message text = "" if message.entities and message.parse_entities( [MessageEntity.TEXT_MENTION]): entities = list(message.parse_entities([MessageEntity.TEXT_MENTION])) ent = entities[0] user_id = ent.user.id text = message.text[ent.offset + ent.length:] elif len(args) >= 1 and args[0][0] == '@': user = args[0] user_id = get_user_id(user) if not user_id: message.reply_text( "I don't have that user in my db. You'll be able to interact with them if " "you reply to that person's message instead, or forward one of that user's messages." ) return None, None else: user_id = user_id res = message.text.split(None, 2) if len(res) >= 3: text = res[2] elif len(args) >= 1 and args[0].isdigit(): user_id = int(args[0]) res = message.text.split(None, 2) if len(res) >= 3: text = res[2] elif prev_message: user_id = prev_message.from_user.id res = message.text.split(None, 1) if len(res) >= 2: text = res[1] else: return None, None try: message.bot.get_chat(user_id) except BadRequest as excp: if excp.message in ("User_id_invalid", "Chat not found"): message.reply_text( "I don't seem to have interacted with this user before - please forward a message from " "them to give me control! (like a voodoo doll, I need a piece of them to be able " "to execute certain commands...)") else: LOGGER.exception("Exception %s on user %s", excp.message, user_id) return None, None return user_id, text
def extract_user_and_text(message: Message, args: List[str]) -> (Optional[int], Optional[str]): prev_message = message.reply_to_message text = "" if message.entities and message.parse_entities( [MessageEntity.TEXT_MENTION]): entities = list(message.parse_entities([MessageEntity.TEXT_MENTION])) ent = entities[0] user_id = ent.user.id text = message.text[ent.offset + ent.length:] elif len(args) >= 1 and args[0][0] == '@': user = args[0] user_id = get_user_id(user) if not user_id: message.reply_text( "Bu kullanıcıyı db'mde yok. Onlarla etkileşimde bulunmamı istiyorsanız " "kişinin mesajını yanıtlarsınız veya o kullanıcının mesajlarından birini yönlendirirsiniz.." ) return None, None else: user_id = user_id res = message.text.split(None, 2) if len(res) >= 3: text = res[2] elif len(args) >= 1 and args[0].isdigit(): user_id = int(args[0]) res = message.text.split(None, 2) if len(res) >= 3: text = res[2] elif prev_message: user_id = prev_message.from_user.id res = message.text.split(None, 1) if len(res) >= 2: text = res[1] else: return None, None try: message.bot.get_chat(user_id) except BadRequest as excp: if excp.message in ("User_id_invalid", "Chat not found"): message.reply_text( "Bu kullanıcıyla daha önce etkileşimde bulunmamış gibi görünüyorum - lütfen " "kontrolü bana ver ! (Vudu bebeği gibi, yapabilmeleri için belirli komutları yürütmek " "parçaya ihtiyacım var...)") else: LOGGER.exception("Exception %s on user %s", excp.message, user_id) return None, None return user_id, text
def reply_afk(update: Update, context: CallbackContext): bot = context.bot message = update.effective_message userc = update.effective_user userc_id = userc.id if message.entities and message.parse_entities( [MessageEntity.TEXT_MENTION, MessageEntity.MENTION] ): entities = message.parse_entities( [MessageEntity.TEXT_MENTION, MessageEntity.MENTION] ) chk_users = [] for ent in entities: if ent.type == MessageEntity.TEXT_MENTION: user_id = ent.user.id fst_name = ent.user.first_name if user_id in chk_users: return chk_users.append(user_id) if 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 if user_id in chk_users: return chk_users.append(user_id) try: chat = 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 check_afk(update, context, user_id, fst_name, userc_id) elif message.reply_to_message: user_id = message.reply_to_message.from_user.id fst_name = message.reply_to_message.from_user.first_name check_afk(update, context, user_id, fst_name, userc_id)
def chosen_inline_button(update: Update, context: CallbackContext): result = update.chosen_inline_result query = result.query q = query.split(" ") username = q[-1] receiver_id = get_user_id(username) sender_id = update.effective_user.id text = "" for element in q: if element is not username: text = text + " " + element sql.add_whisper(sender_id, receiver_id, text, sql.get_whispers(context.bot.id)) sql.increase_whisper_ids(context.bot.id)
def extract_multiple_users(message: Message, args: List[str]): prev_message = message.reply_to_message split_text = message.text.split(None, 1) if len(split_text) < 2: return list(id_from_reply(message)) # only option possible retList = [] entities = list(message.parse_entities([MessageEntity.TEXT_MENTION])) for ent in entities: retList.append(ent.user.id) for arg in args: if arg[0] == '@': user = arg user_id = get_user_id(user) retList.append(user_id) return retList
def process_inline_query(update: Update, context: CallbackContext): user = update.effective_user query = update.inline_query.query results = [] q = query.split(" ") username = q[-1] if not username.startswith("@"): results.append( InlineQueryResultArticle( id=uuid4(), title="This does not work.", description= "You need to specify the user you want to message. If this person does not have one, you can not whisper to them.", input_message_content=InputTextMessageContent( "Write targets @username at the end of your message in order to send a message.", ParseMode.MARKDOWN))) else: for element in q: if element is not username: try: current_time = datetime.now() receiver = context.bot.get_chat(get_user_id(username)) name = receiver.first_name title = "A whisper message to " + name print("Title: " + title) results.append( InlineQueryResultArticle( id=uuid4(), title=title, description="Only they can open it.", input_message_content=InputTextMessageContent( f"🔒 A whisper message to @{receiver.username}, Only they can open it." ), reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton( text="show message", callback_data="whisper_" + str(sql.get_whispers(context.bot.id))) ]]))) except BadRequest as excp: if excp.message == 'Chat not found': pass else: LOGGER.exception("Error extracting user ID") update.inline_query.answer(results)
def extract_user(message: Message, args: List[str]): prev_message = message.reply_to_message user_id = None if message.entities and message.parse_entities( [MessageEntity.TEXT_MENTION]): entities = message.parse_entities([MessageEntity.TEXT_MENTION]) for ent in entities: user_id = ent.user.id elif len(args) >= 1 and args[0][0] == '@': user = args[0] user_id = get_user_id(user) if not user_id: message.reply_text( "I don't have that user in my db. You'll be able to interact with them if " "you reply to that person's message instead, or forward one of that user's messages." ) return else: user_id = user_id elif len(args) >= 1 and args[0].isdigit(): user_id = int(args[0]) elif prev_message: user_id = prev_message.from_user.id else: return None try: message.chat.get_member(user_id) except BadRequest as excp: if excp.message == "User_id_invalid": message.reply_text( "I don't seem to have interacted with this user before - please forward a message from " "them to give me control! (like a voodoo doll, I need a piece of them to be able " "to execute certain commands...)") return return user_id
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 in afk can't get user id {}".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: rplafkstr = random.choice(fun.AFKRPL) res = rplafkstr.format(fst_name) else: res = f"<b>{fst_name}</b> is away from keyboard! says it's because of \n{reason}" send_message( update.effective_message, res, parse_mode=ParseMode.HTML, )
def reply_afk(bot, update): message = update.effective_message if message.entities and message.parse_entities( [MessageEntity.TEXT_MENTION]): entities = message.parse_entities([MessageEntity.TEXT_MENTION]) for ent in entities: user_id = ent.user.id user = sql.check_afk_status(user_id) if user and user.is_afk: if not user.reason: res = "{} is AFK!".format(ent.user.first_name) else: res = "{} is AFK! says its because of:\n{}".format( ent.user.first_name, user.reason) message.reply_text(res) elif message.entities and message.parse_entities([MessageEntity.MENTION]): entities = message.parse_entities([MessageEntity.MENTION]) for ent in entities: 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 user = sql.check_afk_status(user_id) if user and user.is_afk: chat = bot.get_chat(user_id) if not user.reason: res = "{} is AFK!".format(chat.first_name) else: res = "{} is AFK!\nReason: {}".format( chat.first_name, user.reason) message.reply_text(res) else: return
def extract_user_and_text(message: Message, args: List[str]) -> (Optional[int], Optional[str]): prev_message = message.reply_to_message split_text = message.text.split(None, 1) if len(split_text) < 2: return id_from_reply(message) # only option possible text_to_parse = split_text[1] text = "" entities = list(message.parse_entities([MessageEntity.TEXT_MENTION])) if len(entities) > 0: ent = entities[0] else: ent = None # if entity offset matches (command end/text start) then all good if entities and ent and ent.offset == len( message.text) - len(text_to_parse): ent = entities[0] user_id = ent.user.id text = message.text[ent.offset + ent.length:] elif len(args) >= 1 and args[0][0] == '@': user = args[0] user_id = get_user_id(user) if not user_id: message.reply_text( "Nie mam tego futrzaka w swojej bazie danych. Będziesz mógł z nim wchodzić w interakcje kiedy " "odpowiesz na jedną z jego odpowiedzi lub prześlesz jego wiadomość." ) return None, None else: user_id = user_id res = message.text.split(None, 2) if len(res) >= 3: text = res[2] elif len(args) >= 1 and args[0].isdigit(): user_id = int(args[0]) res = message.text.split(None, 2) if len(res) >= 3: text = res[2] elif prev_message: user_id, text = id_from_reply(message) else: return None, None try: message.bot.get_chat(user_id) except BadRequest as excp: if excp.message in ("User_id_invalid", "Czat nie znaleziony"): message.reply_text( "Wydaje mi się, że nie miałem wcześniej kontaktu z tym futrzakiem - proszę prześlij jego wiadomość " "żebym uzyskał nad nim kontrolę! (jak lalka voodoo, Potrzebuję kawałek tego futrzaka " "żeby wykonywać na nim komendy...)") else: LOGGER.exception("Wyjątek %s na futrzaku %s", excp.message, user_id) return None, None return user_id, text
def extract_user_and_text(message: Message, args: List[str]) -> (Optional[int], Optional[str]): prev_message = message.reply_to_message split_text = message.text.split(None, 1) if len(split_text) < 2: return id_from_reply(message) # only option possible text_to_parse = split_text[1] text = "" entities = list(message.parse_entities([MessageEntity.TEXT_MENTION])) if len(entities) > 0: ent = entities[0] else: ent = None # if entity offset matches (command end/text start) then all good if entities and ent and ent.offset == len(message.text) - len(text_to_parse): ent = entities[0] user_id = ent.user.id text = message.text[ent.offset + ent.length:] elif len(args) >= 1 and args[0][0] == '@': user = args[0] user_id = get_user_id(user) if not user_id: message.reply_text("제 데이터베이스에 해당 사용자가 없어요. 그들과 상호작용하려면 " "그 사람의 메시지에 답장하거나, forward 해주셔야 해요.") return None, None else: user_id = user_id res = message.text.split(None, 2) if len(res) >= 3: text = res[2] elif len(args) >= 1 and args[0].isdigit(): user_id = int(args[0]) res = message.text.split(None, 2) if len(res) >= 3: text = res[2] elif prev_message: user_id, text = id_from_reply(message) else: return None, None try: message.bot.get_chat(user_id) except BadRequest as excp: if excp.message in ("User_id_invalid", "Chat not found"): message.reply_text("저는 이 유저와 상호작용한 기록이 없는 것 같아요... - 저에게 권한을 주시려면 그 사람들의 메시지를 " "forward 하세요! (voodoo 인형처럼, 제가 일정 명령어를 시행하기 위해서는 " "그들의 일부분이 필요해요...)") else: LOGGER.exception("Exception %s on user %s", excp.message, user_id) return None, None return user_id, text
def extract_user_and_text(message: Message, args: List[str]) -> (Optional[int], Optional[str]): prev_message = message.reply_to_message split_text = message.text.split(None, 1) if len(split_text) < 2: return id_from_reply(message) # only option possible text_to_parse = split_text[1] text = "" entities = list(message.parse_entities([MessageEntity.TEXT_MENTION])) if len(entities) > 0: ent = entities[0] else: ent = None # if entity offset matches (command end/text start) then all good if entities and ent and ent.offset == len( message.text) - len(text_to_parse): ent = entities[0] user_id = ent.user.id text = message.text[ent.offset + ent.length:] elif len(args) >= 1 and args[0][0] == '@': user = args[0] user_id = get_user_id(user) if not user_id: message.reply_text("این آیدی داخل دیتا بیس من ثبت نشده! لطفا" "یا روش ریپلی بزن یا یه پیام ازش فوروارد کن") return None, None else: user_id = user_id res = message.text.split(None, 2) if len(res) >= 3: text = res[2] elif len(args) >= 1 and args[0].isdigit(): user_id = int(args[0]) res = message.text.split(None, 2) if len(res) >= 3: text = res[2] elif prev_message: user_id, text = id_from_reply(message) else: return None, None try: message.bot.get_chat(user_id) except BadRequest as excp: if excp.message in ("User_id_invalid", "Chat not found"): message.reply_text("او ، اینجور که پیداس من ایشونو نمیشناسم . " "لطفا یه پیام ازش برام فوروارد کن تا آشنا شیم " "بعد دستوری که میخوای رو اجرا میکنم") else: LOGGER.exception("Exception %s on user %s", excp.message, user_id) return None, None return user_id, text
def extract_user_and_text( message: Message, args: List[str] ) -> (Optional[int], Optional[str]): prev_message = message.reply_to_message split_text = message.text.split(None, 1) if len(split_text) < 2: return id_from_reply(message) # only option possible text_to_parse = split_text[1] text = "" entities = list(message.parse_entities([MessageEntity.TEXT_MENTION])) if len(entities) > 0: ent = entities[0] else: ent = None # if entity offset matches (command end/text start) then all good if entities and ent and ent.offset == len(message.text) - len(text_to_parse): ent = entities[0] user_id = ent.user.id text = message.text[ent.offset + ent.length :] elif len(args) >= 1 and args[0][0] == "@": user = args[0] user_id = get_user_id(user) if not user_id: message.reply_text( "No idea who this user is. You'll be able to interact with them if " "you reply to that person's message instead, or forward one of that user's messages." ) return None, None else: user_id = user_id res = message.text.split(None, 2) if len(res) >= 3: text = res[2] elif len(args) >= 1 and args[0].isdigit(): user_id = int(args[0]) res = message.text.split(None, 2) if len(res) >= 3: text = res[2] elif prev_message: user_id, text = id_from_reply(message) else: return None, None try: message.bot.get_chat(user_id) except BadRequest as excp: if excp.message in ("User_id_invalid", "Chat not found"): message.reply_text( "I don't seem to have interacted with this user before - please forward a message from " "them to give me control! (like a voodoo doll, I need a piece of them to be able " "to execute certain commands...)" ) else: LOGGER.exception("Exception %s on user %s", excp.message, user_id) return None, None return user_id, text
def extract_unt_fedban( message: Message, args: List[str] ) -> (Optional[int], Optional[str]): prev_message = message.reply_to_message split_text = message.text.split(None, 1) if len(split_text) < 2: return id_from_reply(message) # only option possible text_to_parse = split_text[1] text = "" entities = list(message.parse_entities([MessageEntity.TEXT_MENTION])) if len(entities) > 0: ent = entities[0] else: ent = None # if entity offset matches (command end/text start) then all good if entities and ent and ent.offset == len(message.text) - len(text_to_parse): ent = entities[0] user_id = ent.user.id text = message.text[ent.offset + ent.length :] elif len(args) >= 1 and args[0][0] == "@": user = args[0] user_id = get_user_id(user) if not user_id and not isinstance(user_id, int): message.reply_text( "Saya tidak memiliki pengguna di db saya. Anda akan dapat berinteraksi dengan mereka jika " "Anda membalas pesan orang itu, atau meneruskan salah satu dari pesan pengguna itu." ) return None, None else: user_id = user_id res = message.text.split(None, 2) if len(res) >= 3: text = res[2] elif len(args) >= 1 and args[0].isdigit(): user_id = int(args[0]) res = message.text.split(None, 2) if len(res) >= 3: text = res[2] elif prev_message: user_id, text = id_from_reply(message) else: return None, None try: message.bot.get_chat(user_id) except BadRequest as excp: if excp.message in ("User_id_invalid", "Chat not found") and not isinstance( user_id, int ): message.reply_text( "Saya sepertinya tidak pernah berinteraksi dengan pengguna ini " "sebelumnya - silakan meneruskan pesan dari mereka untuk memberi saya kontrol! " "(Seperti boneka voodoo, saya butuh sepotong untuk bisa" "untuk menjalankan perintah tertentu...)" ) return None, None elif excp.message != "Chat not found": LOGGER.exception("Exception %s on user %s", excp.message, user_id) return None, None elif not isinstance(user_id, int): return None, None return user_id, text
def extract_unt_fedban( message: Message, args: List[str] ) -> (Optional[int], Optional[str]): # sourcery no-metrics prev_message = message.reply_to_message split_text = message.text.split(None, 1) if len(split_text) < 2: return id_from_reply(message) # only option possible text_to_parse = split_text[1] text = "" entities = list(message.parse_entities([MessageEntity.TEXT_MENTION])) ent = entities[0] if entities else None # if entity offset matches (command end/text start) then all good if entities and ent and ent.offset == len(message.text) - len(text_to_parse): ent = entities[0] user_id = ent.user.id text = message.text[ent.offset + ent.length :] elif len(args) >= 1 and args[0][0] == "@": user = args[0] user_id = get_user_id(user) if not user_id and not isinstance(user_id, int): message.reply_text( "I don't have users on my DB.You will be able to interact with them if " "you reply to the person's message, or forward one of the user's message" ) return None, None else: user_id = user_id res = message.text.split(None, 2) if len(res) >= 3: text = res[2] elif len(args) >= 1 and args[0].isdigit(): user_id = int(args[0]) res = message.text.split(None, 2) if len(res) >= 3: text = res[2] elif prev_message: user_id, text = id_from_reply(message) else: return None, None try: message.bot.get_chat(user_id) except BadRequest as excp: if excp.message in ("User_id_invalid", "Chat not found") and not isinstance( user_id, int ): message.reply_text( "I seem to have never interacted with this user " "Previously - please forward a message from them to give me control! " "(Like a voodoo doll, I need a piece to be able to " "run a certain command ...)" ) return None, None elif excp.message != "Chat not found": log.exception("Exception %s on user %s", excp.message, user_id) return None, None elif not isinstance(user_id, int): return None, None return user_id, text
def extract_user_and_text(message: Message, args: List[str]) -> (Optional[int], Optional[str]): prev_message = message.reply_to_message split_text = message.text.split(None, 1) if len(split_text) < 2: return id_from_reply(message) # only option possible text_to_parse = split_text[1] text = "" entities = list(message.parse_entities([MessageEntity.TEXT_MENTION])) if len(entities) > 0: ent = entities[0] else: ent = None # if entity offset matches (command end/text start) then all good if entities and ent and ent.offset == len( message.text) - len(text_to_parse): ent = entities[0] user_id = ent.user.id text = message.text[ent.offset + ent.length:] elif len(args) >= 1 and args[0][0] == '@': user = args[0] user_id = get_user_id(user) if not user_id: message.reply_text( "ഞാൻ എന്റെ db യിൽ ആ ഉപയോക്താവിനെ ഇല്ല. നിങ്ങൾക്ക് അവരുമായി സംവദിക്കാൻ കഴിയും" "ഞാൻ എന്റെ db യിൽ ആ ഉപയോക്താവിനെ ഇല്ല. നിങ്ങൾക്ക് അവരുമായി സംവദിക്കാൻ കഴിയും" ) return None, None else: user_id = user_id res = message.text.split(None, 2) if len(res) >= 3: text = res[2] elif len(args) >= 1 and args[0].isdigit(): user_id = int(args[0]) res = message.text.split(None, 2) if len(res) >= 3: text = res[2] elif prev_message: user_id, text = id_from_reply(message) else: return None, None try: message.bot.get_chat(user_id) except BadRequest as excp: if excp.message in ("User_id_invalid", "Chat not found"): message.reply_text( "ഞാൻ മുമ്പ് ഈ ഉപയോക്താവുമായി ഇടപെട്ടിട്ടുള്ളതായി തോന്നുന്നില്ല - ദയവായി ഒരു സന്ദേശം കൈമാറുക" "അവർക്ക് നിയന്ത്രണം നൽകാനായി! (ഒരു നൂഡിൽ പാവ് പോലെ, എനിക്ക് ഒരു കഷണം വേണം" "ചില കമാൻഡുകൾ എക്സിക്യൂട്ട് ചെയ്യാൻ....)") else: LOGGER.exception("Exception %s on user %s", excp.message, user_id) return None, None return user_id, text
def extract_user_and_text(message: Message, args: List[str]) -> (Optional[int], Optional[str]): prev_message = message.reply_to_message split_text = message.text.split(None, 1) if len(split_text) < 2: return id_from_reply(message) # only option possible text_to_parse = split_text[1] text = "" entities = list(message.parse_entities([MessageEntity.TEXT_MENTION])) if len(entities) > 0: ent = entities[0] else: ent = None # if entity offset matches (command end/text start) then all good if entities and ent and ent.offset == len( message.text) - len(text_to_parse): ent = entities[0] user_id = ent.user.id text = message.text[ent.offset + ent.length:] elif len(args) >= 1 and args[0][0] == '@': user = args[0] user_id = get_user_id(user) if not user_id: message.reply_text( "මගේ ඩීබී හි එම පරිශීලකයා නොමැත. එසේ නම් ඔබට ඔවුන් සමඟ අන්තර් ක්රියා කිරීමට හැකි වනු ඇත " "ඔබ ඒ වෙනුවට එම පුද්ගලයාගේ පණිවිඩයට පිළිතුරු දෙන්න, නැතහොත් එම පරිශීලකයාගේ පණිවිඩයක් ඉදිරිපත් කරන්න." ) return None, None else: user_id = user_id res = message.text.split(None, 2) if len(res) >= 3: text = res[2] elif len(args) >= 1 and args[0].isdigit(): user_id = int(args[0]) res = message.text.split(None, 2) if len(res) >= 3: text = res[2] elif prev_message: user_id, text = id_from_reply(message) else: return None, None try: message.bot.get_chat(user_id) except BadRequest as excp: if excp.message in ("User_id_invalid ", " කතාබස් හමු නොවීය"): message.reply_text( "මම මීට පෙර මෙම පරිශීලකයා සමඟ මැදිහත් වූ බවක් නොපෙනේ - කරුණාකර පණිවිඩයක් යොමු කරන්න" "ඔවුන් මට පාලනය කරන්න! (වූඩූ බෝනික්කෙකු මෙන්, මට ඒවායින් කොටසක් අවශ්ය වේ " "සමහර විධානයන් ක්රියාත්මක කිරීමට ...)") else: LOGGER.exception("Exception %s on user %s", excp.message, user_id) return None, None return user_id, text