Beispiel #1
0
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 AVATAR, 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)
Beispiel #2
0
def temp_ban(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]

    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text(tld(chat.id, "You don't seem to be referring to a user."))
        return ""

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text(tld(chat.id, "I can't seem to find this user"))
            return ""
        else:
            raise

    if is_user_ban_protected(chat, user_id, member):
        message.reply_text(tld(chat.id, "This user is ban protected, meaning that you cannot ban this user!"))
        return ""

    if user_id == bot.id:
        message.reply_text(tld(chat.id, "I'm not gonna BAN myself, are you crazy?"))
        return ""

    if not reason:
        message.reply_text(tld(chat.id, "You haven't specified a time to ban this user for!"))
        return ""

    split_reason = reason.split(None, 1)

    time_val = split_reason[0].lower()
    if len(split_reason) > 1:
        reason = split_reason[1]
    else:
        reason = ""

    bantime = extract_time(message, time_val)

    if not bantime:
        return ""

    log = "<b>{}:</b>" \
          "\n#TEMP BANNED" \
          "\n<b>Admin:</b> {}" \
          "\n<b>User:</b> {} (<code>{}</code>)" \
          "\n<b>Time:</b> {}".format(html.escape(chat.title),
                                     mention_html(user.id, user.first_name),
                                     mention_html(member.user.id, member.user.first_name),
                                     member.user.id,
                                     time_val)
    if reason:
        log += "\n<b>Reason:</b> {}".format(reason)

    try:
        chat.kick_member(user_id, until_date=bantime)
        bot.send_sticker(chat.id, BAN_STICKER)  # banhammer marie sticker
        message.reply_text("Banned! User will be banned for {}.".format(time_val))
        return log

    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            bot.send_sticker(chat.id, BAN_STICKER)  # banhammer marie sticker
            message.reply_text(tld(chat.id, "Banned! User will be banned for {}.").format(time_val), quote=False)
            return log
        else:
            LOGGER.warning(update)
            LOGGER.exception("ERROR banning user %s in chat %s (%s) due to %s", user_id, chat.title, chat.id,
                             excp.message)
            message.reply_text(tld(chat.id, "Well damn, I can't ban that user."))

    return ""
Beispiel #3
0
def control_panel(bot, update):
    chat = update.effective_chat
    user = update.effective_user

    # ONLY send help in PM
    if chat.type != chat.PRIVATE:

        update.effective_message.reply_text(
            "Contact me in PM to access the control panel.",
            reply_markup=InlineKeyboardMarkup([[
                InlineKeyboardButton(
                    text="Control Panel",
                    url=f"t.me/{bot.username}?start=controlpanel")
            ]]))
        return

    #Support to run from command handler
    query = update.callback_query
    if query:

        try:
            query.message.delete()
        except BadRequest as ee:
            update.effective_message.reply_text(
                f"Failed to delete query, {ee}")

        M_match = re.match(r"cntrl_panel_M", query.data)
        U_match = re.match(r"cntrl_panel_U", query.data)
        G_match = re.match(r"cntrl_panel_G", query.data)
        back_match = re.match(r"help_back", query.data)

    else:
        M_match = "Haruka Aya is best bot"  #LMAO, don't uncomment

    if M_match:
        text = "*Control panel* 🛠"

        keyboard = [[
            InlineKeyboardButton(text="👤 My settings",
                                 callback_data="cntrl_panel_U(1)")
        ]]

        #Show connected chat and add chat settings button
        conn = connected(bot, update, chat, user.id, need_admin=False)

        if conn:
            chatG = bot.getChat(conn)
            #admin_list = chatG.get_administrators() #Unused variable

            #If user admin
            member = chatG.get_member(user.id)
            if member.status in ('administrator', 'creator'):
                text += f"\nConnected chat - *{chatG.title}* (you {member.status})"
                keyboard += [[
                    InlineKeyboardButton(text="👥 Group settings",
                                         callback_data="cntrl_panel_G_back")
                ]]
            elif user.id in SUDO_USERS:
                text += f"\nConnected chat - *{chatG.title}* (you sudo)"
                keyboard += [[
                    InlineKeyboardButton(text="👥 Group settings (SUDO)",
                                         callback_data="cntrl_panel_G_back")
                ]]
            else:
                text += f"\nConnected chat - *{chatG.title}* (you aren't an admin!)"
        else:
            text += "\nNo chat connected!"

        keyboard += [[
            InlineKeyboardButton(text="⬅️ Back", callback_data="bot_start")
        ]]

        update.effective_message.reply_text(
            text,
            reply_markup=InlineKeyboardMarkup(keyboard),
            parse_mode=ParseMode.MARKDOWN)

    elif U_match:

        mod_match = re.match(r"cntrl_panel_U_module\((.+?)\)", query.data)
        back_match = re.match(r"cntrl_panel_U\((.+?)\)", query.data)

        chatP = update.effective_chat  # type: Optional[Chat]
        if mod_match:
            module = mod_match.group(1)

            R = CHAT_SETTINGS[module].__user_settings__(bot, update, user)

            text = "You has the following settings for the *{}* module:\n\n".format(
                CHAT_SETTINGS[module].__mod_name__) + R[0]

            keyboard = R[1]
            keyboard += [[
                InlineKeyboardButton(text="⬅️ Back",
                                     callback_data="cntrl_panel_U(1)")
            ]]

            query.message.reply_text(
                text=text,
                arse_mode=ParseMode.MARKDOWN,
                reply_markup=InlineKeyboardMarkup(keyboard))

        elif back_match:
            text = "*User control panel* 🛠"

            query.message.reply_text(text=text,
                                     parse_mode=ParseMode.MARKDOWN,
                                     reply_markup=InlineKeyboardMarkup(
                                         paginate_modules(
                                             user.id, 0, USER_SETTINGS,
                                             "cntrl_panel_U")))

    elif G_match:
        mod_match = re.match(r"cntrl_panel_G_module\((.+?)\)", query.data)
        prev_match = re.match(r"cntrl_panel_G_prev\((.+?)\)", query.data)
        next_match = re.match(r"cntrl_panel_G_next\((.+?)\)", query.data)
        back_match = re.match(r"cntrl_panel_G_back", query.data)

        chatP = chat
        conn = connected(bot, update, chat, user.id)

        if conn:
            chat = bot.getChat(conn)
        else:
            query.message.reply_text(text="Error with connection to chat")
            exit(1)

        if mod_match:
            module = mod_match.group(1)
            R = CHAT_SETTINGS[module].__chat_settings__(
                bot, update, chat, chatP, user)

            if type(R) is list:
                text = R[0]
                keyboard = R[1]
            else:
                text = R
                keyboard = []

            text = "*{}* has the following settings for the *{}* module:\n\n".format(
                escape_markdown(chat.title),
                CHAT_SETTINGS[module].__mod_name__) + text

            keyboard += [[
                InlineKeyboardButton(text="Back",
                                     callback_data="cntrl_panel_G_back")
            ]]

            query.message.reply_text(
                text=text,
                parse_mode=ParseMode.MARKDOWN,
                reply_markup=InlineKeyboardMarkup(keyboard))

        elif prev_match:
            chat_id = prev_match.group(1)
            curr_page = int(prev_match.group(2))
            chat = bot.get_chat(chat_id)
            query.message.reply_text(tld(
                user.id, "send-group-settings").format(chat.title),
                                     reply_markup=InlineKeyboardMarkup(
                                         paginate_modules(curr_page - 1,
                                                          0,
                                                          CHAT_SETTINGS,
                                                          "cntrl_panel_G",
                                                          chat=chat_id)))

        elif next_match:
            chat_id = next_match.group(1)
            next_page = int(next_match.group(2))
            chat = bot.get_chat(chat_id)
            query.message.reply_text(tld(
                user.id, "send-group-settings").format(chat.title),
                                     reply_markup=InlineKeyboardMarkup(
                                         paginate_modules(next_page + 1,
                                                          0,
                                                          CHAT_SETTINGS,
                                                          "cntrl_panel_G",
                                                          chat=chat_id)))

        elif back_match:
            text = "Control Panel :3"
            query.message.reply_text(text=text,
                                     parse_mode=ParseMode.MARKDOWN,
                                     reply_markup=InlineKeyboardMarkup(
                                         paginate_modules(
                                             user.id, 0, CHAT_SETTINGS,
                                             "cntrl_panel_G")))
