def tagg_all_button(update, context): query = update.callback_query chat = update.effective_chat splitter = query.data.split('=') query_match = splitter[0] user_id = splitter[1] if query_match == "tagall_accept": if query.from_user.id == int(user_id): member = chat.get_member(int(user_id)) chat_id = str(chat.id)[1:] REDIS.sadd(f'tagall2_{chat_id}', mention_html(member.user.id, member.user.first_name)) query.message.edit_text( "{} is accepted! to add yourself {}'s tag list.".format( mention_html(member.user.id, member.user.first_name), chat.title), parse_mode=ParseMode.HTML) else: context.bot.answer_callback_query( query.id, text="You're not the user being added in tag list!") elif query_match == "tagall_dicline": if query.from_user.id == int(user_id): member = chat.get_member(int(user_id)) query.message.edit_text( "{} is deslined! to add yourself {}'s tag list.".format( mention_html(member.user.id, member.user.first_name), chat.title), parse_mode=ParseMode.HTML) else: context.bot.answer_callback_query( query.id, text="You're not the user being added in tag list!")
def removetag(update, context): chat = update.effective_chat user = update.effective_user message = update.effective_message args = context.args user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("You don't seem to be referring to a user.") return try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": message.reply_text("I can't seem to find this user") return raise if user_id == context.bot.id: message.reply_text("how I supposed to tag or untag myself") return chat_id = str(chat.id)[1:] tagall_list = list(REDIS.sunion(f'tagall2_{chat_id}')) match_user = mention_html(member.user.id, member.user.first_name) if match_user not in tagall_list: message.reply_text("{} is doesn't exist in {}'s list!".format( mention_html(member.user.id, member.user.first_name), chat.title), parse_mode=ParseMode.HTML) return member = chat.get_member(int(user_id)) chat_id = str(chat.id)[1:] REDIS.srem(f'tagall2_{chat_id}', mention_html(member.user.id, member.user.first_name)) message.reply_text("{} is successfully removed from {}'s list.".format( mention_html(member.user.id, member.user.first_name), chat.title), parse_mode=ParseMode.HTML)
def unapproveall(update, context): chat = update.effective_chat user = update.effective_user message = update.effective_message chat_id = str(chat.id)[1:] approve_list = list(REDIS.sunion(f'approve_list_{chat_id}')) for target_user in approve_list: REDIS.srem(f'approve_list_{chat_id}', target_user) message.reply_text("Successully unapproved all users from {}.".format( chat.title))
def untagall(update, context): chat = update.effective_chat user = update.effective_user message = update.effective_message chat_id = str(chat.id)[1:] tagall_list = list(REDIS.sunion(f'tagall2_{chat_id}')) for tag_user in tagall_list: REDIS.srem(f'tagall2_{chat_id}', tag_user) message.reply_text( "Successully removed all users from {}'s tag list.".format(chat.title))
def tagall(update, context): chat = update.effective_chat user = update.effective_user message = update.effective_message args = context.args query = " ".join(args) if not query: message.reply_text("Please give a reason why are you want to tag all!") return chat_id = str(chat.id)[1:] tagall = list(REDIS.sunion(f'tagall2_{chat_id}')) tagall.sort() tagall = ", ".join(tagall) if tagall: tagall_reason = query if message.reply_to_message: message.reply_to_message.reply_text("{}" "\n\n<b>• Tagged Reason : </b>" "\n{}".format( tagall, tagall_reason), parse_mode=ParseMode.HTML) else: message.reply_text("{}" "\n\n<b>• Tagged Reason : </b>" "\n{}".format(tagall, tagall_reason), parse_mode=ParseMode.HTML) else: message.reply_text("Tagall list is empty!")
def tagme(update, context): chat = update.effective_chat user = update.effective_user message = update.effective_message chat_id = str(chat.id)[1:] tagall_list = list(REDIS.sunion(f'tagall2_{chat_id}')) match_user = mention_html(user.id, user.first_name) if match_user in tagall_list: message.reply_text("You're Already Exist In {}'s Tag List!".format( chat.title)) return REDIS.sadd(f'tagall2_{chat_id}', mention_html(user.id, user.first_name)) message.reply_text( "{} has been successfully added in {}'s tag list.".format( mention_html(user.id, user.first_name), chat.title), parse_mode=ParseMode.HTML)
def untagme(update, context): chat = update.effective_chat user = update.effective_user message = update.effective_message chat_id = str(chat.id)[1:] tagall_list = list(REDIS.sunion(f'tagall2_{chat_id}')) match_user = mention_html(user.id, user.first_name) if match_user not in tagall_list: message.reply_text( "You're already doesn't exist in {}'s tag list!".format( chat.title)) return REDIS.srem(f'tagall2_{chat_id}', mention_html(user.id, user.first_name)) message.reply_text("{} has been removed from {}'s tag list.".format( mention_html(user.id, user.first_name), chat.title), parse_mode=ParseMode.HTML)
def afk(update, context): args = update.effective_message.text.split(None, 1) user = update.effective_user if not user: # ignore channels return if user.id == 777000: return start_afk_time = time.time() if len(args) >= 2: reason = args[1] else: reason = "none" start_afk(update.effective_user.id, reason) REDIS.set(f'afk_time_{update.effective_user.id}', start_afk_time) fname = update.effective_user.first_name try: update.effective_message.reply_text("{} is now Away!".format(fname)) except BadRequest: pass
def __user_info__(user_id): is_afk = is_user_afk(user_id) text = "" if is_afk: since_afk = get_readable_time( (time.time() - float(REDIS.get(f'afk_time_{user_id}')))) text = "<i>This user is currently afk (away from keyboard).</i>" text += f"\n<i>Since: {since_afk}</i>" else: text = "<i>This user is currently isn't afk (away from keyboard).</i>" return text
def no_longer_afk(update, context): user = update.effective_user message = update.effective_message if not user: # ignore channels return if not is_user_afk(user.id): #Check if user is afk or not return end_afk_time = get_readable_time( (time.time() - float(REDIS.get(f'afk_time_{user.id}')))) REDIS.delete(f'afk_time_{user.id}') res = end_afk(user.id) if res: if message.new_chat_members: #dont say msg return firstname = update.effective_user.first_name try: message.reply_text( "{} is no longer AFK!\nTime you were AFK for: {}".format( firstname, end_afk_time)) except Exception: return
def approve(update: Update, context: CallbackContext) -> str: bot = context.bot args = context.args chat = update.effective_chat user = update.effective_user message = update.effective_message args = context.args user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("You don't seem to be referring to a user.") return try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": message.reply_text("I can't seem to find this user") return else: raise if user_id == context.bot.id: message.reply_text("How I supposed to approve myself") return chat_id = str(chat.id)[1:] approve_list = list(REDIS.sunion(f'approve_list_{chat_id}')) target_user = mention_html(member.user.id, member.user.first_name) if target_user in approve_list: message.reply_text("{} is already approved in {}.".format( mention_html(member.user.id, member.user.first_name), chat.title), parse_mode=ParseMode.HTML) return member = chat.get_member(int(user_id)) chat_id = str(chat.id)[1:] REDIS.sadd(f'approve_list_{chat_id}', mention_html(member.user.id, member.user.first_name)) message.reply_text("{} has been approved in {}.".format( mention_html(member.user.id, member.user.first_name), chat.title), parse_mode=ParseMode.HTML)
def check_afk(update, context, user_id, fst_name, userc_id): if is_user_afk(user_id): reason = afk_reason(user_id) since_afk = get_readable_time( (time.time() - float(REDIS.get(f'afk_time_{user_id}')))) if reason == "none": if int(userc_id) == int(user_id): return res = "{} is AFK!\nSince: {}".format(fst_name, since_afk) update.effective_message.reply_text(res) else: if int(userc_id) == int(user_id): return res = "{} is AFK! Says it's because of:\n{}\nSince: {}".format( fst_name, reason, since_afk) update.effective_message.reply_text(res)
def approved(update: Update, context: CallbackContext) -> str: bot = context.bot args = context.args chat = update.effective_chat user = update.effective_user message = update.effective_message chat_id = str(chat.id)[1:] approved_list = list(REDIS.sunion(f'approve_list_{chat_id}')) approved_list.sort() approved_list = ", ".join(approved_list) if approved_list: message.reply_text("The Following Users Are Approved: \n" "{}".format(approved_list), parse_mode=ParseMode.HTML) else: message.reply_text("No users are are approved in {}.".format( chat.title), parse_mode=ParseMode.HTML)
def approval(update: Update, context: CallbackContext) -> str: bot = context.bot args = context.args chat = update.effective_chat user = update.effective_user message = update.effective_message args = context.args user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("You don't seem to be referring to a user.") return try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": message.reply_text("I can't seem to find this user") return else: raise if user_id == context.bot.id: message.reply_text("How I supposed to approve myself") return chat_id = str(chat.id)[1:] approve_list = list(REDIS.sunion(f'approve_list_{chat_id}')) target_user = mention_html(member.user.id, member.user.first_name) if target_user in approve_list: message.reply_text( "{} is an approved user. Auto Warns, antiflood, and blocklists won't apply to them." .format(mention_html(member.user.id, member.user.first_name)), parse_mode=ParseMode.HTML) return if target_user not in approve_list: message.reply_text( "{} is not an approved user. They are affected by normal commands." .format(mention_html(member.user.id, member.user.first_name)), parse_mode=ParseMode.HTML) return
def addtag(update, context): chat = update.effective_chat user = update.effective_user message = update.effective_message args = context.args user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("You don't seem to be referring to a user.") return try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": message.reply_text("I can't seem to find this user") return raise if user_id == context.bot.id: message.reply_text("how I supposed to tag myself") return chat_id = str(chat.id)[1:] tagall_list = list(REDIS.sunion(f'tagall2_{chat_id}')) match_user = mention_html(member.user.id, member.user.first_name) if match_user in tagall_list: message.reply_text("{} is already exist in {}'s tag list.".format( mention_html(member.user.id, member.user.first_name), chat.title), parse_mode=ParseMode.HTML) return message.reply_text( "{} accept this, if you want to add yourself into {}'s tag list! or just simply decline this." .format(mention_html(member.user.id, member.user.first_name), chat.title), reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton(text="Accept", callback_data=f"tagall_accept={user_id}"), InlineKeyboardButton(text="Decline", callback_data=f"tagall_dicline={user_id}") ]]), parse_mode=ParseMode.HTML)
def start_afk(userid, reason): REDIS.set(f'is_afk_{userid}', reason)
def end_afk(userid): REDIS.delete(f'is_afk_{userid}') return True
def is_user_afk(userid): rget = REDIS.get(f'is_afk_{userid}') if rget: return True else: return False
def del_lockables(update, context): chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] user = update.effective_user chat_id = str(chat.id)[1:] approve_list = list(REDIS.sunion(f'approve_list_{chat_id}')) target_user = mention_html(user.id, user.first_name) if target_user in approve_list: return for lockable, filter in LOCK_TYPES.items(): if lockable == "rtl": if sql.is_locked(chat.id, lockable) and can_delete( chat, context.bot.id): if message.caption: check = ad.detect_alphabet(u"{}".format(message.caption)) if "ARABIC" in check: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in lockables") break if message.text: check = ad.detect_alphabet(u"{}".format(message.text)) if "ARABIC" in check: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in lockables") break continue if lockable == "button": if sql.is_locked(chat.id, lockable) and can_delete( chat, context.bot.id): if message.reply_markup and message.reply_markup.inline_keyboard: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in lockables") break continue if lockable == "inline": if sql.is_locked(chat.id, lockable) and can_delete( chat, context.bot.id): if message and message.via_bot: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in lockables") break continue if (filter(update) and sql.is_locked(chat.id, lockable) and can_delete(chat, context.bot.id)): if lockable == "bots": new_members = update.effective_message.new_chat_members for new_mem in new_members: if new_mem.is_bot: if not is_bot_admin(chat, context.bot.id): send_message( update.effective_message, "I see a bot and I've been told to stop them from joining..." "but I'm not admin!", ) return chat.kick_member(new_mem.id) send_message( update.effective_message, "Only admins are allowed to add bots in this chat! Get outta here.", ) break else: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in lockables") break
def afk_reason(userid): return strb(REDIS.get(f'is_afk_{userid}'))