async def _(event): try: chat = event.chat user = event.sender args = event.pattern_match.group(1) if event.is_group: if (await is_register_admin(event.input_chat, event.sender_id)): pass else: return if event.is_private: await event.reply( "This command is specific to the group, not to my pm !") return fed_id = sql.get_fed_id(chat.id) if not fed_id: await event.reply("This group is not in any federation!") return if is_user_fed_admin(fed_id, user.id) is False: await event.reply("Only fed admins can do this!") return if args: x = sql.set_frules(fed_id, args) if not x: await event.reply( "There was an error while setting federation rules!\nPlease go to @MissJuliaRobotSupport to report this." ) return rules = sql.get_fed_info(fed_id)['frules'] getfed = sql.get_fed_info(fed_id) get_fedlog = sql.get_fed_log(fed_id) if get_fedlog: if eval(get_fedlog): await tbot.send_message( get_fedlog, "**{}** has updated federation rules for fed **{}**". format(user.first_name, getfed['fname']), parse_mode="markdown") await event.reply(f"Rules have been changed to :\n{rules}!") else: await event.reply("Please give some rules to set.") except Exception as e: print(e)
async def _(event): chat = event.chat user = event.sender if event.is_group: if (await is_register_admin(event.input_chat, event.sender_id)): pass else: return if event.is_private: await event.reply( "This command is specific to the group, not to my pm !") return fed_id = sql.get_fed_id(chat.id) fed_info = sql.get_fed_info(fed_id) if user.id == OWNER_ID: pass else: try: async for userr in tbot.iter_participants( event.chat_id, filter=types.ChannelParticipantsAdmins): if not isinstance(userr.participant, types.ChannelParticipantCreator): aid = userr.id if int(event.sender_id) != int(aid): await event.reply( "Only group creators can use this command!") return except Exception as e: print(e) if sql.chat_leave_fed(chat.id) is True: get_fedlog = sql.get_fed_log(fed_id) if get_fedlog: await tbot.send_message( get_fedlog, "Chat *{}* has left the federation *{}*".format( chat.title, fed_info['fname']), parse_mode="markdown") await event.reply("This group has left the federation **{}**".format( fed_info['fname'])) else: await event.reply( "How can you leave a federation that you never joined ?")
async def _(event): try: chat = event.chat user = event.sender args = event.pattern_match.group(1) if event.is_group: if (await is_register_admin(event.input_chat, event.sender_id)): pass else: return if event.is_private: await event.reply( "This command is specific to the group, not to my pm !") return if not args: await event.reply("Where is the federation ID ?") return fed_id = sql.get_fed_id(chat.id) if user.id in OWNER_ID: pass else: try: async for userr in tbot.iter_participants( event.chat_id, filter=types.ChannelParticipantAdmins): if not isinstance(userr.participant, types.ChannelParticipantCreator): aid = userr.id if int(event.sender_id) == int(aid): await event.reply( "Only group creators can use this command!") return except Exception as e: print(e) if fed_id: await event.reply("You cannot join two federations from one chat") return if len(args) >= 1: getfed = sql.search_fed_by_id(args) if getfed is False: await event.reply("Please enter a valid federation ID") return x = sql.chat_join_fed(args, chat.title, chat.id) if not x: await event.reply( "Failed to join federation! Please contact @MissJuliaRobotSupport should this problem persist!" ) return get_fedlog = sql.get_fed_log(args) if get_fedlog: if eval(get_fedlog): await tbot.send_message( get_fedlog, "Chat *{}* has joined the federation *{}*".format( chat.title, getfed['fname']), parse_mode="markdown") await event.reply( "This group has joined the federation: {}!".format( getfed['fname'])) except Exception as e: print(e)
async def _(event): try: chat = event.chat args = event.pattern_match.group(1) user = event.sender if event.is_group: if (await is_register_admin(event.input_chat, event.sender_id)): pass else: return if event.is_private: await event.reply( "This command is specific to the group, not to my pm !") return fed_id = sql.get_fed_id(chat.id) if not fed_id: await event.reply("This group is not a part of any federation!") return info = sql.get_fed_info(fed_id) getfednotif = sql.user_feds_report(info['owner']) if is_user_fed_admin(fed_id, user.id) is False: await event.reply("Only federation admins can do this!") return if "|" in args: iid, reasonn = args.split("|") cid = iid.strip() reason = reasonn.strip() if cid.isnumeric(): cid = int(cid) entity = await tbot.get_input_entity(cid) try: user_id = entity.user_id except Exception: await event.reply("Couldn't fetch that user.") return if not reason: await event.reply("Need a reason for fban.") return fban, fbanreason, fbantime = sql.get_fban_user(fed_id, user_id) if not user_id: await event.reply("You don't seem to be referring to a user") return if user_id == BOT_ID: await event.reply("Haha you can't fban me.") return if is_user_fed_owner(fed_id, user_id) is True: await event.reply("You are the fed owner.\nI will not fban you !") return if is_user_fed_admin(fed_id, user_id) is True: await event.reply("That's a federation admin, I can't fban.") return if user_id == OWNER_ID: await event.reply("Haha i will never fban my owner !") return if user_id in [777000, 1087968824]: await event.reply("Fool! You can't attack Telegram's native tech!") return try: user_chat = await tbot.get_entity(user_id) isvalid = True fban_user_id = user_chat.id fban_user_name = user_chat.first_name fban_user_lname = user_chat.last_name fban_user_uname = user_chat.username except Exception as e: if not str(user_id).isdigit(): await event.reply(e) return elif len(str(user_id)) != 9: await event.reply("That's not a user!") return isvalid = False fban_user_id = int(user_id) fban_user_name = "user({})".format(user_id) fban_user_lname = None fban_user_uname = None if isvalid and not isinstance(user_chat, User): await event.reply("That's not a user!") return if isvalid: user_target = f"<p><a href='tg://user?id={fban_user_id}'>{fban_user_name}</a></p>" else: user_target = fban_user_name if fban: fed_name = info['fname'] temp = sql.un_fban_user(fed_id, fban_user_id) if not temp: await event.reply("Failed to update the reason for fedban!") return x = sql.fban_user(fed_id, fban_user_id, fban_user_name, fban_user_lname, fban_user_uname, reason, int(time.time())) if not x: await event.reply( "Failed to ban from the federation! If this problem continues, contact @MissJuliaRobotSupport." ) return fed_chats = sql.all_fed_chats(fed_id) # Will send to current chat await tbot.send_message(chat.id, "<b>FedBan reason updated</b>" \ "\n<b>Federation:</b> {}" \ "\n<b>Federation Admin:</b> {}" \ "\n<b>User:</b> {}" \ "\n<b>User ID:</b> <code>{}</code>" \ "\n<b>Reason:</b> {}".format(fed_name, f"<p><a href='tg://user?id={user.id}'>{user.first_name}</a></p>", user_target, fban_user_id, reason), parse_mode="html") # Send message to owner if fednotif is enabled if getfednotif: await tbot.send_message(info['owner'], "<b>FedBan reason updated</b>" \ "\n<b>Federation:</b> {}" \ "\n<b>Federation Admin:</b> {}" \ "\n<b>User:</b> {}" \ "\n<b>User ID:</b> <code>{}</code>" \ "\n<b>Reason:</b> {}".format(fed_name, f"<p><a href='tg://user?id={user.id}'>{user.first_name}</a></p>", user_target, fban_user_id, reason), parse_mode="html") # If fedlog is set, then send message, except fedlog is current chat get_fedlog = sql.get_fed_log(fed_id) if get_fedlog: if int(get_fedlog) != int(chat.id): await tbot.send_message(get_fedlog, "<b>FedBan reason updated</b>" \ "\n<b>Federation:</b> {}" \ "\n<b>Federation Admin:</b> {}" \ "\n<b>User:</b> {}" \ "\n<b>User ID:</b> <code>{}</code>" \ "\n<b>Reason:</b> {}".format(fed_name, f"<p><a href='tg://user?id={user.id}'>{user.first_name}</a></p>", user_target, fban_user_id, reason), parse_mode="html") for fedschat in fed_chats: try: await tbot.kick_participant(fedschat, fban_user_id) except Exception as e: print(e) # Fban for fed subscriber subscriber = list(sql.get_subscriber(fed_id)) if len(subscriber) != 0: for fedsid in subscriber: all_fedschat = sql.all_fed_chats(fedsid) for fedschat in all_fedschat: try: await tbot.kick_participant(fedschat, fban_user_id) except Exception as e: print(e) continue return fed_name = info['fname'] x = sql.fban_user(fed_id, fban_user_id, fban_user_name, fban_user_lname, fban_user_uname, reason, int(time.time())) if not x: await event.reply( "Failed to ban from the federation! If this problem continues, contact @OnePunchSupport." ) return fed_chats = sql.all_fed_chats(fed_id) # Will send to current chat await tbot.send_message(chat.id, "<b>FedBan reason updated</b>" \ "\n<b>Federation:</b> {}" \ "\n<b>Federation Admin:</b> {}" \ "\n<b>User:</b> {}" \ "\n<b>User ID:</b> <code>{}</code>" \ "\n<b>Reason:</b> {}".format(fed_name, f"<p><a href='tg://user?id={user.id}'>{user.first_name}</a></p>", user_target, fban_user_id, reason), parse_mode="html") # Send message to owner if fednotif is enabled if getfednotif: await tbot.send_message(info['owner'], "<b>FedBan reason updated</b>" \ "\n<b>Federation:</b> {}" \ "\n<b>Federation Admin:</b> {}" \ "\n<b>User:</b> {}" \ "\n<b>User ID:</b> <code>{}</code>" \ "\n<b>Reason:</b> {}".format(fed_name, f"<p><a href='tg://user?id={user.id}'>{user.first_name}</a></p>", user_target, fban_user_id, reason), parse_mode="html") # If fedlog is set, then send message, except fedlog is current chat get_fedlog = sql.get_fed_log(fed_id) if get_fedlog: if int(get_fedlog) != int(chat.id): await tbot.send_message(get_fedlog, "<b>FedBan reason updated</b>" \ "\n<b>Federation:</b> {}" \ "\n<b>Federation Admin:</b> {}" \ "\n<b>User:</b> {}" \ "\n<b>User ID:</b> <code>{}</code>" \ "\n<b>Reason:</b> {}".format(fed_name, f"<p><a href='tg://user?id={user.id}'>{user.first_name}</a></p>", user_target, fban_user_id, reason), parse_mode="html") chats_in_fed = 0 for fedschat in fed_chats: chats_in_fed += 1 try: await tbot.kick_participant(fedschat, fban_user_id) except Exception as e: print(e) # Fban for fed subscriber subscriber = list(sql.get_subscriber(fed_id)) if len(subscriber) != 0: for fedsid in subscriber: all_fedschat = sql.all_fed_chats(fedsid) for fedschat in all_fedschat: try: await tbot.kick_participant(fedschat, fban_user_id) except Exception as e: print(e) except Exception as e: print(e)