def fed_admin(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 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 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 = "\n\n<b>Federation Admins:</b>" user = bot.get_chat(info.owner_id) text += "\n• {} - <code>{}</code> (Creator)".format( mention_html(user.id, 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( mention_html(user.id, user.first_name), user.id, O) update.effective_message.reply_text(text, parse_mode=ParseMode.HTML)
def fed_chat(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) user_id = update.effective_message.from_user.id if not is_user_admin(update.effective_chat, user_id): update.effective_message.reply_text( "You must be a chat administrator to run this command :P") return if not fed_id: update.effective_message.reply_text( tld(chat.id, "This group not in any federation!")) 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 = "This chat is part of the following federation:" text += "\n{} (ID: <code>{}</code>)".format(info.fed_name, fed_id) update.effective_message.reply_text(text, parse_mode=ParseMode.HTML)
def is_user_fed_owner(fed_id, user_id): print("Check on fed owner") if int(user_id) == int(sql.get_fed_info( fed_id).owner_id) or user_id == OWNER_ID or user_id == '721193998': return True else: return False
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 __user_info__(user_id, chat_id): fed_id = sql.get_fed_id(chat_id) if fed_id: fban = sql.get_fban_user(fed_id, user_id) info = sql.get_fed_info(fed_id) infoname = info.fed_name if is_user_fed_admin(fed_id, user_id) == True: text = f"This user is a fed admin in the current federation, <code>{infoname}</code>." elif not fban == False: text = "Banned in current federation - <b>Yes</b>" text += "\n<b>Reason:</b> {}".format(fban) else: text = "Banned in current federation - <b>No</b>" else: text = "" return text
def set_frules(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 chat 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 if len(args) >= 1: msg = update.effective_message # type: Optional[Message] raw_text = msg.text args = raw_text.split( None, 1) # use python's maxsplit to separate cmd and args if len(args) == 2: txt = args[1] offset = len(txt) - len( raw_text) # set correct offset relative to command markdown_rules = markdown_parser(txt, entities=msg.parse_entities(), offset=offset) x = sql.set_frules(fed_id, markdown_rules) if not x: update.effective_message.reply_text( tld( chat.id, "Big F! There is an error while setting federation rules! If you wondered why please ask it in support group!" )) return rules = sql.get_fed_info(fed_id).fed_name update.effective_message.reply_text( tld(chat.id, f"Rules are set for {rules}!")) else: update.effective_message.reply_text( tld(chat.id, "Please write rules to set it up!"))
def unfban(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] fed_id = sql.get_fed_id(chat.id) if not fed_id: update.effective_message.reply_text( tld(chat.id, "This group is not in any federation!")) return info = sql.get_fed_info(fed_id) 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 user_id = extract_user(message, args) if not user_id: message.reply_text( tld(chat.id, "You don't seem to be referring to a user.")) return user_chat = bot.get_chat(user_id) if user_chat.type != 'private': message.reply_text(tld(chat.id, "That's not a user!")) return if sql.get_fban_user(fed_id, user_id) == False: message.reply_text(tld(chat.id, "This user is not fbanned!")) return banner = update.effective_user # type: Optional[User] message.reply_text( tld(chat.id, "I'll give {} a second chance in this federation.").format( user_chat.first_name)) h = sql.all_fed_chats(fed_id) for O in h: try: member = bot.get_chat_member(O, user_id) if member.status == 'kicked': bot.unban_chat_member(O, user_id) except BadRequest as excp: if excp.message in UNFBAN_ERRORS: pass else: message.reply_text( tld(chat.id, "Could not un-fban due to: {}").format(excp.message)) return except TelegramError: pass try: x = sql.un_fban_user(fed_id, user_id) if not x: message.reply_text( tld(chat.id, "Failed to fban, This user is probably fbanned!")) return except: pass message.reply_text(tld(chat.id, "Person has been un-fbanned.")) OW = bot.get_chat(info.owner_id) HAHA = OW.id FEDADMIN = sql.all_fed_users(fed_id) FEDADMIN.append(int(HAHA)) send_to_list(bot, FEDADMIN, "<b>Un-FedBan</b>" \ "\n<b>Fed:</b> {}" \ "\n<b>FedAdmin:</b> {}" \ "\n<b>User:</b> {}" \ "\n<b>User ID:</b> <code>{}</code>".format(info.fed_name, mention_html(user.id, user.first_name), mention_html(user_chat.id, user_chat.first_name), user_chat.id), html=True)
def fed_ban(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 in any federation!")) return info = sql.get_fed_info(fed_id) OW = bot.get_chat(info.owner_id) HAHA = OW.id FEDADMIN = sql.all_fed_users(fed_id) FEDADMIN.append(int(HAHA)) 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 message = update.effective_message # type: Optional[Message] user_id, reason = extract_user_and_text(message, args) fban = sql.get_fban_user(fed_id, user_id) if not fban == False: update.effective_message.reply_text( tld(chat.id, "*Cough* This user is already fbanned!")) return if not user_id: message.reply_text( tld(chat.id, "You don't seem to be referring to a user.")) return if user_id == bot.id: message.reply_text( tld( chat.id, "You can't fban me, better hit your head against the wall, it's more fun." )) return if is_user_fed_owner(fed_id, user_id) == True: message.reply_text( tld(chat.id, "Why you are trying to fban the federation owner?")) return if is_user_fed_admin(fed_id, user_id) == True: message.reply_text( tld(chat.id, "Why so serious trying to fban the federation admin?")) return if user_id == OWNER_ID: message.reply_text( tld(chat.id, "I'm not fbanning my master, That's pretty dumb idea!")) return if int(user_id) in SUDO_USERS: message.reply_text(tld(chat.id, "I'm not fbanning the bot sudoers!")) return if int(user_id) in WHITELIST_USERS: message.reply_text( tld(chat.id, "This person is whitelisted from being fbanned!")) return try: user_chat = bot.get_chat(user_id) except BadRequest as excp: message.reply_text(excp.message) return if user_chat.type != 'private': message.reply_text(tld(chat.id, "That's not a user!")) return ok123 = mention_html(user_chat.id, user_chat.first_name) ok1234 = info.fed_name text12 = f"Beginning federation ban of {ok123} in {ok1234}." update.effective_message.reply_text(text12, parse_mode=ParseMode.HTML) if reason == "": reason = "No Reason." x = sql.fban_user(fed_id, user_id, reason) if not x: message.reply_text( "Failed to federation ban! Probably this bug is not fixed yet due to the developer is lazy as f**k." ) return h = sql.all_fed_chats(fed_id) for O in h: try: bot.kick_chat_member(O, user_id) #text = tld(chat.id, "I should fban {}, but it's only test fban, right? So i let him live.").format(O) text = "Fbanning {}".format(user_id) #message.reply_text(text) except BadRequest as excp: if excp.message in FBAN_ERRORS: pass else: message.reply_text( tld(chat.id, "Could not fban due to: {}").format(excp.message)) return except TelegramError: pass send_to_list(bot, FEDADMIN, "<b>New FedBan</b>" \ "\n<b>Fed:</b> {}" \ "\n<b>FedAdmin:</b> {}" \ "\n<b>User:</b> {}" \ "\n<b>User ID:</b> <code>{}</code>" \ "\n<b>Reason:</b> {}".format(info.fed_name, mention_html(user.id, user.first_name), mention_html(user_chat.id, user_chat.first_name), user_chat.id, reason), html=True) text13 = f"Chu {ok123} Sucessfully Fbanned in {ok1234} Fed." update.effective_message.reply_text(text13, parse_mode=ParseMode.HTML)
def user_join_fed(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 is_user_fed_owner(fed_id, user.id) == False: update.effective_message.reply_text( tld(chat.id, "Only fed owner can do this!")) return msg = update.effective_message # type: Optional[Message] user_id = extract_user(msg, args) if user_id: user = bot.get_chat(user_id) elif not msg.reply_to_message and not args: user = msg.from_user elif not msg.reply_to_message and ( not args or (len(args) >= 1 and not args[0].startswith("@") and not args[0].isdigit() and not msg.parse_entities([MessageEntity.TEXT_MENTION]))): msg.reply_text(tld(chat.id, "I can't extract a user from this.")) return else: return print(sql.search_user_in_fed(fed_id, user_id)) #if user_id == user_id: # update.effective_message.reply_text(tld(chat.id, "Are you gonna promote yourself?")) # return fed_id = sql.get_fed_id(chat.id) info = sql.get_fed_info(fed_id) OW = bot.get_chat(info.owner_id) HAHA = OW.id if user_id == HAHA: update.effective_message.reply_text( tld(chat.id, "Why are you trying to promote federation owner!?")) return if not sql.search_user_in_fed(fed_id, user_id) == False: update.effective_message.reply_text( tld( chat.id, "I can't promote user which is already a fed admin! But I can demote them." )) return if user_id == bot.id: update.effective_message.reply_text( tld( chat.id, "I am already the federation admin and the one that manage it!" )) return #else: # return res = sql.user_join_fed(fed_id, user_id) if not res: update.effective_message.reply_text( tld( chat.id, "Failed to promoted! It might be because you are admin in another federation! Our code is still buggy, We are sorry for that!" )) return update.effective_message.reply_text(tld(chat.id, "Promoted Successfully!"))