Exemplo n.º 1
0
    def disable(bot: Bot, update: Update, args: List[str]):
        chat = update.effective_chat  # type: Optional[Chat]
        user = update.effective_user  # type: Optional[User]

        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 = update.effective_chat

        if len(args) >= 1:
            disable_cmd = args[0]
            if disable_cmd.startswith(CMD_STARTERS):
                disable_cmd = disable_cmd[1:]

            if disable_cmd in set(DISABLE_CMDS + DISABLE_OTHER):
                sql.disable_command(chatD.id, disable_cmd)
                update.effective_message.reply_text(
                    tld(chat.id, "Disabled the use of `{}` in *{}*").format(
                        disable_cmd, chatD.title),
                    parse_mode=ParseMode.MARKDOWN)
            else:
                update.effective_message.reply_text(
                    tld(chat.id, "That command can't be disabled"))

        else:
            update.effective_message.reply_text(
                tld(chat.id, "What should I disable?"))
Exemplo n.º 2
0
    def enable(bot: Bot, update: Update, args: List[str]):
        chat = update.effective_chat  # type: Optional[Chat]
        user = update.effective_user  # type: Optional[User]

        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 = update.effective_chat

        if len(args) >= 1:
            enable_cmd = args[0]
            if enable_cmd.startswith(CMD_STARTERS):
                enable_cmd = enable_cmd[1:]

            if sql.enable_command(chatD.id, enable_cmd):
                update.effective_message.reply_text(
                    tld(chat.id, "Enabled the use of `{}` in *{}*").format(
                        enable_cmd, chatD.title),
                    parse_mode=ParseMode.MARKDOWN)
            else:
                update.effective_message.reply_text(
                    tld(chat.id, "Is that even disabled?"))

        else:
            update.effective_message.reply_text(
                tld(chat.id, "What should I enable?"))
Exemplo n.º 3
0
    def commands(bot: Bot, update: Update):
        chat = update.effective_chat
        user = update.effective_user  # type: Optional[User]

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

        disabled = sql.get_all_disabled(chatD.id)
        if not disabled:
            update.effective_message.reply_text(
                tld(chat.id,
                    "No commands are disabled! in *{}*!").format(chatD.title))

        text = build_curr_disabled(chatD.id, chat.id)

        update.effective_message.reply_text(tld(
            chat.id,
            "The following commands are currently restricted in *{}*:\n{}").
                                            format(chatD.title, text),
                                            parse_mode=ParseMode.MARKDOWN)
Exemplo n.º 4
0
def fed_admin(bot: Bot, update: Update, args: List[str]):

    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    fed_id = sql.get_fed_id(chat.id)

    if not fed_id:
        update.effective_message.reply_text(
            tld(chat.id, "This group not in any federation!"))
        return

    if is_user_fed_admin(fed_id, user.id) == False:
        update.effective_message.reply_text(
            tld(chat.id, "Only fed admins can do this!"))
        return

    print(fed_id)
    user = update.effective_user  # type: Optional[Chat]
    chat = update.effective_chat  # type: Optional[Chat]
    info = sql.get_fed_info(fed_id)

    text = "\n\n<b>Federation Admins:</b>"
    user = bot.get_chat(info.owner_id)
    text += "\n• {} - <code>{}</code> (Creator)".format(
        mention_html(user.id, user.first_name), user.id)

    h = sql.all_fed_users(fed_id)
    for O in h:
        user = bot.get_chat(O)
        text += "\n• {} - <code>{}</code>".format(
            mention_html(user.id, user.first_name), user.id, O)

    update.effective_message.reply_text(text, parse_mode=ParseMode.HTML)
Exemplo n.º 5
0
def set_frules(bot: Bot, update: Update, args: List[str]):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    fed_id = sql.get_fed_id(chat.id)

    if is_user_fed_admin(fed_id, user.id) == False:
        update.effective_message.reply_text(
            tld(chat.id, "Only fed admins can do this!"))
        return

    if len(args) >= 1:
        msg = update.effective_message  # type: Optional[Message]
        raw_text = msg.text
        args = raw_text.split(
            None, 1)  # use python's maxsplit to separate cmd and args
        if len(args) == 2:
            txt = args[1]
            offset = len(txt) - len(
                raw_text)  # set correct offset relative to command
            markdown_rules = markdown_parser(txt,
                                             entities=msg.parse_entities(),
                                             offset=offset)
        sql.set_frules(fed_id, markdown_rules)
        update.effective_message.reply_text(
            tld(chat.id, "Rules setuped for this fed!"))
    else:
        update.effective_message.reply_text(tld(chat.id,
                                                "Please write rules!"))