Beispiel #4
0
def __import_data__(chat_id, data):
    failures = []
    for notename, notedata in data.get('extra', {}).items():
        match = FILE_MATCHER.match(notedata)
        matchsticker = STICKER_MATCHER.match(notedata)
        matchbtn = BUTTON_MATCHER.match(notedata)
        matchfile = MYFILE_MATCHER.match(notedata)
        matchphoto = MYPHOTO_MATCHER.match(notedata)
        matchaudio = MYAUDIO_MATCHER.match(notedata)
        matchvoice = MYVOICE_MATCHER.match(notedata)
        matchvideo = MYVIDEO_MATCHER.match(notedata)
        matchvn = MYVIDEONOTE_MATCHER.match(notedata)

        if match:
            failures.append(notename)
            notedata = notedata[match.end():].strip()
            if notedata:
                sql.add_note_to_db(chat_id, notename[1:], notedata,
                                   sql.Types.TEXT)
        elif matchsticker:
            content = notedata[matchsticker.end():].strip()
            if content:
                sql.add_note_to_db(chat_id,
                                   notename[1:],
                                   notedata,
                                   sql.Types.STICKER,
                                   file=content)
        elif matchbtn:
            parse = notedata[matchbtn.end():].strip()
            notedata = parse.split("<###button###>")[0]
            buttons = parse.split("<###button###>")[1]
            buttons = ast.literal_eval(buttons)
            if buttons:
                sql.add_note_to_db(chat_id,
                                   notename[1:],
                                   notedata,
                                   sql.Types.BUTTON_TEXT,
                                   buttons=buttons)
        elif matchfile:
            file = notedata[matchfile.end():].strip()
            file = file.split("<###TYPESPLIT###>")
            notedata = file[1]
            content = file[0]
            if content:
                sql.add_note_to_db(chat_id,
                                   notename[1:],
                                   notedata,
                                   sql.Types.DOCUMENT,
                                   file=content)
        elif matchphoto:
            photo = notedata[matchphoto.end():].strip()
            photo = photo.split("<###TYPESPLIT###>")
            notedata = photo[1]
            content = photo[0]
            if content:
                sql.add_note_to_db(chat_id,
                                   notename[1:],
                                   notedata,
                                   sql.Types.PHOTO,
                                   file=content)
        elif matchaudio:
            audio = notedata[matchaudio.end():].strip()
            audio = audio.split("<###TYPESPLIT###>")
            notedata = audio[1]
            content = audio[0]
            if content:
                sql.add_note_to_db(chat_id,
                                   notename[1:],
                                   notedata,
                                   sql.Types.AUDIO,
                                   file=content)
        elif matchvoice:
            voice = notedata[matchvoice.end():].strip()
            voice = voice.split("<###TYPESPLIT###>")
            notedata = voice[1]
            content = voice[0]
            if content:
                sql.add_note_to_db(chat_id,
                                   notename[1:],
                                   notedata,
                                   sql.Types.VOICE,
                                   file=content)
        elif matchvideo:
            video = notedata[matchvideo.end():].strip()
            video = video.split("<###TYPESPLIT###>")
            notedata = video[1]
            content = video[0]
            if content:
                sql.add_note_to_db(chat_id,
                                   notename[1:],
                                   notedata,
                                   sql.Types.VIDEO,
                                   file=content)
        elif matchvn:
            video_note = notedata[matchvn.end():].strip()
            video_note = video_note.split("<###TYPESPLIT###>")
            notedata = video_note[1]
            content = video_note[0]
            if content:
                sql.add_note_to_db(chat_id,
                                   notename[1:],
                                   notedata,
                                   sql.Types.VIDEO_NOTE,
                                   file=content)
        else:
            sql.add_note_to_db(chat_id, notename[1:], notedata, sql.Types.TEXT)

    if failures:
        with BytesIO(str.encode("\n".join(failures))) as output:
            output.name = "failed_imports.txt"
            text_caption = tld(chat.id, "note_fail_to_import")
            dispatcher.bot.send_document(chat_id,
                                         document=output,
                                         filename="failed_imports.txt",
                                         caption=text_caption)
Beispiel #5
0
def connect_chat(bot, update, args):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    if update.effective_chat.type == 'private':
        if len(args) >= 1:
            try:
                connect_chat = int(args[0])
            except ValueError:
                update.effective_message.reply_text(
                    tld(chat.id, "common_err_invalid_chatid"))
                return
            if (bot.get_chat_member(
                    connect_chat, update.effective_message.from_user.id).status
                    in ('administrator', 'creator') or
                (sql.allow_connect_to_chat(connect_chat) == True)
                    and bot.get_chat_member(
                        connect_chat,
                        update.effective_message.from_user.id).status in
                ('member')) or (user.id in SUDO_USERS):

                connection_status = sql.connect(
                    update.effective_message.from_user.id, connect_chat)
                if connection_status:
                    chat_name = dispatcher.bot.getChat(
                        connected(bot, update, chat, user.id,
                                  need_admin=False)).title
                    update.effective_message.reply_text(
                        tld(chat.id, "connection_success").format(chat_name),
                        parse_mode=ParseMode.MARKDOWN)

                    #Add chat to connection history
                    history = sql.get_history(user.id)
                    if history:
                        #Vars
                        if history.chat_id1:
                            history1 = int(history.chat_id1)
                        if history.chat_id2:
                            history2 = int(history.chat_id2)
                        if history.chat_id3:
                            history3 = int(history.chat_id3)
                        if history.updated:
                            number = history.updated

                        if number == 1 and connect_chat != history2 and connect_chat != history3:
                            history1 = connect_chat
                            number = 2
                        elif number == 2 and connect_chat != history1 and connect_chat != history3:
                            history2 = connect_chat
                            number = 3
                        elif number >= 3 and connect_chat != history2 and connect_chat != history1:
                            history3 = connect_chat
                            number = 1
                        else:
                            print("Error")

                        print(history.updated)
                        print(number)

                        sql.add_history(user.id, history1, history2, history3,
                                        number)
                        # print(history.user_id, history.chat_id1, history.chat_id2, history.chat_id3, history.updated)
                    else:
                        sql.add_history(user.id, connect_chat, "0", "0", 2)
                    # Rebuild user's keyboard
                    keyboard(bot, update)

                else:
                    update.effective_message.reply_text(
                        tld(chat.id, "connection_fail"))
            else:
                update.effective_message.reply_text(
                    tld(chat.id, "connection_err_not_allowed"))
        else:
            update.effective_message.reply_text(
                tld(chat.id, "connection_err_no_chatid"))
            history = sql.get_history(user.id)
            # print(history.user_id, history.chat_id1, history.chat_id2, history.chat_id3, history.updated)

    elif update.effective_chat.type == 'supergroup':
        connect_chat = chat.id
        if (bot.get_chat_member(connect_chat,
                                update.effective_message.from_user.id).status
                in ('administrator', 'creator') or
            (sql.allow_connect_to_chat(connect_chat) == True)
                and bot.get_chat_member(
                    connect_chat, update.effective_message.from_user.id).status
                in 'member') or (user.id in SUDO_USERS):

            connection_status = sql.connect(
                update.effective_message.from_user.id, connect_chat)
            if connection_status:
                update.effective_message.reply_text(
                    tld(chat.id, "connection_success").format(chat.id),
                    parse_mode=ParseMode.MARKDOWN)
            else:
                update.effective_message.reply_text(
                    tld(chat.id, "connection_fail"),
                    parse_mode=ParseMode.MARKDOWN)
        else:
            update.effective_message.reply_text(
                tld(chat.id, "common_err_not_admin"))

    else:
        update.effective_message.reply_text(tld(chat.id, "common_cmd_pm_only"))
