Beispiel #1
0
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 = sql.MYFEDS_SUBSCRIBER
 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)
 addsub = sql.add_sub(fed_id, args)
 await event.reply(f"Federation {name} has now subscribed to {sname}. All fedbans in {sname} will now take effect in both feds.")
Beispiel #2
0
async def jf(event):
 if not event.is_private and not event.is_group:
   return await channel_fed(event)
 if event.is_private:
   return await event.reply("Only supergroups can join feds.")
 if not await is_admin(event, event.sender_id):
   await event.reply("You need to be an admin to do this.")
   return
 if not await is_admin(event, BOT_ID):
    return await event.reply("I need to be admin with permission to restrict users to join a fed!")
 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.')
Beispiel #3
0
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."
    )
Beispiel #4
0
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."
    )
Beispiel #5
0
async def channel_fed(event):
 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)
 if not getfed:
  return await event.reply("This FedID does not refer to an existing federation.")
 text = "Only channel creators can join a fed; please ask the creator to press this."
 buttons = Button.inline("Join fed", data="jfd_{}".format(args)), Button.inline("Cancel", data="cfd")
 await event.reply(text, buttons=buttons)
Beispiel #6
0
async def dcfd_fed(event):
 tata = event.pattern_match.group(1)
 data = tata.decode()
 args = data.split("_", 1)[1]
 user_id = event.sender_id
 permissions = await tbot.get_permissions(event.chat_id, user_id)
 if not permissions.is_creator:
      return await event.answer(f"You need to be the chat owner of {event.chat.title} to do this.")
 getfed = sql.search_fed_by_id(args)
 name = getfed["fname"]
 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.edit(f'Successfully joined the "{name}" federation! All new federation bans will now also remove the members from this chat.', buttons=None)