Exemplo n.º 6
0
def adminlist(bot, update):
    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 not conn == False:
        chatP = dispatcher.bot.getChat(conn)
    else:
        chatP = update.effective_chat
        if chat.type == "private":
            exit(1)

    administrators = chatP.get_administrators()

    text = tld(chat.id, "Admins in") + " *{}*:".format(
        chatP.title or tld(chat.id, "this chat"))
    for admin in administrators:
        user = admin.user
        status = admin.status
        if status == "creator":
            name = user.first_name + (user.last_name or "") + tld(
                chat.id, " (Creator)")
        else:
            name = user.first_name + (user.last_name or "")
        text += "\n• {}".format(name)

    update.effective_message.reply_text(text, parse_mode=ParseMode.MARKDOWN)
Exemplo n.º 7
0
def invite(bot: Bot, update: Update):
    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 not conn == False:
        chatP = dispatcher.bot.getChat(conn)
    else:
        chatP = update.effective_chat
        if chat.type == "private":
            exit(1)

    if chatP.username:
        update.effective_message.reply_text(chatP.username)
    elif chatP.type == chatP.SUPERGROUP or chatP.type == chatP.CHANNEL:
        bot_member = chatP.get_member(bot.id)
        if bot_member.can_invite_users:
            invitelink = chatP.invite_link
            #print(invitelink)
            if not invitelink:
                invitelink = bot.exportChatInviteLink(chatP.id)

            update.effective_message.reply_text(invitelink)
        else:
            update.effective_message.reply_text(
                tld(
                    chat.id,
                    "I don't have access to the invite link, try changing my permissions!"
                ))
    else:
        update.effective_message.reply_text(
            tld(
                chat.id,
                "I can only give you invite links for supergroups and channels, sorry!"
            ))
Exemplo n.º 8
0
def leave_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)

    administrators = chat.get_administrators()

    if user.id in SUDO_USERS:
        pass
    else:
        for admin in administrators:
            status = admin.status
            if status == "creator":
                print(admin)
                if str(admin.user.id) == str(user.id):
                    pass
                else:
                    update.effective_message.reply_text(
                        tld(chat.id, "Only group creator can do it!"))
                    return

    if sql.chat_leave_fed(chat.id) == True:
        update.effective_message.reply_text(tld(chat.id, "Leaved from fed!"))
    else:
        update.effective_message.reply_text(
            tld(chat.id,
                "Why you are leaving feds when you have not join any!"))