Beispiel #6
0
def runs(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    update.effective_message.reply_text(random.choice(tld(chat.id, "RUNS-K")))
Beispiel #7
0
DATA_EXPORT = []

GDPR = []

for module_name in ALL_MODULES:
    imported_module = importlib.import_module("haruka.modules." + module_name)
    modname = imported_module.__name__.split('.')[2]

    if not modname.lower() in IMPORTED:
        IMPORTED[modname.lower()] = imported_module
    else:
        raise Exception(
            "Can't have two modules with the same name! Please change one")

    if hasattr(imported_module, "__help__") and imported_module.__help__:
        HELPABLE[modname.lower()] = tld(0, "modname_" + modname).strip()

    # Chats to migrate on chat_migrated events
    if hasattr(imported_module, "__migrate__"):
        MIGRATEABLE.append(imported_module)

    if hasattr(imported_module, "__stats__"):
        STATS.append(imported_module)

    if hasattr(imported_module, "__gdpr__"):
        GDPR.append(imported_module)

    if hasattr(imported_module, "__user_info__"):
        USER_INFO.append(imported_module)

    if hasattr(imported_module, "__import_data__"):
Beispiel #8
0
def extract_user_and_text(message: Message,
                          args: List[str]) -> (Optional[int], Optional[str]):
    chat = message.chat  # type: Optional[Chat]
    prev_message = message.reply_to_message
    split_text = message.text.split(None, 1)

    if len(split_text) < 2:
        return id_from_reply(message)  # only option possible

    text_to_parse = split_text[1]

    text = ""

    entities = list(message.parse_entities([MessageEntity.TEXT_MENTION]))
    if len(entities) > 0:
        ent = entities[0]
    else:
        ent = None

    # if entity offset matches (command end/text start) then all good
    if entities and ent and ent.offset == len(
            message.text) - len(text_to_parse):
        ent = entities[0]
        user_id = ent.user.id
        text = message.text[ent.offset + ent.length:]

    elif len(args) >= 1 and args[0][0] == '@':
        user = args[0]
        user_id = get_user_id(user)
        if not user_id:
            message.reply_text(tld(chat.id, 'helpers_user_not_in_db'))
            return None, None

        else:
            user_id = user_id
            res = message.text.split(None, 2)
            if len(res) >= 3:
                text = res[2]

    elif len(args) >= 1 and args[0].isdigit():
        user_id = int(args[0])
        res = message.text.split(None, 2)
        if len(res) >= 3:
            text = res[2]

    elif prev_message:
        user_id, text = id_from_reply(message)

    else:
        return None, None

    try:
        message.bot.get_chat(user_id)
    except BadRequest as excp:
        if excp.message in ("User_id_invalid", "Chat not found"):
            message.reply_text(tld(chat.id, 'helpers_user_not_in_db'))
        else:
            LOGGER.exception("Exception %s on user %s", excp.message, user_id)

        return None, None

    return user_id, text
Beispiel #9
0
def fed_stat_user(bot, update, args):

	chat = update.effective_chat  # type: Optional[Chat]

	user = update.effective_user  # type: Optional[User]
	msg = update.effective_message  # type: Optional[Message]

	if args:
		if args[0].isdigit():
			user_id = args[0]
		else:
			user_id = extract_user(msg, args)
	else:
		user_id = extract_user(msg, args)

	if user_id:
		if len(args) == 2 and args[0].isdigit():
			fed_id = args[1]
			user_name, reason, fbantime = sql.get_user_fban(fed_id, str(user_id))
			if fbantime:
				fbantime = time.strftime("%d/%m/%Y", time.localtime(fbantime))
			else:
				fbantime = "Unavaiable"
			if user_name == False:
				send_message(update.effective_message, tld(update.effective_message, "Federation {} not found!").format(fed_id), parse_mode="markdown")
				return
			if user_name == "" or user_name == None:
				user_name = tld(update.effective_message, "Day")
			if not reason:
				send_message(update.effective_message, tld(update.effective_message, "{} has not been banned in this federation!").format(user_name))
			else:
				text = tld(update.effective_message, "{} banned in this federation because:\n`{}`\n*Banned on:* `{}`").format(user_name, reason, fbantime)
				send_message(update.effective_message, text, parse_mode="markdown")
			return
		user_name, fbanlist = sql.get_user_fbanlist(str(user_id))
		if user_name == "":
			try:
				user_name = bot.get_chat(user_id).first_name
			except BadRequest:
				user_name = tld(update.effective_message, "Day")
			if user_name == "" or user_name == None:
				user_name = tld(update.effective_message, "Day")
		if len(fbanlist) == 0:
			send_message(update.effective_message, tld(update.effective_message, "{} not yet banned in any federation!").format(user_name))
			return
		else:
			text = tld(update.effective_message, "{} has been banned in this federation:\n").format(user_name)
			for x in fbanlist:
				text += "- `{}`: {}\n".format(x[0], x[1][:20])
			text += tld(update.effective_message, "\nIf you want to find out more about the specific reasons for fedban, use it /fbanstat <FedID>")
			send_message(update.effective_message, text, parse_mode="markdown")

	elif not msg.reply_to_message and not args:
		user_id = msg.from_user.id
		user_name, fbanlist = sql.get_user_fbanlist(user_id)
		if user_name == "":
			user_name = msg.from_user.first_name
		if len(fbanlist) == 0:
			send_message(update.effective_message, tld(update.effective_message, "{} not yet banned in any federation!").format(user_name))
		else:
			text = tld(update.effective_message, "{} has been banned in this federation:\n").format(user_name)
			for x in fbanlist:
				text += "- `{}`: {}\n".format(x[0], x[1][:20])
			text += tld(update.effective_message, "\nIf you want to find out more about the specific reasons for fedban, use it /fbanstat <FedID>")
			send_message(update.effective_message, text, parse_mode="markdown")

	else:
		fed_id = args[0]
		fedinfo = sql.get_fed_info(fed_id)
		if not fedinfo:
			send_message(update.effective_message, tld(update.effective_message, "Federation {} not found!").format(fed_id))
			return
		name, reason, fbantime = sql.get_user_fban(fed_id, msg.from_user.id)
		if fbantime:
			fbantime = time.strftime("%d/%m/%Y", time.localtime(fbantime))
		else:
			fbantime = "Unavaiable"
		if not name:
			name = msg.from_user.first_name
		if not reason:
			send_message(update.effective_message, tld(update.effective_message, "{} not banned in this federation").format(name))
			return
		send_message(update.effective_message, tld(update.effective_message, "{} banned in this federation because:\n`{}`\n*Banned on:* `{}`").format(name, reason, fbantime), parse_mode="markdown")
Beispiel #10
0
def insults(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    text = random.choice(tld(chat.id, "INSULTS-K"))
    update.effective_message.reply_text(text)
Beispiel #11
0
    #pprint(eval(str(update)))
    #update.effective_message.reply_text("Hola tester! _I_ *have* `markdown`", parse_mode=ParseMode.MARKDOWN)
    update.effective_message.reply_text("This person edited a message")
    print(update.effective_message)


@run_async
def start(bot: Bot, update: Update, args: List[str]):
    LOGGER.info("Start")
    chat = update.effective_chat  # type: Optional[Chat]
    #query = update.callback_query #Unused variable
    if update.effective_chat.type == "private":
        if len(args) >= 1:
            if args[0].lower() == "help":
                send_help(update.effective_chat.id, tld(chat.id, "send-help").format(
                     dispatcher.bot.first_name, "" if not ALLOW_EXCL else tld(
                         chat.id, "\nAll commands can either be used with `/` or `!`.\n"
                             )))

            elif args[0].lower().startswith("stngs_"):
                match = re.match("stngs_(.*)", args[0].lower())
                chat = dispatcher.bot.getChat(match.group(1))

                if is_user_admin(chat, update.effective_user.id):
                    send_settings(match.group(1), update.effective_user.id, update, user=False)
                else:
                    send_settings(match.group(1), update.effective_user.id, update, user=True)

            elif args[0][1:].isdigit() and "rules" in IMPORTED:
                IMPORTED["rules"].send_rules(update, args[0], from_pm=True)

            elif args[0].lower() == "controlpanel":
Beispiel #12
0
def check_flood(bot: Bot, update: Update) -> str:
    user = update.effective_user  # type: Optional[User]
    chat = update.effective_chat  # type: Optional[Chat]
    msg = update.effective_message  # type: Optional[Message]

    if not user:  # ignore channels
        return ""

    # ignore admins
    if is_user_admin(chat, user.id):
        sql.update_flood(chat.id, None)
        return ""

    should_ban = sql.update_flood(chat.id, user.id)
    if not should_ban:
        return ""

    try:
        getmode, getvalue = sql.get_flood_setting(chat.id)
        if getmode == 1:
            chat.kick_member(user.id)
            execstrings = tld(update.effective_message, "Exit!")
            tag = "BANNED"
        elif getmode == 2:
            chat.kick_member(user.id)
            chat.unban_member(user.id)
            execstrings = tld(update.effective_message, "Exit!")
            tag = "KICKED"
        elif getmode == 3:
            bot.restrict_chat_member(chat.id, user.id, can_send_messages=False)
            execstrings = tld(update.effective_message, "Now you are silent!")
            tag = "MUTED"
        elif getmode == 4:
            bantime = extract_time(msg, getvalue)
            chat.kick_member(user.id, until_date=bantime)
            execstrings = tld(update.effective_message,
                              "Out as long {}!").format(getvalue)
            tag = "TBAN"
        elif getmode == 5:
            mutetime = extract_time(msg, getvalue)
            bot.restrict_chat_member(chat.id,
                                     user.id,
                                     until_date=mutetime,
                                     can_send_messages=False)
            execstrings = tld(update.effective_message,
                              "Now you stay silent for {}!").format(getvalue)
            tag = "TMUTE"
        send_message(
            update.effective_message,
            tld(
                update.effective_message,
                "I don't like people who send successive messages. But you made me "
                "dissapointed. {}").format(execstrings))

        return "<b>{}:</b>" \
               "\n#{}" \
               "\n<b>User:</b> {}" \
               "\nFlooded the group.".format(tag, html.escape(chat.title),
                                             mention_html(user.id, user.first_name))

    except BadRequest:
        send_message(
            update.effective_message,
            tld(
                update.effective_message,
                "Does not have kick permission, so automatically disables antiflood."
            ))
        sql.set_flood(chat.id, 0)
        return "<b>{}:</b>" \
               "\n#INFO" \
               "\n{}".format(chat.title, tld(update.effective_message, "Does not have kick permission, so automatically disables antiflood."))
Beispiel #13
0
def set_flood_mode(bot: Bot, update: Update, args: List[str]):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    msg = update.effective_message  # type: Optional[Message]

    conn = connected(bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if update.effective_message.chat.type == "private":
            send_message(
                update.effective_message,
                tld(update.effective_message,
                    "You can do this command in the group, not the PM"))
            return ""
        chat = update.effective_chat
        chat_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title

    if args:
        if args[0].lower() == 'ban':
            settypeflood = tld(update.effective_message, 'block')
            sql.set_flood_strength(chat_id, 1, "0")
        elif args[0].lower() == 'kick':
            settypeflood = tld(update.effective_message, 'kick')
            sql.set_flood_strength(chat_id, 2, "0")
        elif args[0].lower() == 'mute':
            settypeflood = tld(update.effective_message, 'mute')
            sql.set_flood_strength(chat_id, 3, "0")
        elif args[0].lower() == 'tban':
            if len(args) == 1:
                text = tld(
                    update.effective_message,
                    """It looks like you are trying to set a temporary value for anti-flood, but have not determined the time yet; use `/ setfloodmode tban <timevalue> `.

Example time values: 4m = 4 minutes, 3h = 3 hours, 6d = 6 days, 5w = 5 weeks."""
                )
                send_message(update.effective_message,
                             text,
                             parse_mode="markdown")
                return
            settypeflood = tld(update.effective_message,
                               "block while for {}").format(args[1])
            sql.set_flood_strength(chat_id, 4, str(args[1]))
        elif args[0].lower() == 'tmute':
            if len(args) == 1:
                text = tld(
                    update.effective_message,
                    """It looks like you are trying to set a temporary value for anti-flood, but have not determined the time yet; use `/ setfloodmode tmute <timevalue>`.

Example time values: 4m = 4 minutes, 3h = 3 hours, 6d = 6 days, 5w = 5 weeks."""
                )
                send_message(update.effective_message,
                             text,
                             parse_mode="markdown")
                return
            settypeflood = tld(update.effective_message,
                               'block while for {}').format(args[1])
            sql.set_flood_strength(chat_id, 5, str(args[1]))
        else:
            send_message(
                update.effective_message,
                tld(update.effective_message,
                    "I only understand ban/kick/mute/tban/tmute!"))
            return
        if conn:
            text = tld(
                update.effective_message,
                "Sending too many messages now will result in `{}` in * {} *! "
            ).format(settypeflood, chat_name)
        else:
            text = tld(
                update.effective_message,
                "Sending too many messages will now result in `{}`!").format(
                    settypeflood)
        send_message(update.effective_message, text, parse_mode="markdown")
        return "<b>{}:</b>\n" \
                "<b>Admin:</b> {}\n" \
                "Has changed antiflood mode. User will {}.".format(settypeflood, html.escape(chat.title),
                                                                            mention_html(user.id, user.first_name))
    else:
        getmode, getvalue = sql.get_flood_setting(chat.id)
        if getmode == 1:
            settypeflood = tld(update.effective_message, 'block')
        elif getmode == 2:
            settypeflood = tld(update.effective_message, 'kick')
        elif getmode == 3:
            settypeflood = tld(update.effective_message, 'mute')
        elif getmode == 4:
            settypeflood = tld(update.effective_message,
                               'block while for {}').format(getvalue)
        elif getmode == 5:
            settypeflood = tld(update.effective_message,
                               'block while for {}').format(getvalue)
        if conn:
            text = tld(
                update.effective_message,
                "If a member sends successive messages, he will *{}* in *{}*."
            ).format(settypeflood, chat_name)
        else:
            text = tl(
                update.effective_message,
                "If a member sends successive messages, he will be *{}*."
            ).format(settypeflood)
        send_message(update.effective_message,
                     text,
                     parse_mode=ParseMode.MARKDOWN)
    return ""
Beispiel #14
0
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)
Beispiel #15
0
def gban(bot: Bot, update: Update, args: List[str]):
    message = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]
    banner = update.effective_user  # type: Optional[User]
    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text(tld(chat.id, "common_err_no_user"))
        return

    if int(user_id) in SUDO_USERS:
        message.reply_text(tld(chat.id, "antispam_err_usr_sudo"))
        return

    if int(user_id) in SUPPORT_USERS:
        message.reply_text(tld(chat.id, "antispam_err_usr_support"))
        return

    if user_id == bot.id:
        message.reply_text(tld(chat.id, "antispam_err_usr_bot"))
        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, "antispam_err_not_usr"))
        return

    if user_chat.first_name == '':
        message.reply_text(tld(chat.id, "antispam_err_user_deleted"))
        return

    full_reason = f"{reason} // GBanned by {banner.first_name} id {banner.id}"

    if sql.is_user_gbanned(user_id):
        if not reason:
            message.reply_text(tld(chat.id, "antispam_err_no_new_reason"))
            return

        old_reason = sql.update_gban_reason(
            user_id, user_chat.username or user_chat.first_name,
            full_reason) or "None"

        if int(banner.id) in [172811422, 214416808]:
            return

        try:
            bot.send_message(
                MESSAGE_DUMP,
                tld(chat.id, "antispam_logger_update_gban").format(
                    mention_html(banner.id, banner.first_name),
                    mention_html(user_chat.id, user_chat.first_name
                                 or "Deleted Account"), user_chat.id,
                    old_reason, full_reason),
                parse_mode=ParseMode.HTML)
        except:
            pass

        message.reply_text(tld(chat.id, "antispam_reason_updated").format(
            html.escape(old_reason), html.escape(full_reason)),
                           parse_mode=ParseMode.HTML)

        return

    starting = tld(chat.id, "antispam_new_gban").format(
        mention_html(user_chat.id, user_chat.first_name or "Deleted Account"),
        user_chat.id)
    message.reply_text(starting, parse_mode=ParseMode.HTML)

    try:
        bot.send_message(MESSAGE_DUMP,
                         tld(chat.id, "antispam_logger_new_gban").format(
                             mention_html(banner.id, banner.first_name),
                             mention_html(user_chat.id, user_chat.first_name),
                             user_chat.id, full_reason
                             or tld(chat.id, "antispam_no_reason")),
                         parse_mode=ParseMode.HTML)
    except:
        print("nut")

    sql.gban_user(user_id, user_chat.username or user_chat.first_name,
                  full_reason)

    try:
        if int(banner.id) in [172811422, 214416808]:
            return
        chat.kick_member(user_chat.id)
    except:
        print("Meh")
