async def sub(event): args = event.pattern_match.group(1) fedowner = sql.get_user_owner_fed_full(event.sender_id) if not fedowner: return await event.reply("Only federation creators can subscribe to a fed. But you don't have a federation!") for f in fedowner: fed_id = f["fed_id"] name = f["fed"]["fname"] if not args: return await event.reply("You need to specify which federation you're asking about by giving me a FedID!") if len(args) < 8: return await event.reply("This isn't a valid FedID format!") getfed = sql.search_fed_by_id(args) if not getfed: return await event.reply("This FedID does not refer to an existing federation.") sname = getfed["fname"] if args == fed_id: return await event.reply("... What's the point in subscribing a fed to itself?") try: subs = luv[fed_id] except: subs = [] if len(subs) > 5: return await event.reply("You can subscribe to at most 5 federations. Please unsubscribe from other federations before adding more.") subfed = sql.subs_fed(args, fed_id) await event.reply(f"Federation {name} has now subscribed to {sname}. All fedbans in {sname} will now take effect in both feds.")
async def log(event): chat = event.chat_id if not is_admin(event, event.sender_id): return await event.reply("You need to be an admin to do this") args = event.pattern_match.group(1) if not args: fedowner = sql.get_user_owner_fed_full(event.sender_id) if not fedowner: return await event.reply( "Only fed creators can set a fed log - but you don't have a federation!" ) for f in fedowner: args = "{}".format(f["fed_id"]) name = f["fed"]["fname"] else: if len(args) < 8: return await event.reply("This isn't a valid FedID format!") getfed = sql.search_fed_by_id(args) name = getfed["fname"] if not getfed: return await event.reply( "This FedID does not refer to an existing federation.") setlog = sql.set_fed_log(args, chat) await event.reply( f"This has been set as the fed log for {name} - all fed related actions will be logged here." )
async def unsub(event): args = event.pattern_match.group(1) fedowner = sql.get_user_owner_fed_full(event.sender_id) if not fedowner: return await event.reply( "Only federation creators can unsubscribe from a fed. But you don't have a federation!" ) for f in fedowner: fed_id = f["fed_id"] name = f["fed"]["fname"] if not args: return await event.reply( "You need to specify which federation you're asking about by giving me a FedID!" ) if len(args) < 8: return await event.reply("This isn't a valid FedID format!") getfed = sql.search_fed_by_id(args) if not getfed: return await event.reply( "This FedID does not refer to an existing federation.") sname = getfed["fname"] remsub = sql.rem_sub(fed_id, args) unsubfed = sql.unsubs_fed(args, fed_id) await event.reply( f"Federation {name} is no longer subscribed to {sname}. Bans in {sname} will no longer be applied.\nPlease note that any bans that happened because the user was banned from the subfed will need to be removed manually." )
async def jf(event): if not event.is_group: return if not await is_admin(event, event.sender_id): await event.reply("You need to be an admin to do this.") return permissions = await tbot.get_permissions(event.chat_id, event.sender_id) if not permissions.is_creator: return await event.reply( f"You need to be the chat owner of {event.chat.title} to do this.") args = event.pattern_match.group(1) if not args: return await event.reply( "You need to specify which federation you're asking about by giving me a FedID!" ) if len(args) < 8: return await event.reply("This isn't a valid FedID format!") getfed = sql.search_fed_by_id(args) name = getfed["fname"] if not getfed: return await event.reply( "This FedID does not refer to an existing federation.") fed_id = sql.get_fed_id(event.chat_id) if fed_id: sql.chat_leave_fed(event.chat_id) x = sql.chat_join_fed(args, event.chat.title, event.chat_id) return await event.reply( f'Successfully joined the "{name}" federation! All new federation bans will now also remove the members from this chat.' )