Exemplo n.º 9
0
def join_fed(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
    administrators = chat.get_administrators()
    fed_id = sql.get_fed_id(chat.id)

    if user.id in SUDO_USERS:
        pass
    else:
        for admin in administrators:
            status = admin.status
            if status == "creator":
                print(admin)
                if str(admin.user.id) == str(user.id):
                    pass
                else:
                    update.effective_message.reply_text(
                        tld(chat.id, "Only group creator can do it!"))
                    return
    if fed_id:
        message.reply_text(
            tld(chat.id,
                "Uh, Are you gonna join two federations at one chat?"))
        return

    if len(args) >= 1:
        sql.chat_join_fed(args[0], chat.id)
        message.reply_text(tld(chat.id, "Chat joined to federation!"))
Exemplo n.º 10
0
    def setlog(bot: Bot, update: Update):
        message = update.effective_message  # type: Optional[Message]
        chat = update.effective_chat  # type: Optional[Chat]
        if chat.type == chat.CHANNEL:
            message.reply_text(tld(chat.id, "Now, forward the /setlog to the group you want to tie this channel to!"))

        elif message.forward_from_chat:
            sql.set_chat_log_channel(chat.id, message.forward_from_chat.id)
            try:
                message.delete()
            except BadRequest as excp:
                if excp.message == "Message to delete not found":
                    pass
                else:
                    LOGGER.exception("Error deleting message in log channel. Should work anyway though.")

            try:
                bot.send_message(message.forward_from_chat.id, tld(chat.id, 
                                 "This channel has been set as the log channel for {}.").format(
                                     chat.title or chat.first_name))
            except Unauthorized as excp:
                if excp.message == "Forbidden: bot is not a member of the channel chat":
                    bot.send_message(chat.id, tld(chat.id, "Successfully set log channel!"))
                else:
                    LOGGER.exception("ERROR in setting the log channel.")

            bot.send_message(chat.id, tld(chat.id, "Successfully set log channel!"))

        else:
            message.reply_text(tld(chat.id, "*The steps to set a log channel are:*\n"
                               " • add bot to the desired channel\n"
                               " • send /setlog to the channel\n"
                               " • forward the /setlog to the group\n"), ParseMode.MARKDOWN)
Exemplo n.º 11
0
def __user_info__(user_id, chat_id):
    if user_id == dispatcher.bot.id:
        return tld(
            chat_id,
            "I've seen them in... Wow. Are they stalking me? They're in all the same places I am... oh. It's me."
        )
    num_chats = sql.get_user_num_chats(user_id)
    return tld(
        chat_id,
        "I've seen them in <code>{}</code> chats in total.").format(num_chats)
Exemplo n.º 12
0
    def unsetlog(bot: Bot, update: Update):
        message = update.effective_message  # type: Optional[Message]
        chat = update.effective_chat  # type: Optional[Chat]

        log_channel = sql.stop_chat_logging(chat.id)
        if log_channel:
            bot.send_message(log_channel, tld(chat.id, "Channel has been unlinked from {}").format(chat.title))
            message.reply_text(tld(chat.id, "Log channel has been un-set."))

        else:
            message.reply_text(tld(chat.id, "No log channel has been set yet!"))
Exemplo n.º 13
0
def flood(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]

    limit = sql.get_flood_limit(chat.id)
    if limit == 0:
        update.effective_message.reply_text(
            tld(chat.id, "I'm not currently enforcing flood control!"))
    else:
        update.effective_message.reply_text(
            tld(
                chat.id,
                "I'm currently muting users if they send more than {} consecutive messages."
            ).format(limit))
Exemplo n.º 14
0
 def list_cmds(bot: Bot, update: Update):
     chat = update.effective_chat  # type: Optional[Chat]
     if DISABLE_CMDS + DISABLE_OTHER:
         result = ""
         for cmd in set(DISABLE_CMDS + DISABLE_OTHER):
             result += " • `{}`\n".format(escape_markdown(cmd))
         update.effective_message.reply_text(tld(
             chat.id,
             "The following commands are toggleable:\n{}").format(result),
                                             parse_mode=ParseMode.MARKDOWN)
     else:
         update.effective_message.reply_text(
             tld(chat.id, "No commands can be disabled."))
Exemplo n.º 15
0
def set_flood(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]

    if len(args) >= 1:
        val = args[0].lower()
        if val == "off" or val == "no" or val == "0":
            sql.set_flood(chat.id, 0)
            message.reply_text(tld(chat.id, "Antiflood has been disabled."))

        elif val.isdigit():
            amount = int(val)
            if amount <= 0:
                sql.set_flood(chat.id, 0)
                message.reply_text(tld(chat.id,
                                       "Antiflood has been disabled."))
                return "<b>{}:</b>" \
                       "\n#SETFLOOD" \
                       "\n<b>Admin:</b> {}" \
                       "\nDisabled antiflood.".format(html.escape(chat.title), mention_html(user.id, user.first_name))

            elif amount < 3:
                message.reply_text(
                    tld(
                        chat.id,
                        "Antiflood has to be either 0 (disabled), or a number bigger than 3 (enabled)!"
                    ))
                return ""

            else:
                sql.set_flood(chat.id, amount)
                message.reply_text(
                    tld(chat.id,
                        "Antiflood has been updated and set to {}").format(
                            amount))
                return "<b>{}:</b>" \
                       "\n#SETFLOOD" \
                       "\n<b>Admin:</b> {}" \
                       "\nSet antiflood to <code>{}</code>.".format(html.escape(chat.title),
                                                                    mention_html(user.id, user.first_name), amount)

        else:
            message.reply_text(
                tld(
                    chat.id,
                    "Unrecognised argument - please use a number, 'off', or 'no'."
                ))

    return ""
Exemplo n.º 16
0
def new_fed(bot: Bot, update: Update, args: List[str]):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    if len(args) >= 1:
        fed_id = str(uuid.uuid4())
        fed_name = args[0]

        #if sql.search_fed_by_name(fed_name):
        #    update.effective_message.reply_text(tld(chat.id, "There is existing federation with this name, change name!"))
        #    return

        print(fed_id)
        sql.new_fed(user.id, fed_name, fed_id)
        update.effective_message.reply_text("*You have successfully created a new federation!*"\
                        "\nName: `{}`"\
                        "\nID: `{}`"
                        "\n\nUse the below command to join the federation:"
                        "\n`/joinfed {}`".format(fed_name, fed_id, fed_id), parse_mode=ParseMode.MARKDOWN)
        bot.send_message(
            MESSAGE_DUMP,
            "Federation <b>{}</b> have been created with ID: <pre>{}</pre>".
            format(fed_name, fed_id),
            parse_mode=ParseMode.HTML)
    else:
        update.effective_message.reply_text(
            tld(chat.id, "Please write federation name!"))
Exemplo n.º 17
0
def locale(bot, update, args):
    chat = update.effective_chat
    if len(args) > 0:
        locale = args[0].lower()
        if locale in list_locales:
            if locale in ('en', 'ru', 'ua', 'es', 'tr', 'id', 'it'):
                switch_to_locale(chat.id, locale)
                update.message.reply_text(
                    tld(chat.id, 'Switched to {} successfully!').format(
                        list_locales[locale]))
            else:
                update.message.reply_text("{} not supported yet!".format(
                    list_locales[locale]))
        else:
            update.message.reply_text(
                "Is that even a valid language code? Use an internationally accepted ISO code!"
            )
    else:
        LANGUAGE = prev_locale(chat.id)
        if LANGUAGE:
            locale = LANGUAGE.locale_name
            native_lang = list_locales[locale]
            update.message.reply_text(
                "Current locale for this chat is: *{}*".format(native_lang),
                parse_mode=ParseMode.MARKDOWN)
        else:
            update.message.reply_text(
                "Current locale for this chat is: *English*",
                parse_mode=ParseMode.MARKDOWN)
Exemplo n.º 18
0
def allow_connections(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat  # type: Optional[Chat]
    if chat.type != chat.PRIVATE:
        if len(args) >= 1:
            var = args[0]
            print(var)
            if (var == "no"):
                sql.set_allow_connect_to_chat(chat.id, False)
                update.effective_message.reply_text(tld(chat.id, "Disabled connections to this chat for users"))
            elif(var == "yes"):
                sql.set_allow_connect_to_chat(chat.id, True)
                update.effective_message.reply_text(tld(chat.id, "Enabled connections to this chat for users"))
            else:
                update.effective_message.reply_text(tld(chat.id, "Please enter on/yes/off/no in group!"))
        else:
            update.effective_message.reply_text(tld(chat.id, "Please enter on/yes/off/no in group!"))
    else:
        update.effective_message.reply_text(tld(chat.id, "Please enter on/yes/off/no in group!"))
Exemplo n.º 19
0
def get_frules(bot: Bot, update: Update, args: List[str]):
    chat = update.effective_chat  # type: Optional[Chat]
    fed_id = sql.get_fed_id(chat.id)
    rules = sql.get_frules(fed_id).rules
    print(rules)
    text = "*Rules in this fed:*\n"
    text += rules
    update.effective_message.reply_text(tld(chat.id, text),
                                        parse_mode=ParseMode.MARKDOWN)
Exemplo n.º 20
0
def paginate_modules(chat_id,
                     page_n: int,
                     module_dict: Dict,
                     prefix,
                     chat=None) -> List:
    if not chat:
        modules = sorted([
            EqInlineKeyboardButton(tld(chat_id, x.__mod_name__),
                                   callback_data="{}_module({})".format(
                                       prefix, x.__mod_name__.lower()))
            for x in module_dict.values()
        ])
    else:
        modules = sorted([
            EqInlineKeyboardButton(tld(chat_id, x.__mod_name__),
                                   callback_data="{}_module({},{})".format(
                                       prefix, chat, x.__mod_name__.lower()))
            for x in module_dict.values()
        ])

    pairs = list(zip(modules[::2], modules[1::2]))

    if len(modules) % 2 == 1:
        pairs.append((modules[-1], ))

    max_num_pages = ceil(len(pairs) / 7)
    modulo_page = page_n % max_num_pages

    # can only have a certain amount of buttons side by side
    if len(pairs) > 7:
        pairs = pairs[modulo_page * 7:7 * (modulo_page + 1)] + [
            (EqInlineKeyboardButton(
                "<<", callback_data="{}_prev({})".format(prefix, modulo_page)),
             EqInlineKeyboardButton("⬅️ Back", callback_data="bot_start"),
             EqInlineKeyboardButton(">>",
                                    callback_data="{}_next({})".format(
                                        prefix, modulo_page)))
        ]
    else:
        pairs += [[
            EqInlineKeyboardButton("⬅️ Back", callback_data="bot_start")
        ]]

    return pairs
Exemplo n.º 21
0
def fed_info(bot: Bot, update: Update, args: List[str]):

    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    fed_id = sql.get_fed_id(chat.id)
    info = sql.get_fed_info(fed_id)

    if not fed_id:
        update.effective_message.reply_text(
            tld(chat.id, "This group not in any federation!"))
        return

    if is_user_fed_admin(fed_id, user.id) == False:
        update.effective_message.reply_text(
            tld(chat.id, "Only fed admins can do this!"))
        return

    OW = bot.get_chat(info.owner_id)
    HAHA = OW.id
    FEDADMIN = sql.all_fed_users(fed_id)
    FEDADMIN.append(int(HAHA))
    ACTUALADMIN = len(FEDADMIN)

    print(fed_id)
    user = update.effective_user  # type: Optional[Chat]
    chat = update.effective_chat  # type: Optional[Chat]
    info = sql.get_fed_info(fed_id)

    text = "<b>Fed info:</b>"
    text += "\nFedID: <code>{}</code>".format(fed_id)
    text += "\nName: {}".format(info.fed_name)
    text += "\nCreator: {}".format(mention_html(HAHA, "this guy"))
    text += "\nNumber of admins: <code>{}</code>".format(ACTUALADMIN)
    R = 0
    for O in sql.get_all_fban_users(fed_id):
        R = R + 1

    text += "\nNumber of bans: <code>{}</code>".format(R)
    h = sql.all_fed_chats(fed_id)
    asdf = len(h)
    text += "\nNumber of connected chats: <code>{}</code>".format(asdf)

    update.effective_message.reply_text(text, parse_mode=ParseMode.HTML)
Exemplo n.º 22
0
def get_help(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    args = update.effective_message.text.split(None, 1)

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

        update.effective_message.reply_text(
            "Contact me in PM to get the list of possible commands.",
            reply_markup=InlineKeyboardMarkup([[
                InlineKeyboardButton(text="Help",
                                     url="t.me/{}?start=help".format(
                                         bot.username))
            ]]))
        return

    elif len(args) >= 2 and any(args[1].lower() == x for x in HELPABLE):
        module = args[1].lower()
        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)
        send_help(
            chat.id, text,
            InlineKeyboardMarkup([[
                InlineKeyboardButton(text=tld(chat.id, "Back"),
                                     callback_data="help_back")
            ]]))

    else:
        send_help(
            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")))
Exemplo n.º 23
0
def stop_filter(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    args = update.effective_message.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":
            chat_name = "local notes"
        else:
            chat_name = chat.title

    if len(args) < 2:
        return

    chat_filters = sql.get_chat_triggers(chat_id)

    if not chat_filters:
        update.effective_message.reply_text(
            tld(chat.id, "No filters are active in {}!").format(chat_name))
        return

    for keyword in chat_filters:
        if keyword == args[1]:
            sql.remove_filter(chat_id, args[1])
            update.effective_message.reply_text(
                tld(chat.id,
                    "Yep, I'll stop replying to that in *{}*.").format(
                        chat_name),
                parse_mode=telegram.ParseMode.MARKDOWN)
            raise DispatcherHandlerStop

    update.effective_message.reply_text(
        tld(
            chat.id,
            "That's not a current filter - run /filters for all active filters."
        ))
Exemplo n.º 24
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:
        bot.restrict_chat_member(chat.id, user.id, can_send_messages=False)
        msg.reply_text(
            tld(
                chat.id,
                "I like to leave the flooding to natural disasters. But you, you were just a "
                "disappointment. *Muted*!"))

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

    except BadRequest:
        msg.reply_text(
            tld(
                chat.id,
                "I can't mute people here, give me permissions first! Until then, I'll disable antiflood."
            ))
        sql.set_flood(chat.id, 0)
        return "<b>{}:</b>" \
               "\n#INFO" \
               "\nDon't have mute permissions, so automatically disabled antiflood.".format(chat.title)
Exemplo n.º 25
0
    def build_curr_disabled(chatD_id, chat_id):

        disabled = sql.get_all_disabled(chatD_id)

        result = ""
        for cmd in disabled:
            result += " • `{}`\n".format(escape_markdown(cmd))

        if result == "":
            return tld(chat_id, "No commands are disabled!")
        else:
            return result
Exemplo n.º 26
0
def del_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 not fed_id:
        update.effective_message.reply_text(
            tld(
                chat.id,
                "At the moment, We only supported deleting federation on the group that joined it."
            ))
        return

    if not is_user_fed_owner(fed_id, user.id):
        update.effective_message.reply_text(
            tld(chat.id, "Only fed owner can do this!"))
        return

    sql.del_fed(fed_id, chat.id)
    update.effective_message.reply_text(tld(chat.id, "Deleted!"))
Exemplo n.º 27
0
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":
                control_panel(bot, update)
        else:
            send_start(bot, update)
    else:
        update.effective_message.reply_text("Hey there! I'm alive :3")
Exemplo n.º 28
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 is_user_fed_owner(fed_id, user.id) == True:
        update.effective_message.reply_text(
            tld(chat.id, "Are you gonna promote yourself?"))
        return

    elif 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)
    update.effective_message.reply_text(tld(chat.id, "Promoted Successfully!"))
Exemplo n.º 29
0
def list_handlers(bot: Bot, update: Update):
    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 not conn == False:
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
        filter_list = tld(chat.id, "*List of filters in {}:*\n")
    else:
        chat_id = update.effective_chat.id
        if chat.type == "private":
            chat_name = tld(chat.id, "local filters")
            filter_list = tld(chat.id, "*local filters:*\n")
        else:
            chat_name = chat.title
            filter_list = tld(chat.id, "*Filters in {}*:\n")

    all_handlers = sql.get_chat_triggers(chat_id)

    if not all_handlers:
        update.effective_message.reply_text(
            tld(chat.id, "No filters in {}!").format(chat_name))
        return

    for keyword in all_handlers:
        entry = " • `{}`\n".format(escape_markdown(keyword))
        if len(entry) + len(filter_list) > telegram.MAX_MESSAGE_LENGTH:
            update.effective_message.reply_text(
                filter_list.format(chat_name),
                parse_mode=telegram.ParseMode.MARKDOWN)
            filter_list = entry
        else:
            filter_list += entry

    update.effective_message.reply_text(filter_list.format(chat_name),
                                        parse_mode=telegram.ParseMode.MARKDOWN)
Exemplo n.º 30
0
def welcome_fed(bot, update):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]

    fed_id = sql.get_fed_id(chat.id)
    fban = fban = sql.get_fban_user(fed_id, user.id)
    if not fban == False:
        update.effective_message.reply_text(
            tld(
                chat.id,
                "This user is banned in current federation! I will remove him."
            ))
        bot.kick_chat_member(chat.id, user.id)
        return True
    else:
        return False