def unblacklist(bot: Bot, update: Update):
    msg = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    words = msg.text.split(None, 1)

    conn = connected(bot, update, chat, user.id)
    if not conn == False:
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        chat_id = update.effective_chat.id
        if chat.type == "private":
            exit(1)
        else:
            chat_name = chat.title

    if len(words) > 1:
        text = words[1]
        to_unblacklist = list(
            set(trigger.strip() for trigger in text.split("\n")
                if trigger.strip()))
        successful = 0
        for trigger in to_unblacklist:
            success = sql.rm_from_blacklist(chat_id, trigger.lower())
            if success:
                successful += 1

        if len(to_unblacklist) == 1:
            if successful:
                msg.reply_text(tld(
                    chat.id,
                    "Removed <code>{}</code> from the blacklist in <b>{}</b>!"
                ).format(html.escape(to_unblacklist[0]), chat_name),
                               parse_mode=ParseMode.HTML)
            else:
                msg.reply_text(
                    tld(chat.id, "This isn't a blacklisted trigger...!"))

        elif successful == len(to_unblacklist):
            msg.reply_text(tld(
                chat.id,
                "Removed <code>{}</code> triggers from the blacklist in <b>{}</b>!"
            ).format(successful, chat_name),
                           parse_mode=ParseMode.HTML)

        elif not successful:
            msg.reply_text(tld(
                chat.id,
                "None of these triggers were exist, so they weren't removed.").
                           format(successful,
                                  len(to_unblacklist) - successful),
                           parse_mode=ParseMode.HTML)

        else:
            msg.reply_text(tld(
                chat.id,
                "Removed <code>{}</code> triggers from the blacklist in <b>{}</b>! {} did not exist, "
                "so were not removed.").format(
                    successful, chat_name,
                    len(to_unblacklist) - successful),
                           parse_mode=ParseMode.HTML)
    else:
        msg.reply_text(
            tld(
                chat.id,
                "Tell me what words you would like to remove from the blacklist."
            ))
