def fed_info(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] fed_id = sql.get_fed_id(chat.id) if not fed_id: update.effective_message.reply_text( tld(chat.id, "This group is not linked to any federation!")) return if is_user_fed_admin(fed_id, user.id) == False: update.effective_message.reply_text( tld(chat.id, "Only fed admins can do this!")) return print(fed_id) user = update.effective_user # type: Optional[Chat] chat = update.effective_chat # type: Optional[Chat] info = sql.get_fed_info(fed_id) text = "<b>Federation INFO:</b>" text += "\nName: <code>{}</code>".format(info.fed_name) text += "\nID: <code>{}</code>".format(fed_id) R = 0 for O in sql.get_all_fban_users(fed_id): R = R + 1 text += "\nBanned: <code>{}</code>".format(R) text += "\n\n<b>Chats:</b>" h = sql.all_fed_chats(fed_id) for O in h: cht = bot.get_chat(O) text += "\n• {} (<code>{}</code>)".format(cht.title, O) text += "\n\n<b>Admins:</b>" user = bot.get_chat(info.owner_id) text += "\n• {} - <code>{}</code> (Creator)".format( user.first_name, user.id) h = sql.all_fed_users(fed_id) for O in h: user = bot.get_chat(O) text += "\n• {} - <code>{}</code>".format(user.first_name, user.id, O) # Chance 1/5 to add this string to /fedinfo # You can remove this or reduce the percentage, but if you really like my work leave this. num = random.randint(1, 5) print("random ", num) if num == 3: text += "\n\nFederation by MrYacha for YanaBot" update.effective_message.reply_text(text, parse_mode=ParseMode.HTML)
def fed_info(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] fed_id = sql.get_fed_id(chat.id) info = sql.get_fed_info(fed_id) if not fed_id: update.effective_message.reply_text( tld(chat.id, "This group is not in any federation!")) return if is_user_fed_admin(fed_id, user.id) == False: update.effective_message.reply_text( tld(chat.id, "Only fed admins can do this!")) return OW = bot.get_chat(info.owner_id) HAHA = OW.id FEDADMIN = sql.all_fed_users(fed_id) FEDADMIN.append(int(HAHA)) ACTUALADMIN = len(FEDADMIN) print(fed_id) user = update.effective_user # type: Optional[Chat] chat = update.effective_chat # type: Optional[Chat] info = sql.get_fed_info(fed_id) text = "<b>Fed info:</b>" text += "\nFedID: <code>{}</code>".format(fed_id) text += "\nName: {}".format(info.fed_name) text += "\nCreator: {}".format(mention_html(HAHA, "this guy")) text += "\nNumber of admins: <code>{}</code>".format(ACTUALADMIN) R = 0 for O in sql.get_all_fban_users(fed_id): R = R + 1 text += "\nNumber of bans: <code>{}</code>".format(R) h = sql.all_fed_chats(fed_id) asdf = len(h) text += "\nNumber of connected chats: <code>{}</code>".format(asdf) update.effective_message.reply_text(text, parse_mode=ParseMode.HTML)
def fed_info(bot: Bot, update: Update, args: List[str]): spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id) if spam == True: return update.effective_message.reply_text("Spammer detected! Ignoring user.") chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] fed_id = sql.get_fed_id(chat.id) info = sql.get_fed_info(fed_id) if not fed_id: update.effective_message.reply_text("This group is not in any federation!") return if is_user_fed_admin(fed_id, user.id) == False: update.effective_message.reply_text("Only a federation admin can do this!") return owner = bot.get_chat(info['owner']) try: owner_name = owner.first_name + " " + owner.last_name except: owner_name = owner.first_name FEDADMIN = sql.all_fed_users(fed_id) FEDADMIN.append(int(owner.id)) TotalAdminFed = len(FEDADMIN) user = update.effective_user # type: Optional[Chat] chat = update.effective_chat # type: Optional[Chat] info = sql.get_fed_info(fed_id) text = "<b>ℹ️ Federation Information:</b>" text += "\nFedID: <code>{}</code>".format(fed_id) text += "\nName: {}".format(info['fname']) text += "\nCreator: {}".format(mention_html(owner.id, owner_name)) text += "\nAll Admins: <code>{}</code>".format(TotalAdminFed) getfban = sql.get_all_fban_users(fed_id) text += "\nTotal banned users: <code>{}</code>".format(len(getfban)) getfchat = sql.all_fed_chats(fed_id) text += "\nNumber of groups in this federation: <code>{}</code>".format(len(getfchat)) update.effective_message.reply_text(text, parse_mode=ParseMode.HTML)
def fed_ban_list(bot: Bot, update: Update, args: List[str], chat_data): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] fed_id = sql.get_fed_id(chat.id) info = sql.get_fed_info(fed_id) if not fed_id: update.effective_message.reply_text("This group is not a part of any federation!") return if is_user_fed_owner(fed_id, user.id) == False: update.effective_message.reply_text("Only federation owners can do this!") return user = update.effective_user # type: Optional[Chat] chat = update.effective_chat # type: Optional[Chat] getfban = sql.get_all_fban_users(fed_id) if len(getfban) == 0: update.effective_message.reply_text("The federation ban list of {} is empty.".format(info['fname']), parse_mode=ParseMode.HTML) return if args: if args[0] == 'json': jam = time.time() new_jam = jam + 1800 cek = get_chat(chat.id, chat_data) if cek.get('status'): if jam <= int(cek.get('value')): waktu = time.strftime("%H:%M:%S %d/%m/%Y", time.localtime(cek.get('value'))) update.effective_message.reply_text("You can back up your data once every 30 minutes!\nYou can back up data again at `{}`".format(waktu), parse_mode=ParseMode.MARKDOWN) return else: if user.id not in SUDO_USERS: put_chat(chat.id, new_jam, chat_data) else: if user.id not in SUDO_USERS: put_chat(chat.id, new_jam, chat_data) backups = "" for users in getfban: getuserinfo = sql.get_all_fban_users_target(fed_id, users) json_parser = {"user_id": users, "first_name": getuserinfo['first_name'], "last_name": getuserinfo['last_name'], "user_name": getuserinfo['user_name'], "reason": getuserinfo['reason']} backups += json.dumps(json_parser) backups += "\n" with BytesIO(str.encode(backups)) as output: output.name = "rin_fbanned_users.json" update.effective_message.reply_document(document=output, filename="rin_fbanned_users.json", caption="Total {} User are blocked by the Federation {}.".format(len(getfban), info['fname'])) return elif args[0] == 'csv': jam = time.time() new_jam = jam + 1800 cek = get_chat(chat.id, chat_data) if cek.get('status'): if jam <= int(cek.get('value')): waktu = time.strftime("%H:%M:%S %d/%m/%Y", time.localtime(cek.get('value'))) update.effective_message.reply_text("You can back up data once every 30 minutes!\nYou can back up data again at `{}`".format(waktu), parse_mode=ParseMode.MARKDOWN) return else: if user.id not in SUDO_USERS: put_chat(chat.id, new_jam, chat_data) else: if user.id not in SUDO_USERS: put_chat(chat.id, new_jam, chat_data) backups = "id,firstname,lastname,username,reason\n" for users in getfban: getuserinfo = sql.get_all_fban_users_target(fed_id, users) backups += "{user_id},{first_name},{last_name},{user_name},{reason}".format(user_id=users, first_name=getuserinfo['first_name'], last_name=getuserinfo['last_name'], user_name=getuserinfo['user_name'], reason=getuserinfo['reason']) backups += "\n" with BytesIO(str.encode(backups)) as output: output.name = "rin_fbanned_users.csv" update.effective_message.reply_document(document=output, filename="rin_fbanned_users.csv", caption="Total {} User are blocked by Federation {}.".format(len(getfban), info['fname'])) return text = "<b>{} users have been banned from the federation {}:</b>\n".format(len(getfban), info['fname']) for users in getfban: getuserinfo = sql.get_all_fban_users_target(fed_id, users) if getuserinfo == False: text = "There are no users banned from the federation {}".format(info['fname']) break user_name = getuserinfo['first_name'] if getuserinfo['last_name']: user_name += " " + getuserinfo['last_name'] text += " • {} (<code>{}</code>)\n".format(mention_html(users, user_name), users) try: update.effective_message.reply_text(text, parse_mode=ParseMode.HTML) except: jam = time.time() new_jam = jam + 1800 cek = get_chat(chat.id, chat_data) if cek.get('status'): if jam <= int(cek.get('value')): waktu = time.strftime("%H:%M:%S %d/%m/%Y", time.localtime(cek.get('value'))) update.effective_message.reply_text("You can back up data once every 30 minutes!\nYou can back up data again at `{}`".format(waktu), parse_mode=ParseMode.MARKDOWN) return else: if user.id not in SUDO_USERS: put_chat(chat.id, new_jam, chat_data) else: if user.id not in SUDO_USERS: put_chat(chat.id, new_jam, chat_data) cleanr = re.compile('<.*?>') cleantext = re.sub(cleanr, '', text) with BytesIO(str.encode(cleantext)) as output: output.name = "fbanlist.txt" update.effective_message.reply_document(document=output, filename="fbanlist.txt", caption="The following is the list of users who are currently fbanned in the Federation {}.".format(info['fname']))