Beispiel #17
0
def info(bot: Bot, update: Update, args: List[str]):
    msg = update.effective_message  # type: Optional[Message]
    user_id = extract_user(update.effective_message, args)
    chat = update.effective_chat  # type: Optional[Chat]

    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

    text = tld(chat.id, "<b>User info</b>:")
    text += "\nID: <code>{}</code>".format(user.id)
    text += tld(chat.id,
                "\nFirst Name: {}").format(html.escape(user.first_name))

    if user.last_name:
        text += tld(chat.id,
                    "\nLast Name: {}").format(html.escape(user.last_name))

    if user.username:
        text += tld(chat.id,
                    "\nUsername: @{}").format(html.escape(user.username))

    text += tld(chat.id,
                "\nUser link: {}\n").format(mention_html(user.id, "link"))

    if user.id == OWNER_ID:
        text += tld(
            chat.id,
            "\n\nAy, This guy is my owner. I would never do anything against him!"
        )
    else:
        if user.id in SUDO_USERS:
            text += tld(chat.id, "\nThis person is one of my sudo users! " \
            "Nearly as powerful as my owner - so watch it.")
        else:
            if user.id in SUPPORT_USERS:
                text += tld(chat.id, "\nThis person is one of my support users! " \
                        "Not quite a sudo user, but can still gban you off the map.")

            if user.id in WHITELIST_USERS:
                text += tld(chat.id, "\nThis person has been whitelisted! " \
                        "That means I'm not allowed to ban/kick them.")

    for mod in USER_INFO:
        mod_info = mod.__user_info__(user.id, chat.id).strip()
        if mod_info:
            text += "\n\n" + mod_info

    update.effective_message.reply_text(text, parse_mode=ParseMode.HTML)
Beispiel #18
0
def temp_mute(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]

    conn = connected(bot, update, chat, user.id)
    if not conn == False:
        chatD = dispatcher.bot.getChat(conn)
    else:
        if chat.type == "private":
            exit(1)
        else:
            chatD = chat

    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text(
            tld(chat.id, "You don't seem to be referring to a user."))
        return ""

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text(tld(chat.id, "I can't seem to find this user"))
            return ""
        else:
            raise

    if is_user_admin(chat, user_id, member):
        message.reply_text(
            tld(chat.id,
                "DEMI ALEK LAKO BISA GUA MUTE ADMIN UDAH GUA MUTE..."))
        return ""

    if user_id == bot.id:
        message.reply_text(tld(chat.id, "GILA LU MAU MUTE GUA?"))
        return ""

    if not reason:
        message.reply_text(
            tld(chat.id,
                "You haven't specified a time to mute this user for!"))
        return ""

    split_reason = reason.split(None, 1)

    time_val = split_reason[0].lower()
    if len(split_reason) > 1:
        reason = split_reason[1]
    else:
        reason = ""

    mutetime = extract_time(message, time_val)

    if not mutetime:
        return ""

    log = "<b>{}:</b>" \
          "\n#TEMP MUTED" \
          "\n<b>Admin:</b> {}" \
          "\n<b>User:</b> {}" \
          "\n<b>Time:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name),
                                     mention_html(member.user.id, member.user.first_name), time_val)
    if reason:
        log += "\n<b>Reason:</b> {}".format(reason)

    try:
        if member.can_send_messages is None or member.can_send_messages:
            bot.restrict_chat_member(chat.id,
                                     user_id,
                                     until_date=mutetime,
                                     can_send_messages=False)
            message.reply_text(
                tld(chat.id,
                    "Muted for {} in {}!").format(time_val, chatD.title))
            return log
        else:
            message.reply_text(
                tld(chat.id,
                    "This user is already muted in {}!").format(chatD.title))

    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text(tld(chat.id, "Muted for {} in {}!").format(
                time_val, chatD.title),
                               quote=False)
            return log
        else:
            LOGGER.warning(update)
            LOGGER.exception("ERROR muting user %s in chat %s (%s) due to %s",
                             user_id, chat.title, chat.id, excp.message)
            message.reply_text(
                tld(chat.id, "Well damn, I can't mute that user."))

    return ""
Beispiel #19
0
def __chat_settings__(bot, update, chat, chatP, user):
    chatname = tld(chatP.id, "this chat")
    return build_lock_message(chat, chatP, user, chatname)
Beispiel #20
0
def mute(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]

    conn = connected(bot, update, chat, user.id)
    if not conn == False:
        chatD = dispatcher.bot.getChat(conn)
    else:
        if chat.type == "private":
            exit(1)
        else:
            chatD = chat

    user_id = extract_user(message, args)
    if not user_id:
        message.reply_text(
            tld(
                chat.id,
                "You'll need to either give me a username to mute, or reply to someone to be muted."
            ))
        return ""

    if user_id == bot.id:
        message.reply_text(tld(chat.id, "GAUSA MUTE GUA NGENTOT!"))
        return ""

    member = chatD.get_member(int(user_id))

    if member:

        if user_id in SUDO_USERS:
            message.reply_text(
                tld(
                    chat.id,
                    "No! I'm not muting bot sudoers! That would be a pretty dumb idea."
                ))

        elif is_user_admin(chatD, user_id, member=member):
            message.reply_text(
                tld(chat.id, "Et bego gua mana bisa mute admin ajg!"))

        elif member.can_send_messages is None or member.can_send_messages:
            bot.restrict_chat_member(chatD.id,
                                     user_id,
                                     can_send_messages=False)
            keyboard = []
            reply = tld(chat.id, "{} is muted in {}!").format(
                mention_html(member.user.id, member.user.first_name),
                chatD.title)
            message.reply_text(reply,
                               reply_markup=keyboard,
                               parse_mode=ParseMode.HTML)
            return "<b>{}:</b>" \
                   "\n#MUTE" \
                   "\n<b>Admin:</b> {}" \
                   "\n<b>User:</b> {}".format(html.escape(chatD.title),
                                              mention_html(user.id, user.first_name),
                                              mention_html(member.user.id, member.user.first_name))

        else:
            message.reply_text(
                tld(chat.id, "MAMPUS LU GUA MUTE! {}!").format(chatD.title))
    else:
        message.reply_text(
            tld(chat.id, "This user isn't in the {}!").format(chatD.title))

    return ""
Beispiel #21
0
def help_button(bot: Bot, update: Update):
    query = update.callback_query
    chat = update.effective_chat  # type: Optional[Chat]
    mod_match = re.match(r"help_module\((.+?)\)", query.data)
    prev_match = re.match(r"help_prev\((.+?)\)", query.data)
    next_match = re.match(r"help_next\((.+?)\)", query.data)
    back_match = re.match(r"help_back", query.data)
    try:
        if mod_match:
            module = mod_match.group(1)
            mod_name = tld(chat.id, "modname_" + module).strip()
            help_txt = tld(
                chat.id, module +
                "_help")  # tld_help(chat.id, HELPABLE[module].__mod_name__)

            if not help_txt:
                LOGGER.exception(f"Help string for {module} not found!")

            text = tld(chat.id, "here_is_help").format(mod_name, help_txt)
            query.message.reply_text(text=text,
                                     parse_mode=ParseMode.MARKDOWN,
                                     reply_markup=InlineKeyboardMarkup([[
                                         InlineKeyboardButton(
                                             text=tld(chat.id, "btn_go_back"),
                                             callback_data="help_back")
                                     ]]))

        elif prev_match:
            curr_page = int(prev_match.group(1))
            query.message.reply_text(tld(chat.id, "send-help").format(
                dispatcher.bot.first_name,
                "" if not ALLOW_EXCL else tld(chat.id, "cmd_multitrigger")),
                                     parse_mode=ParseMode.MARKDOWN,
                                     reply_markup=InlineKeyboardMarkup(
                                         paginate_modules(
                                             chat.id, curr_page - 1, HELPABLE,
                                             "help")))

        elif next_match:
            next_page = int(next_match.group(1))
            query.message.reply_text(tld(chat.id, "send-help").format(
                dispatcher.bot.first_name,
                "" if not ALLOW_EXCL else tld(chat.id, "cmd_multitrigger")),
                                     parse_mode=ParseMode.MARKDOWN,
                                     reply_markup=InlineKeyboardMarkup(
                                         paginate_modules(
                                             chat.id, next_page + 1, HELPABLE,
                                             "help")))

        elif back_match:
            query.message.reply_text(text=tld(chat.id, "send-help").format(
                dispatcher.bot.first_name,
                "" if not ALLOW_EXCL else tld(chat.id, "cmd_multitrigger")),
                                     parse_mode=ParseMode.MARKDOWN,
                                     reply_markup=InlineKeyboardMarkup(
                                         paginate_modules(
                                             chat.id, 0, HELPABLE, "help")))

        # ensure no spinny white circle
        bot.answer_callback_query(query.id)
        query.message.delete()
    except BadRequest as excp:
        if excp.message == "Message is not modified":
            pass
        elif excp.message == "Query_id_invalid":
            pass
        elif excp.message == "Message can't be deleted":
            pass
        else:
            LOGGER.exception("Exception in help buttons. %s", str(query.data))
Beispiel #22
0
def nomedia(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]

    conn = connected(bot, update, chat, user.id)
    if not conn == False:
        chatD = dispatcher.bot.getChat(conn)
    else:
        if chat.type == "private":
            exit(1)
        else:
            chatD = chat

    user_id = extract_user(message, args)
    if not user_id:
        message.reply_text(
            tld(
                chat.id,
                "You'll need to either give me a username to restrict, or reply to someone to be restricted."
            ))
        return ""

    if user_id == bot.id:
        message.reply_text(tld(chat.id, "I'm not restricting myself!"))
        return ""

    member = chatD.get_member(int(user_id))

    if member:
        if is_user_admin(chatD, user_id, member=member):
            message.reply_text(tld(chat.id, "Afraid I can't restrict admins!"))

        elif member.can_send_messages is None or member.can_send_messages:
            bot.restrict_chat_member(chatD.id,
                                     user_id,
                                     can_send_messages=True,
                                     can_send_media_messages=False,
                                     can_send_other_messages=False,
                                     can_add_web_page_previews=False)
            keyboard = []
            reply = tld(chat.id,
                        "{} is restricted from sending media in {}!").format(
                            mention_html(member.user.id,
                                         member.user.first_name), chatD.title)
            message.reply_text(reply,
                               reply_markup=keyboard,
                               parse_mode=ParseMode.HTML)
            return "<b>{}:</b>" \
                   "\n#RESTRICTED" \
                   "\n<b>• Admin:</b> {}" \
                   "\n<b>• User:</b> {}" \
                   "\n<b>• ID:</b> <code>{}</code>".format(html.escape(chatD.title),
                                              mention_html(user.id, user.first_name),
                                              mention_html(member.user.id, member.user.first_name), user_id)

        else:
            message.reply_text(
                tld(chat.id, "This user is already restricted in {}!"))
    else:
        message.reply_text(
            tld(chat.id, "This user isn't in the {}!").format(chatD.title))

    return ""
Beispiel #23
0
def get(bot, update, notename, show_none=True, no_format=False):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    conn = connected(bot, update, chat, user.id, need_admin=False)
    if conn:
        chat_id = conn
        send_id = user.id
    else:
        chat_id = update.effective_chat.id
        send_id = chat_id

    note = sql.get_note(chat_id, notename)
    message = update.effective_message  # type: Optional[Message]

    if note:
        pass
    elif notename[0] == "#":
        hashnote = sql.get_note(chat_id, notename[1:])
        if hashnote:
            note = hashnote
    elif show_none:
        message.reply_text(tld(chat.id, "note_not_existed"))
        return

    # If we're replying to a message, reply to that message (unless it's an error)
    if message.reply_to_message:
        reply_id = message.reply_to_message.message_id
    else:
        reply_id = message.message_id

    if note.is_reply:
        if MESSAGE_DUMP:
            try:
                bot.forward_message(chat_id=chat_id,
                                    from_chat_id=MESSAGE_DUMP,
                                    message_id=note.value)
            except BadRequest as excp:
                if excp.message == "Message to forward not found":
                    message.reply_text(tld(chat.id, "note_lost"))
                    sql.rm_note(chat_id, notename)
                else:
                    raise
        else:
            try:
                bot.forward_message(chat_id=chat_id,
                                    from_chat_id=chat_id,
                                    message_id=note.value)

            except BadRequest as excp:
                if excp.message == "Message to forward not found":
                    message.reply_text(tld(chat.id, "note_msg_del"))
                sql.rm_note(chat_id, notename)

            else:
                raise
    else:
        text = note.value
        keyb = []
        parseMode = ParseMode.MARKDOWN
        buttons = sql.get_buttons(chat_id, notename)
        if no_format:
            parseMode = None
            text += revert_buttons(buttons)
        else:
            keyb = build_keyboard(buttons)

        keyboard = InlineKeyboardMarkup(keyb)

        try:
            if note.msgtype in (sql.Types.BUTTON_TEXT, sql.Types.TEXT):
                try:
                    bot.send_message(send_id,
                                     text,
                                     reply_to_message_id=reply_id,
                                     parse_mode=parseMode,
                                     disable_web_page_preview=True,
                                     reply_markup=keyboard)
                except BadRequest as excp:
                    if excp.message == "Wrong http url":
                        failtext = tld(chat.id, "note_url_invalid")
                        failtext += "\n\n```\n{}```".format(
                            note.value + revert_buttons(buttons))
                        message.reply_text(failtext, parse_mode="markdown")
                    pass
            else:
                ENUM_FUNC_MAP[note.msgtype](send_id,
                                            note.file,
                                            caption=text,
                                            reply_to_message_id=reply_id,
                                            parse_mode=parseMode,
                                            disable_web_page_preview=True,
                                            reply_markup=keyboard)

        except BadRequest as excp:
            if excp.message == "Entity_mention_user_invalid":
                message.reply_text(tld(chat.id, "note_mention_invalid"))

            elif FILE_MATCHER.match(note.value):
                message.reply_text(tld(chat.id, "note_incorrect_import"))
                sql.rm_note(chat_id, notename)
            else:
                message.reply_text(tld(chat.id, "note_cannot_send"))
                LOGGER.exception("Could not parse message #%s in chat %s",
                                 notename, str(chat_id))
                LOGGER.warning("Message was: %s", str(note.value))

    return
Beispiel #24
0
def temp_nomedia(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]

    conn = connected(bot, update, chat, user.id)
    if not conn == False:
        chatD = dispatcher.bot.getChat(conn)
    else:
        if chat.type == "private":
            exit(1)
        else:
            chatD = chat

    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text(
            tld(chat.id, "You don't seem to be referring to a user."))
        return ""

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text(tld(chat.id, "I can't seem to find this user"))
            return ""
        else:
            raise

    if is_user_admin(chat, user_id, member):
        message.reply_text(
            tld(chat.id, "I really wish I could restrict admins..."))
        return ""

    if user_id == bot.id:
        message.reply_text(
            tld(chat.id, "I'm not gonna RESTRICT myself, are you crazy?"))
        return ""

    if not reason:
        message.reply_text(
            tld(chat.id,
                "You haven't specified a time to restrict this user for!"))
        return ""

    split_reason = reason.split(None, 1)

    time_val = split_reason[0].lower()
    if len(split_reason) > 1:
        reason = split_reason[1]
    else:
        reason = ""

    mutetime = extract_time(message, time_val)

    if not mutetime:
        return ""

    log = "<b>{}:</b>" \
          "\n#TEMP RESTRICTED" \
          "\n<b>• Admin:</b> {}" \
          "\n<b>• User:</b> {}" \
          "\n<b>• ID:</b> <code>{}</code>" \
          "\n<b>• Time:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name),
                                       mention_html(member.user.id, member.user.first_name), user_id, time_val)
    if reason:
        log += "\n<b>• Reason:</b> {}".format(reason)

    try:
        if member.can_send_messages is None or member.can_send_messages:
            bot.restrict_chat_member(chat.id,
                                     user_id,
                                     until_date=mutetime,
                                     can_send_messages=True,
                                     can_send_media_messages=False,
                                     can_send_other_messages=False,
                                     can_add_web_page_previews=False)
            message.reply_text(
                tld(chat.id,
                    "Restricted from sending media for {} in {}!").format(
                        time_val, chatD.title))
            return log
        else:
            message.reply_text(
                tld(chat.id, "This user is already restricted in {}.").format(
                    chatD.title))

    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text(tld(chat.id, "Restricted for {} in {}!").format(
                time_val, chatD.title),
                               quote=False)
            return log
        else:
            LOGGER.warning(update)
            LOGGER.exception("ERROR muting user %s in chat %s (%s) due to %s",
                             user_id, chat.title, chat.id, excp.message)
            message.reply_text(
                tld(chat.id, "Well damn, I can't restrict that user."))

    return ""
Beispiel #25
0
def demote(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat  # type: Optional[Chat]
    message = update.effective_message  # type: Optional[Message]
    user = update.effective_user  # type: Optional[User]
    conn = connected(bot, update, chat, user.id)
    if not conn == False:
        chatD = dispatcher.bot.getChat(conn)
    else:
        chatD = update.effective_chat
        if chat.type == "private":
            exit(1)

    if not chatD.get_member(bot.id).can_promote_members:
        update.effective_message.reply_text(
            "I can't promote/demote people here! "
            "Make sure I'm admin and can appoint new admins.")
        exit(1)

    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_member = chatD.get_member(user_id)
    if user_member.status == 'creator':
        message.reply_text(
            tld(chat.id,
                "This person CREATED the chat, how would I demote them?"))
        return ""

    if not user_member.status == 'administrator':
        message.reply_text(tld(chat.id, "Can't demote what wasn't promoted!"))
        return ""

    if user_id == bot.id:
        message.reply_text(tld(chat.id, "I can't demote myself!"))
        return ""

    try:
        bot.promoteChatMember(int(chatD.id),
                              int(user_id),
                              can_change_info=False,
                              can_post_messages=False,
                              can_edit_messages=False,
                              can_delete_messages=False,
                              can_invite_users=False,
                              can_restrict_members=False,
                              can_pin_messages=False,
                              can_promote_members=False)
        message.reply_text(tld(chat.id,
                               f"Successfully demoted in *{chatD.title}*!"),
                           parse_mode=ParseMode.MARKDOWN)
        return f"<b>{html.escape(chatD.title)}:</b>" \
                "\n#DEMOTED" \
               f"\n<b>Admin:</b> {mention_html(user.id, user.first_name)}" \
               f"\n<b>User:</b> {mention_html(user_member.user.id, user_member.user.first_name)}"

    except BadRequest:
        message.reply_text(
            tld(
                chat.id,
                "Could not demote. I might not be admin, or the admin status was appointed by another user, so I can't act upon them!"
            ))
        return ""
Beispiel #26
0
def unmute(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]

    conn = connected(bot, update, chat, user.id)
    if not conn == False:
        chatD = dispatcher.bot.getChat(conn)
    else:
        if chat.type == "private":
            exit(1)
        else:
            chatD = chat

    user_id = extract_user(message, args)
    if not user_id:
        message.reply_text(
            tld(
                chat.id,
                "You'll need to either give me a username to unmute, or reply to someone to be unmuted."
            ))
        return ""

    member = chatD.get_member(int(user_id))

    if member.status != 'kicked' and member.status != 'left':
        if member.can_send_messages and member.can_send_media_messages \
                and member.can_send_other_messages and member.can_add_web_page_previews:
            message.reply_text(
                tld(chat.id,
                    "NAH SEKARANG COBA NGOMONG {}.").format(chatD.title))
        else:
            bot.restrict_chat_member(chatD.id,
                                     int(user_id),
                                     can_send_messages=True,
                                     can_send_media_messages=True,
                                     can_send_other_messages=True,
                                     can_add_web_page_previews=True)
            keyboard = []
            reply = tld(chat.id,
                        "Yep, {} can start talking again in {}!").format(
                            mention_html(member.user.id,
                                         member.user.first_name), chatD.title)
            message.reply_text(reply,
                               reply_markup=keyboard,
                               parse_mode=ParseMode.HTML)
            return "<b>{}:</b>" \
                   "\n#UNMUTE" \
                   "\n<b>• Admin:</b> {}" \
                   "\n<b>• User:</b> {}" \
                   "\n<b>• ID:</b> <code>{}</code>".format(html.escape(chatD.title),
                                                           mention_html(user.id, user.first_name),
                                                           mention_html(member.user.id, member.user.first_name), user_id)
    else:
        message.reply_text(
            tld(
                chat.id,
                "This user isn't even in the chat, unmuting them won't make them talk more than they "
                "already do!"))

    return ""
Beispiel #27
0
def settings_button(bot: Bot, update: Update):
    query = update.callback_query
    user = update.effective_user
    chatP = update.effective_chat  # type: Optional[Chat]
    mod_match = re.match(r"stngs_module\((.+?),(.+?)\)", query.data)
    prev_match = re.match(r"stngs_prev\((.+?),(.+?)\)", query.data)
    next_match = re.match(r"stngs_next\((.+?),(.+?)\)", query.data)
    back_match = re.match(r"stngs_back\((.+?)\)", query.data)
    try:
        if mod_match:
            chat_id = mod_match.group(1)
            module = mod_match.group(2)
            chat = bot.get_chat(chat_id)
            text = "*{}* has the following settings for the *{}* module:\n\n".format(escape_markdown(chat.title),
                                                                                     CHAT_SETTINGS[
                                                                                         module].__mod_name__) + \
                   CHAT_SETTINGS[module].__chat_settings__(bot, update, chat, chatP, user)
            query.message.reply_text(
                text=text,
                parse_mode=ParseMode.MARKDOWN,
                reply_markup=InlineKeyboardMarkup([[
                    InlineKeyboardButton(
                        text="Back",
                        callback_data="stngs_back({})".format(chat_id))
                ]]))

        elif prev_match:
            chat_id = prev_match.group(1)
            curr_page = int(prev_match.group(2))
            chat = bot.get_chat(chat_id)
            query.message.reply_text(tld(
                user.id, "send-group-settings").format(chat.title),
                                     reply_markup=InlineKeyboardMarkup(
                                         paginate_modules(curr_page - 1,
                                                          0,
                                                          CHAT_SETTINGS,
                                                          "stngs",
                                                          chat=chat_id)))

        elif next_match:
            chat_id = next_match.group(1)
            next_page = int(next_match.group(2))
            chat = bot.get_chat(chat_id)
            query.message.reply_text(tld(
                user.id, "send-group-settings").format(chat.title),
                                     reply_markup=InlineKeyboardMarkup(
                                         paginate_modules(next_page + 1,
                                                          0,
                                                          CHAT_SETTINGS,
                                                          "stngs",
                                                          chat=chat_id)))

        elif back_match:
            chat_id = back_match.group(1)
            chat = bot.get_chat(chat_id)
            query.message.reply_text(text=tld(user.id,
                                              "send-group-settings").format(
                                                  escape_markdown(chat.title)),
                                     parse_mode=ParseMode.MARKDOWN,
                                     reply_markup=InlineKeyboardMarkup(
                                         paginate_modules(user.id,
                                                          0,
                                                          CHAT_SETTINGS,
                                                          "stngs",
                                                          chat=chat_id)))

        # ensure no spinny white circle
        bot.answer_callback_query(query.id)
        query.message.delete()
    except BadRequest as excp:
        if excp.message == "Message is not modified":
            pass
        elif excp.message == "Query_id_invalid":
            pass
        elif excp.message == "Message can't be deleted":
            pass
        else:
            LOGGER.exception("Exception in settings buttons. %s",
                             str(query.data))
Beispiel #28
0
def ungban(bot: Bot, update: Update, args: List[str]):
    message = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]

    user_id = extract_user(message, args)
    if not user_id:
        message.reply_text(tld(chat.id, "common_err_no_user"))
        return

    user_chat = bot.get_chat(user_id)
    if user_chat.type != 'private':
        message.reply_text(tld(chat.id, "antispam_err_not_usr"))
        return

    if not sql.is_user_gbanned(user_id):
        message.reply_text(tld(chat.id, "antispam_user_not_gbanned"))
        return

    banner = update.effective_user  # type: Optional[User]

    message.reply_text("I'll give {} a second chance, globally.".format(
        user_chat.first_name))

    try:
        bot.send_message(MESSAGE_DUMP,
                         tld(chat.id, "antispam_logger_ungban").format(
                             mention_html(banner.id, banner.first_name),
                             mention_html(user_chat.id, user_chat.first_name)),
                         parse_mode=ParseMode.HTML)
    except:
        pass

    chats = get_all_chats()
    for chat in chats:
        chat_id = chat.chat_id

        # Check if this group has disabled gbans
        if not sql.does_chat_gban(chat_id):
            continue

        try:
            member = bot.get_chat_member(chat_id, user_id)
            if member.status == 'kicked':
                bot.unban_chat_member(chat_id, user_id)

        except BadRequest as excp:
            if excp.message in UNGBAN_ERRORS:
                pass
            else:
                message.reply_text(
                    tld(chat.id, "antispam_err_ungban").format(excp.message))
                bot.send_message(
                    OWNER_ID,
                    tld(chat.id, "antispam_err_ungban").format(excp.message))
                return
        except TelegramError:
            pass

    sql.ungban_user(user_id)

    bot.send_message(MESSAGE_DUMP, tld(chat.id, "antispam_ungban_success"))

    message.reply_text(tld(chat.id, "antispam_ungban_success"))
Beispiel #29
0
def help_button(bot: Bot, update: Update):
    query = update.callback_query
    chat = update.effective_chat  # type: Optional[Chat]
    mod_match = re.match(r"help_module\((.+?)\)", query.data)
    prev_match = re.match(r"help_prev\((.+?)\)", query.data)
    next_match = re.match(r"help_next\((.+?)\)", query.data)
    back_match = re.match(r"help_back", query.data)
    try:
        if mod_match:
            module = mod_match.group(1)
            mod_name = tld(chat.id, HELPABLE[module].__mod_name__)
            help_txt = tld_help(chat.id, HELPABLE[module].__mod_name__)

            if help_txt == False:
                help_txt = HELPABLE[module].__help__

            text = tld(chat.id,
                       "Here is the help for the *{}* module:\n{}").format(
                           mod_name, help_txt)
            query.message.reply_text(text=text,
                                     parse_mode=ParseMode.MARKDOWN,
                                     reply_markup=InlineKeyboardMarkup([[
                                         InlineKeyboardButton(
                                             text=tld(chat.id, "Back"),
                                             callback_data="help_back")
                                     ]]))

        elif prev_match:
            curr_page = int(prev_match.group(1))
            query.message.reply_text(tld(chat.id, "send-help").format(
                dispatcher.bot.first_name, "" if not ALLOW_EXCL else tld(
                    chat.id,
                    "\nAll commands can either be used with `/` or `!`.\n")),
                                     parse_mode=ParseMode.MARKDOWN,
                                     reply_markup=InlineKeyboardMarkup(
                                         paginate_modules(
                                             chat.id, curr_page - 1, HELPABLE,
                                             "help")))

        elif next_match:
            next_page = int(next_match.group(1))
            query.message.reply_text(tld(chat.id, "send-help").format(
                dispatcher.bot.first_name, "" if not ALLOW_EXCL else tld(
                    chat.id,
                    "\nAll commands can either be used with `/` or `!`.\n")),
                                     parse_mode=ParseMode.MARKDOWN,
                                     reply_markup=InlineKeyboardMarkup(
                                         paginate_modules(
                                             chat.id, next_page + 1, HELPABLE,
                                             "help")))

        elif back_match:
            query.message.reply_text(text=tld(chat.id, "send-help").format(
                dispatcher.bot.first_name, "" if not ALLOW_EXCL else tld(
                    chat.id,
                    "\nAll commands can either be used with `/` or `!`.\n")),
                                     parse_mode=ParseMode.MARKDOWN,
                                     reply_markup=InlineKeyboardMarkup(
                                         paginate_modules(
                                             chat.id, 0, HELPABLE, "help")))

        # ensure no spinny white circle
        bot.answer_callback_query(query.id)
        query.message.delete()
    except BadRequest as excp:
        if excp.message == "Message is not modified":
            pass
        elif excp.message == "Query_id_invalid":
            pass
        elif excp.message == "Message can't be deleted":
            pass
        else:
            LOGGER.exception("Exception in help buttons. %s", str(query.data))
Beispiel #30
0
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!"))