Ejemplo n.º 1
0
def clear_rules(update, context):
    chat = update.effective_chat
    chat_id = update.effective_chat.id
    user = update.effective_user

    conn = connected(context.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,
                tl(update.effective_message,
                   "Anda bisa lakukan command ini pada grup, bukan pada PM"))
            return ""
        chat = update.effective_chat
        chat_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title

    chat_id = update.effective_chat.id
    sql.set_rules(chat_id, "")
    send_message(update.effective_message,
                 tl(update.effective_message, "Berhasil membersihkan aturan!"))
Ejemplo n.º 2
0
def list_locks(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user

    # Connection check
    conn = connected(context.bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_name = chat.title
    else:
        if update.effective_message.chat.type == "private":
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Anda bisa lakukan command ini pada grup, bukan pada PM"))
            return ""
        chat = update.effective_chat
        chat_name = update.effective_message.chat.title

    res = build_lock_message(chat.id)
    if conn:
        res = res.replace(tl(update.effective_message, 'obrolan ini'),
                          '*{}*'.format(chat_name))

    send_message(update.effective_message, res, parse_mode=ParseMode.MARKDOWN)
Ejemplo n.º 3
0
    def commands(update, context):
        chat = update.effective_chat
        user = update.effective_user
        conn = connected(context.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,
                    languages.tl(
                        update.effective_message,
                        "Anda bisa lakukan command ini pada grup, bukan pada PM"
                    ))
                return ""
            chat = update.effective_chat
            chat_id = update.effective_chat.id
            chat_name = update.effective_message.chat.title

        text = build_curr_disabled(chat.id)
        send_message(update.effective_message,
                     text,
                     parse_mode=ParseMode.MARKDOWN)
Ejemplo n.º 4
0
def set_blue_text_must_click(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    args = context.args

    conn = connected(context.bot, update, chat, user.id, need_admin=True)
    if conn:
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if update.effective_message.chat.type == "private":
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Anda bisa lakukan command ini pada grup, bukan pada PM"))
            return ""
        chat_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title

    if len(args) >= 1:
        val = args[0].lower()
        if val == "off" or val == "no":
            sql.set_cleanbt(chat_id, False)
            if conn:
                text = tl(
                    update.effective_message,
                    "Penghapus pesan biru telah di *non-aktifka*n di *{}*."
                ).format(chat_name)
            else:
                text = tl(update.effective_message,
                          "Penghapus pesan biru telah di *non-aktifkan*.")
            send_message(update.effective_message, text, parse_mode="markdown")

        elif val == "yes" or val == "ya" or val == "on":
            sql.set_cleanbt(chat_id, True)
            if conn:
                text = tl(update.effective_message,
                          "Penghapus pesan biru telah di *aktifkan* di *{}*."
                          ).format(chat_name)
            else:
                text = tl(update.effective_message,
                          "Penghapus pesan biru telah di *aktifkan*.")
            send_message(update.effective_message, text, parse_mode="markdown")

        else:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Argumen tidak dikenal - harap gunakan 'yes', atau 'no'."))
    else:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Pengaturan untuk penghapus pesan biru saat ini di {}: *{}*").
            format(chat_name,
                   "Enabled" if sql.is_enable(chat_id) else "Disabled"),
            parse_mode="markdown")
Ejemplo n.º 5
0
    def disable(update, context):
        chat = update.effective_chat  # type: Optional[Chat]
        user = update.effective_user
        args = context.args

        conn = connected(context.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,
                    languages.tl(
                        update.effective_message,
                        "Anda bisa lakukan command ini pada grup, bukan pada PM"
                    ))
                return ""
            chat = update.effective_chat
            chat_id = update.effective_chat.id
            chat_name = update.effective_message.chat.title

        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(chat.id, disable_cmd)
                if conn:
                    text = languages.tl(
                        update.effective_message,
                        "Menonaktifkan penggunaan `{}` pada *{}*").format(
                            disable_cmd, chat_name)
                else:
                    text = languages.tl(
                        update.effective_message,
                        "Menonaktifkan penggunaan `{}`").format(disable_cmd)
                send_message(update.effective_message,
                             text,
                             parse_mode=ParseMode.MARKDOWN)
            else:
                send_message(
                    update.effective_message,
                    languages.tl(update.effective_message,
                                 "Perintah itu tidak bisa dinonaktifkan"))

        else:
            send_message(
                update.effective_message,
                languages.tl(update.effective_message,
                             "Apa yang harus saya nonaktifkan?"))
Ejemplo n.º 6
0
def add_blacklist(update, context):
    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(context.bot, update, chat, user.id)
    if conn:
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        chat_id = update.effective_chat.id
        if chat.type == "private":
            return
        else:
            chat_name = chat.title

    if len(words) > 1:
        text = words[1]
        to_blacklist = list(
            set(trigger.strip() for trigger in text.split("\n")
                if trigger.strip()))
        for trigger in to_blacklist:
            sql.add_to_blacklist(chat_id, trigger.lower())

        if len(to_blacklist) == 1:
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "<code>{}</code> ditambahkan ke daftar hitam di <b>{}</b>!"
                ).format(html.escape(to_blacklist[0]), chat_name),
                parse_mode=ParseMode.HTML)

        else:
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "<code>{}</code> Pemicu ditambahkan ke daftar hitam di <b>{}</b>!"
                ).format(len(to_blacklist), chat_name),
                parse_mode=ParseMode.HTML)

    else:
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Beri tahu saya kata-kata apa yang ingin Anda hapus dari daftar hitam."
            ))
Ejemplo n.º 7
0
def blacklist(update, context):
    msg = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    args = context.args

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

    filter_list = tl(
        update.effective_message,
        "<b>Kata daftar hitam saat ini di {}:</b>\n").format(chat_name)

    all_blacklisted = sql.get_chat_blacklist(chat_id)

    if len(args) > 0 and args[0].lower() == 'copy':
        for trigger in all_blacklisted:
            filter_list += "<code>{}</code>\n".format(html.escape(trigger))
    else:
        for trigger in all_blacklisted:
            filter_list += " - <code>{}</code>\n".format(html.escape(trigger))

    # for trigger in all_blacklisted:
    #     filter_list += " - <code>{}</code>\n".format(html.escape(trigger))

    split_text = split_message(filter_list)
    for text in split_text:
        if filter_list == tl(
                update.effective_message,
                "<b>Kata daftar hitam saat ini di {}:</b>\n").format(
                    chat_name):
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Tidak ada pesan daftar hitam di <b>{}</b>!").format(
                       chat_name),
                parse_mode=ParseMode.HTML)
            return
        send_message(update.effective_message, text, parse_mode=ParseMode.HTML)
Ejemplo n.º 8
0
def private_rules(update, context):
    args = context.args
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    conn = connected(context.bot, update, chat, user.id)
    if conn:
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        chat_id = update.effective_chat.id
        if chat.type == "private":
            chat_name = chat.title
        else:
            chat_name = chat.title

    if len(args) >= 1:
        if args[0] in ("yes", "on", "ya"):
            sql.private_rules(str(chat_id), True)
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Private Rules di *aktifkan*, pesan peraturan akan di kirim di PM."
                ),
                parse_mode="markdown")
        elif args[0] in ("no", "off"):
            sql.private_rules(str(chat_id), False)
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Private Rules di *non-aktifkan*, pesan peraturan akan di kirim di grup."
                ),
                parse_mode="markdown")
        else:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Argumen tidak dikenal - harap gunakan 'yes', atau 'no'."))
    else:
        is_private = sql.get_private_rules(chat_id)
        send_message(update.effective_message,
                     tl(update.effective_message,
                        "Pengaturan Private Rules di {}: *{}*").format(
                            chat_name,
                            "Enabled" if is_private else "Disabled"),
                     parse_mode="markdown")
Ejemplo n.º 9
0
def stop_filter(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    args = update.effective_message.text.split(None, 1)

    conn = connected(context.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 = tl(update.effective_message, "catatan lokal")
        else:
            chat_name = chat.title

    if len(args) < 2:
        send_message(
            update.effective_message,
            tl(update.effective_message, "Apa yang harus saya hentikan?"))
        return

    chat_filters = sql.get_chat_triggers(chat_id)

    if not chat_filters:
        send_message(
            update.effective_message,
            tl(update.effective_message, "Tidak ada filter aktif di sini!"))
        return

    for keyword in chat_filters:
        if keyword == args[1]:
            sql.remove_filter(chat_id, args[1])
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Ya, saya akan berhenti menjawabnya di *{}*.").format(
                       chat_name),
                parse_mode=telegram.ParseMode.MARKDOWN)
            raise DispatcherHandlerStop

    send_message(
        update.effective_message,
        "Itu bukan filter aktif - jalankan /filter untuk semua filter aktif.")
Ejemplo n.º 10
0
def flood(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]

    conn = connected(context.bot, update, chat, user.id, need_admin=False)
    if conn:
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if update.effective_message.chat.type == "private":
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Anda bisa lakukan command ini pada grup, bukan pada PM"))
            return
        chat_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title

    limit = sql.get_flood_limit(chat_id)
    if limit == 0:
        if conn:
            text = tl(
                update.effective_message,
                "Saat ini saya tidak memberlakukan pengendalian pesan beruntun pada *{}*!"
            ).format(chat_name)
        else:
            text = tl(
                update.effective_message,
                "Saat ini saya tidak memberlakukan pengendalian pesan beruntun"
            )
        send_message(update.effective_message, text, parse_mode="markdown")
    else:
        if conn:
            text = tl(
                update.effective_message,
                "Saat ini saya melarang pengguna jika mereka mengirim lebih dari *{}* pesan berturut-turut pada *{}*."
            ).format(limit, chat_name)
        else:
            text = tl(
                update.effective_message,
                "Saat ini saya melarang pengguna jika mereka mengirim lebih dari *{}* pesan berturut-turut."
            ).format(limit)
        send_message(update.effective_message, text, parse_mode="markdown")
Ejemplo n.º 11
0
def list_handlers(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]

    conn = connected(context.bot, update, chat, user.id, need_admin=False)
    if not conn == False:
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
        filter_list = "*Filter di {}:*\n"
    else:
        chat_id = update.effective_chat.id
        if chat.type == "private":
            chat_name = tl(update.effective_message, "filter lokal")
            filter_list = tl(update.effective_message, "*filter lokal:*\n")
        else:
            chat_name = chat.title
            filter_list = tl(update.effective_message, "*Filter di {}*:\n")

    all_handlers = sql.get_chat_triggers(chat_id)

    if not all_handlers:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Tidak ada filter di {}!").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:
            send_message(update.effective_message,
                         filter_list.format(chat_name),
                         parse_mode=telegram.ParseMode.MARKDOWN)
            filter_list = entry
        else:
            filter_list += entry

    send_message(update.effective_message,
                 filter_list.format(chat_name),
                 parse_mode=telegram.ParseMode.MARKDOWN)
Ejemplo n.º 12
0
def set_rules(update, context):
    chat = update.effective_chat
    chat_id = update.effective_chat.id
    user = update.effective_user
    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

    conn = connected(context.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,
                tl(update.effective_message,
                   "Anda bisa lakukan command ini pada grup, bukan pada PM"))
            return ""
        chat = update.effective_chat
        chat_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title

    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_rules(chat_id, markdown_rules)
        if conn:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Berhasil mengatur aturan untuk *{}*.").format(chat_name),
                parse_mode="markdown")
        else:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Berhasil mengatur aturan untuk grup ini."))

    elif msg.reply_to_message and len(args) == 1:
        txt = msg.reply_to_message.text
        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_rules(chat_id, markdown_rules)
        if conn:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Berhasil mengatur aturan untuk *{}*.").format(chat_name),
                parse_mode="markdown")
        else:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Berhasil mengatur aturan untuk grup ini."))
Ejemplo n.º 13
0
def add_blackliststicker(update, context):
    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(context.bot, update, chat, user.id)
    if conn:
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        chat_id = update.effective_chat.id
        if chat.type == "private":
            return
        else:
            chat_name = chat.title

    if len(words) > 1:
        text = words[1].replace('https://t.me/addstickers/', '')
        to_blacklist = list(
            set(trigger.strip() for trigger in text.split("\n")
                if trigger.strip()))
        added = 0
        for trigger in to_blacklist:
            try:
                get = context.bot.getStickerSet(trigger)
                sql.add_to_stickers(chat_id, trigger.lower())
                added += 1
            except BadRequest:
                send_message(
                    update.effective_message,
                    tl(update.effective_message,
                       "Stiker `{}` tidak dapat di temukan!").format(trigger),
                    parse_mode="markdown")

        if added == 0:
            return

        if len(to_blacklist) == 1:
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Stiker <code>{}</code> ditambahkan ke daftar hitam stiker di <b>{}</b>!"
                ).format(html.escape(to_blacklist[0]), chat_name),
                parse_mode=ParseMode.HTML)
        else:
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "<code>{}</code> stiker ditambahkan ke daftar hitam stiker di <b>{}</b>!"
                ).format(added, chat_name),
                parse_mode=ParseMode.HTML)
    elif msg.reply_to_message:
        added = 0
        trigger = msg.reply_to_message.sticker.set_name
        if trigger == None:
            send_message(update.effective_message,
                         tl(update.effective_message, "Stiker tidak valid!"))
            return
        try:
            get = context.bot.getStickerSet(trigger)
            sql.add_to_stickers(chat_id, trigger.lower())
            added += 1
        except BadRequest:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Stiker `{}` tidak dapat di temukan!").format(trigger),
                parse_mode="markdown")

        if added == 0:
            return

        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Stiker <code>{}</code> ditambahkan ke daftar hitam stiker di <b>{}</b>!"
            ).format(trigger, chat_name),
            parse_mode=ParseMode.HTML)
    else:
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Beri tahu saya stiker apa yang ingin Anda tambahkan ke daftar hitam stiker."
            ))
Ejemplo n.º 14
0
def kick(update, context):
    currentchat = update.effective_chat  # type: Optional[Chat]
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    args = context.args

    user_id, reason = extract_user_and_text(message, args)
    if user_id == "error":
        send_message(update.effective_message,
                     tl(update.effective_message, reason))
        return ""

    if not user_id:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda sepertinya tidak mengacu pada pengguna."))
        return ""

    conn = connected(context.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,
                tl(update.effective_message,
                   "Anda bisa lakukan command ini pada grup, bukan pada PM"))
            return ""
        chat = update.effective_chat
        chat_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title

    check = context.bot.getChatMember(chat_id, context.bot.id)
    if check.status == 'member':
        if conn:
            text = tl(
                update.effective_message,
                "Saya tidak bisa membatasi orang di {}! Pastikan saya admin dan dapat menunjuk admin baru."
            ).format(chat_name)
        else:
            text = tl(
                update.effective_message,
                "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru."
            )
        send_message(update.effective_message, text, parse_mode="markdown")
        return ""
    else:
        if check['can_restrict_members'] == False:
            if conn:
                text = tl(
                    update.effective_message,
                    "Saya tidak bisa membatasi orang di *{}*! Pastikan saya admin dan dapat menunjuk admin baru."
                ).format(chat_name)
            else:
                text = tl(
                    update.effective_message,
                    "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru."
                )
            send_message(update.effective_message, text, parse_mode="markdown")
            return ""

    if not user_id:
        return ""

    try:
        if conn:
            member = context.bot.getChatMember(chat_id, user_id)
        else:
            member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Saya tidak dapat menemukan pengguna ini 😣"))
            return ""
        else:
            raise

    if user_id == context.bot.id:
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Saya tidak akan menendang diri saya sendiri, apakah kamu gila? 😠"
            ))
        return ""

    if is_user_ban_protected(chat, user_id):
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Saya tidak bisa menendang orang ini karena dia adalah admin 😒"
            ))
        return ""

    if user_id == context.bot.id:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Yahhh aku tidak akan melakukan itu 😝"))
        return ""

    check = context.bot.getChatMember(chat.id, user.id)
    if check['can_restrict_members'] == False:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda tidak punya hak untuk membatasi seseorang."))
        return ""

    if conn:
        res = context.bot.unbanChatMember(
            chat_id, user_id)  # unban on current user = kick
    else:
        res = chat.unban_member(user_id)  # unban on current user = kick
    if res:
        if conn:
            context.bot.send_sticker(currentchat.id,
                                     BAN_STICKER)  # banhammer marie sticker
            text = tl(update.effective_message,
                      "Tertendang pada *{}*! 😝").format(chat_name)
            send_message(update.effective_message, text, parse_mode="markdown")
        else:
            if message.text.split(None, 1)[0][1:] == "skick":
                update.effective_message.delete()
            else:
                context.bot.send_sticker(
                    chat.id, BAN_STICKER)  # banhammer marie sticker
                text = tl(update.effective_message, "Tertendang! 😝")
                send_message(update.effective_message,
                             text,
                             parse_mode="markdown")
        log = "<b>{}:</b>" \
              "\n#KICKED" \
              "\n<b>Admin:</b> {}" \
              "\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title),
                                                           mention_html(user.id, user.first_name),
                                                           mention_html(member.user.id, member.user.first_name),
                                                           member.user.id)
        log += "\n<b>Reason:</b> {}".format(reason)

        return log

    else:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Yah sial, aku tidak bisa menendang pengguna itu 😒"))

    return ""
Ejemplo n.º 15
0
def unban(update, context):
    message = update.effective_message  # type: Optional[Message]
    user = update.effective_user  # type: Optional[User]
    chat = update.effective_chat  # type: Optional[Chat]
    args = context.args

    user_id, reason = extract_user_and_text(message, args)
    if user_id == "error":
        send_message(update.effective_message,
                     tl(update.effective_message, reason))
        return ""

    conn = connected(context.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,
                tl(update.effective_message,
                   "Anda bisa lakukan command ini pada grup, bukan pada PM"))
            return ""
        chat = update.effective_chat
        chat_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title

    if not user_id:
        return ""

    check = context.bot.getChatMember(chat_id, context.bot.id)
    if check.status == 'member':
        if conn:
            text = tl(
                update.effective_message,
                "Saya tidak bisa membatasi orang di {}! Pastikan saya admin dan dapat menunjuk admin baru."
            ).format(chat_name)
        else:
            text = tl(
                update.effective_message,
                "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru."
            )
        send_message(update.effective_message, text, parse_mode="markdown")
        return ""
    else:
        if check['can_restrict_members'] == False:
            if conn:
                text = tl(
                    update.effective_message,
                    "Saya tidak bisa membatasi orang di {}! Pastikan saya admin dan dapat menunjuk admin baru."
                ).format(chat_name)
            else:
                text = tl(
                    update.effective_message,
                    "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru."
                )
            send_message(update.effective_message, text, parse_mode="markdown")
            return ""

    try:
        if conn:
            member = context.bot.getChatMember(chat_id, user_id)
        else:
            member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Saya tidak dapat menemukan pengguna ini"))
            return ""
        else:
            raise

    if user_id == context.bot.id:
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Bagaimana saya akan unban diri saya sendiri jika saya tidak ada di sini...? 🤔"
            ))
        return ""

    if is_user_in_chat(chat, user_id):
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Mengapa Anda mencoba unban seseorang yang sudah ada di obrolan? 😑"
            ))
        return ""

    check = context.bot.getChatMember(chat.id, user.id)
    if check['can_restrict_members'] == False:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda tidak punya hak untuk membatasi seseorang."))
        return ""

    if conn:
        context.bot.unbanChatMember(chat_id, user_id)
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Ya, pengguna ini dapat bergabung pada {}! 😁").format(
                   chat_name))
    else:
        chat.unban_member(user_id)
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Ya, pengguna ini dapat bergabung! 😁"))

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

    return log
Ejemplo n.º 16
0
def temp_ban(update, context):
    currentchat = update.effective_chat  # type: Optional[Chat]
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    args = context.args

    user_id, reason = extract_user_and_text(message, args)
    if user_id == "error":
        send_message(update.effective_message,
                     tl(update.effective_message, reason))
        return ""

    conn = connected(context.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,
                tl(update.effective_message,
                   "Anda bisa lakukan command ini pada grup, bukan pada PM"))
            return ""
        chat = update.effective_chat
        chat_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title

    check = context.bot.getChatMember(chat_id, context.bot.id)
    if check.status == 'member':
        if conn:
            text = tl(
                update.effective_message,
                "Saya tidak bisa membatasi orang di *{}*! Pastikan saya admin dan dapat menunjuk admin baru."
            ).format(chat_name)
        else:
            text = tl(
                update.effective_message,
                "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru."
            )
        send_message(update.effective_message, text, parse_mode="markdown")
        return ""
    else:
        if check['can_restrict_members'] == False:
            if conn:
                text = tl(
                    update.effective_message,
                    "Saya tidak bisa membatasi orang di *{}*! Pastikan saya admin dan dapat menunjuk admin baru."
                ).format(chat_name)
            else:
                text = tl(
                    update.effective_message,
                    "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru."
                )
            send_message(update.effective_message, text, parse_mode="markdown")
            return ""

    if not user_id:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda sepertinya tidak mengacu pada pengguna."))
        return ""

    try:
        if conn:
            member = context.bot.getChatMember(chat_id, user_id)
        else:
            member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Saya tidak dapat menemukan pengguna ini 😣"))
            return ""
        else:
            raise

    if user_id == context.bot.id:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Saya tidak akan BAN diri saya sendiri, apakah kamu gila? 😠"))
        return ""

    if is_user_ban_protected(chat, user_id, member):
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Saya tidak bisa banned orang ini karena dia adalah admin 😒"))
        return ""

    if member['can_restrict_members'] == False:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda tidak punya hak untuk membatasi seseorang."))
        return ""

    if not reason:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda belum menetapkan waktu untuk banned pengguna ini!"))
        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#TEMPBAN" \
          "\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:
        if conn:
            context.bot.kickChatMember(chat_id, user_id, until_date=bantime)
            context.bot.send_sticker(currentchat.id,
                                     BAN_STICKER)  # banhammer marie sticker
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Banned! Pengguna diblokir untuk *{}* pada *{}*.").format(
                       time_val, chat_name),
                parse_mode="markdown")
        else:
            chat.kick_member(user_id, until_date=bantime)
            context.bot.send_sticker(chat.id,
                                     BAN_STICKER)  # banhammer marie sticker
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Banned! Pengguna diblokir untuk {}.").format(time_val))
        return log

    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Banned! Pengguna diblokir untuk {}.").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)
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Yah sial, aku tidak bisa menendang pengguna itu 😒"))

    return ""
Ejemplo n.º 17
0
def ban(update, context):
    currentchat = update.effective_chat  # type: Optional[Chat]
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    args = context.args

    user_id, reason = extract_user_and_text(message, args)
    if user_id == "error":
        send_message(update.effective_message,
                     tl(update.effective_message, reason))
        return ""

    conn = connected(context.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,
                tl(update.effective_message,
                   "Anda bisa lakukan command ini pada grup, bukan pada PM"))
            return ""
        chat = update.effective_chat
        chat_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title

    check = context.bot.getChatMember(chat_id, context.bot.id)
    if check.status == 'member' or check['can_restrict_members'] == False:
        if conn:
            text = tl(
                update.effective_message,
                "Saya tidak bisa membatasi orang di {}! Pastikan saya admin dan dapat menunjuk admin baru."
            ).format(chat_name)
        else:
            text = tl(
                update.effective_message,
                "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru."
            )
        send_message(update.effective_message, text, parse_mode="markdown")
        return ""

    if not user_id:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda sepertinya tidak mengacu pada pengguna."))
        return ""

    try:
        if conn:
            member = context.bot.getChatMember(chat_id, user_id)
        else:
            member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            if conn:
                text = tl(
                    update.effective_message,
                    "Saya tidak dapat menemukan pengguna ini pada *{}* 😣"
                ).format(chat_name)
            else:
                text = tl(update.effective_message,
                          "Saya tidak dapat menemukan pengguna ini 😣")
            send_message(update.effective_message, text, parse_mode="markdown")
            return ""
        else:
            raise

    if user_id == context.bot.id:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Saya tidak akan BAN diri saya sendiri, apakah kamu gila? 😠"))
        return ""

    if is_user_ban_protected(chat, user_id, member):
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Saya tidak bisa banned orang ini karena dia adalah admin 😒"))
        return ""

    if member['can_restrict_members'] == False:
        if conn:
            text = tl(
                update.effective_message,
                "Anda tidak punya hak untuk membatasi seseorang pada *{}*."
            ).format(chat_name)
        else:
            text = tl(update.effective_message,
                      "Anda tidak punya hak untuk membatasi seseorang.")
        send_message(update.effective_message, text, parse_mode="markdown")
        return ""

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

    try:
        if conn:
            context.bot.kickChatMember(chat_id, user_id)
            context.bot.send_sticker(currentchat.id,
                                     BAN_STICKER)  # banhammer marie sticker
            send_message(update.effective_message,
                         tl(update.effective_message,
                            "Terbanned pada *{}*! 😝").format(chat_name),
                         parse_mode="markdown")
        else:
            chat.kick_member(user_id)
            if message.text.split(None, 1)[0][1:] == "sban":
                update.effective_message.delete()
            else:
                context.bot.send_sticker(
                    chat.id, BAN_STICKER)  # banhammer marie sticker
                send_message(update.effective_message,
                             tl(update.effective_message, "Terbanned! 😝"))
        return log

    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            send_message(update.effective_message,
                         tl(update.effective_message, "Terbanned! 😝"),
                         quote=False)
            return log
        elif excp.message == "Message can't be deleted":
            pass
        else:
            LOGGER.warning(update)
            LOGGER.exception(
                "ERROR membanned pengguna %s di obrolan %s (%s) disebabkan oleh %s",
                user_id, chat.title, chat.id, excp.message)
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Yah sial, aku tidak bisa banned pengguna itu 😒"))

    return ""
Ejemplo n.º 18
0
def temp_mute(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    args = context.args

    user_id, reason = extract_user_and_text(message, args)
    if user_id == "error":
        send_message(update.effective_message,
                     tl(update.effective_message, reason))
        return ""

    if not user_id:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda sepertinya tidak mengacu pada pengguna."))
        return ""

    conn = connected(context.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":
            update.effective_send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Anda bisa lakukan command ini pada grup, bukan pada PM"))
            return ""
        chat = update.effective_chat
        chat_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Saya tidak dapat menemukan pengguna ini"))
            return ""
        else:
            raise

    if is_user_admin(chat, user_id, member):
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Saya benar-benar berharap dapat membisukan admin..."))
        return ""

    if user_id == context.bot.id:
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Saya tidak akan membisukan diri saya sendiri, apakah kamu gila?"
            ))
        return ""

    check = context.bot.getChatMember(chat.id, user.id)
    if check['can_restrict_members'] == False:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda tidak punya hak untuk membatasi seseorang."))
        return ""

    if not reason:
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Anda belum menetapkan waktu untuk menonaktifkan pengguna ini!"
            ))
        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#TMUTE" \
          "\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:
            context.bot.restrict_chat_member(
                chat.id,
                user_id,
                until_date=mutetime,
                permissions=ChatPermissions(can_send_messages=False))
            if conn:
                text = tl(update.effective_message,
                          "Dibisukan untuk *{}* pada *{}*!").format(
                              time_val, chat_name)
            else:
                text = tl(update.effective_message,
                          "Dibisukan untuk *{}*!").format(time_val)
            send_message(update.effective_message, text, parse_mode="markdown")
            return log
        else:
            send_message(
                update.effective_message,
                tl(update.effective_message, "Pengguna ini sudah dibungkam."))

    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            send_message(update.effective_message,
                         tl(update.effective_message,
                            "Dibisukan untuk *{}*!").format(time_val),
                         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)
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Yah sial, aku tidak bisa membisukan pengguna itu."))

    return ""
Ejemplo n.º 19
0
def mute(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    args = context.args

    user_id = extract_user(message, args)
    if not user_id or user_id == "error":
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Anda harus memberi saya nama pengguna untuk membungkam, atau membalas seseorang untuk dibisukan."
            ))
        return ""

    conn = connected(context.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
        text = tl(update.effective_message,
                  "Terbisukan pada *{}*! 😆").format(chat_name)
    else:
        if update.effective_message.chat.type == "private":
            update.effective_send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Anda bisa lakukan command ini pada grup, bukan pada PM"))
            return ""
        chat = update.effective_chat
        chat_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title
        text = tl(update.effective_message, "Terbisukan! 😆")

    if user_id == context.bot.id:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Saya tidak akan membungkam diri saya sendiri!"))
        return ""

    check = context.bot.getChatMember(chat.id, user.id)
    if check['can_restrict_members'] == False:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda tidak punya hak untuk membatasi seseorang."))
        return ""

    member = chat.get_member(int(user_id))

    if member:
        if is_user_admin(chat, user_id, member=member):
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Saya tidak bisa menghentikan seorang admin berbicara!"))

        elif member.can_send_messages is None or member.can_send_messages:
            context.bot.restrict_chat_member(
                chat.id,
                user_id,
                permissions=ChatPermissions(can_send_messages=False))
            send_message(update.effective_message, text, parse_mode="markdown")
            return "<b>{}:</b>" \
                   "\n#MUTE" \
                   "\n<b>Admin:</b> {}" \
                   "\n<b>User:</b> {}".format(html.escape(chat.title),
                                              mention_html(user.id, user.first_name),
                                              mention_html(member.user.id, member.user.first_name))

        else:
            send_message(
                update.effective_message,
                tl(update.effective_message, "Pengguna ini sudah dibungkam!"))
    else:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Pengguna ini tidak ada dalam obrolan!"))

    return ""
Ejemplo n.º 20
0
def timeout_mode(update, context):
    chat = update.effective_chat
    user = update.effective_user
    args = context.args

    conn = connected(context.bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if update.effective_message.chat.type == "private":
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Anda bisa lakukan command ini pada grup, bukan pada PM"))
            return ""
        chat = update.effective_chat
        chat_name = update.effective_message.chat.title

    getcur, extra_verify, cur_value, timeout, timeout_mode, cust_text = sql.welcome_security(
        chat.id)

    if args:
        if args[0].lower() == 'kick' or args[0].lower(
        ) == 'tendang' or args[0].lower() == 'leave':
            settypeblacklist = tl(update.effective_message, 'kick')
            sql.set_welcome_security(chat.id, getcur, extra_verify, cur_value,
                                     timeout, 1, cust_text)
        elif args[0].lower() == 'ban' or args[0].lower() == 'banned':
            settypeblacklist = tl(update.effective_message, 'banned')
            sql.set_welcome_security(chat.id, getcur, extra_verify, cur_value,
                                     timeout, 2, cust_text)
        else:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Saya hanya mengerti kick/banned!"))
            return
        if conn:
            text = tl(update.effective_message,
                      "Mode timeout diubah, Pengguna akan di `{}` pada *{}*!"
                      ).format(settypeblacklist, chat_name)
        else:
            text = tl(update.effective_message,
                      "Mode timeout diubah, Pengguna akan di `{}`!").format(
                          settypeblacklist)
        send_message(update.effective_message, text, parse_mode="markdown")
    else:
        if timeout_mode == 1:
            settypeblacklist = tl(update.effective_message, "kick")
        elif timeout_mode == 2:
            settypeblacklist = tl(update.effective_message, "banned")
        if conn:
            text = tl(
                update.effective_message,
                "Mode timeout saat ini disetel ke *{}* pada *{}*.").format(
                    settypeblacklist, chat_name)
        else:
            text = tl(update.effective_message,
                      "Mode timeout saat ini disetel ke *{}*.").format(
                          settypeblacklist)
        send_message(update.effective_message,
                     text,
                     parse_mode=ParseMode.MARKDOWN)
    return
Ejemplo n.º 21
0
def lock_warns(update, context):
    args = context.args
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user

    # Connection check
    conn = connected(context.bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
    else:
        if update.effective_message.chat.type == "private":
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Anda bisa lakukan command ini pada grup, bukan pada PM"))
            return ""
        chat = update.effective_chat
        chat_id = update.effective_chat.id

    if args:
        if args[0] == "on" or args[0] == "yes":
            sql.set_lockconf(chat_id, True)
            try:
                send_message(
                    update.effective_message,
                    tl(
                        update.effective_message,
                        "Saya *akan* memperingati pengguna jika dia mengirim pesan yang dikunci"
                    ),
                    parse_mode="markdown")
            except BadRequest:
                send_message(
                    update.effective_message,
                    tl(update.effective_message,
                       "Saya *akan* memperingati pengguna jika dia mengirim pesan yang dikunci",
                       parse_mode="markdown",
                       quote=False))
        elif args[0] == "off" or args[0] == "no":
            sql.set_lockconf(chat_id, False)
            try:
                send_message(
                    update.effective_message,
                    tl(
                        update.effective_message,
                        "Saya *tidak akan* memperingati pengguna jika dia mengirim pesan yang dikunci"
                    ),
                    parse_mode="markdown")
            except BadRequest:
                send_message(
                    update.effective_message,
                    tl(update.effective_message,
                       "Saya *tidak akan* memperingati pengguna jika dia mengirim pesan yang dikunci",
                       parse_mode="markdown",
                       quote=False))
        else:
            try:
                send_message(
                    update.effective_message,
                    tl(update.effective_message,
                       "Saya hanya mengerti 'on/yes' atau 'off/no' saja!"),
                    parse_mode="markdown")
            except BadRequest:
                send_message(
                    update.effective_message,
                    tl(update.effective_message,
                       "Saya hanya mengerti 'on/yes' atau 'off/no' saja!"),
                    parse_mode="markdown",
                    quote=False)
    else:
        getconf = sql.get_lockconf(chat_id)
        if getconf:
            try:
                send_message(
                    update.effective_message,
                    tl(
                        update.effective_message,
                        "Saat ini saya *akan* memperingati pengguna jika dia mengirim pesan yang dikunci"
                    ),
                    parse_mode="markdown")
            except BadRequest:
                send_message(
                    update.effective_message,
                    tl(
                        update.effective_message,
                        "Saat ini saya *akan* memperingati pengguna jika dia mengirim pesan yang dikunci"
                    ),
                    parse_mode="markdown",
                    quote=False)
        else:
            try:
                send_message(
                    update.effective_message,
                    tl(
                        update.effective_message,
                        "Saat ini saya *tidak akan* memperingati pengguna jika dia mengirim pesan yang dikunci"
                    ),
                    parse_mode="markdown")
            except BadRequest:
                send_message(
                    update.effective_message,
                    tl(
                        update.effective_message,
                        "Saat ini saya *tidak akan* memperingati pengguna jika dia mengirim pesan yang dikunci"
                    ),
                    parse_mode="markdown",
                    quote=False)
Ejemplo n.º 22
0
def unblackliststicker(update, context):
    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(context.bot, update, chat, user.id)
    if conn:
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        chat_id = update.effective_chat.id
        if chat.type == "private":
            return
        else:
            chat_name = chat.title

    if len(words) > 1:
        text = words[1].replace('https://t.me/addstickers/', '')
        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_stickers(chat_id, trigger.lower())
            if success:
                successful += 1

        if len(to_unblacklist) == 1:
            if successful:
                send_message(
                    update.effective_message,
                    tl(
                        update.effective_message,
                        "Stiker <code>{}</code> dihapus dari daftar hitam di <b>{}</b>!"
                    ).format(html.escape(to_unblacklist[0]), chat_name),
                    parse_mode=ParseMode.HTML)
            else:
                send_message(
                    update.effective_message,
                    tl(update.effective_message,
                       "Ini tidak ada di daftar hitam stiker...!"))

        elif successful == len(to_unblacklist):
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Stiker <code>{}</code> dihapus dari daftar hitam di <b>{}</b>!"
                ).format(successful, chat_name),
                parse_mode=ParseMode.HTML)

        elif not successful:
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Tidak satu pun stiker ini ada, sehingga tidak dapat dihapus."
                ).format(successful,
                         len(to_unblacklist) - successful),
                parse_mode=ParseMode.HTML)

        else:
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Stiker <code>{}</code> dihapus dari daftar hitam. {} Tidak ada, "
                    "jadi tidak dihapus.").format(
                        successful,
                        len(to_unblacklist) - successful),
                parse_mode=ParseMode.HTML)
    elif msg.reply_to_message:
        trigger = msg.reply_to_message.sticker.set_name
        if trigger == None:
            send_message(update.effective_message,
                         tl(update.effective_message, "Stiker tidak valid!"))
            return
        success = sql.rm_from_stickers(chat_id, trigger.lower())

        if success:
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Stiker <code>{}</code> dihapus dari daftar hitam di <b>{}</b>!"
                ).format(trigger, chat_name),
                parse_mode=ParseMode.HTML)
        else:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "{} tidak ada di daftar hitam stiker...!").format(trigger))
    else:
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Beri tahu saya stiker apa yang ingin Anda tambahkan ke daftar hitam stiker."
            ))
Ejemplo n.º 23
0
def blacklist_mode(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    msg = update.effective_message  # type: Optional[Message]
    args = context.args

    conn = connected(context.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,
                tl(update.effective_message,
                   "Anda bisa lakukan command ini pada grup, bukan pada 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() == 'off' or args[0].lower(
        ) == 'nothing' or args[0].lower() == 'no':
            settypeblacklist = tl(update.effective_message, 'di biarkan')
            sql.set_blacklist_strength(chat_id, 0, "0")
        elif args[0].lower() == 'del' or args[0].lower() == 'delete':
            settypeblacklist = tl(update.effective_message,
                                  'di biarkan, pesannya akan dihapus')
            sql.set_blacklist_strength(chat_id, 1, "0")
        elif args[0].lower() == 'warn':
            settypeblacklist = tl(update.effective_message, 'di peringati')
            sql.set_blacklist_strength(chat_id, 2, "0")
        elif args[0].lower() == 'mute':
            settypeblacklist = tl(update.effective_message, 'di bisukan')
            sql.set_blacklist_strength(chat_id, 3, "0")
        elif args[0].lower() == 'kick':
            settypeblacklist = tl(update.effective_message, 'di tendang')
            sql.set_blacklist_strength(chat_id, 4, "0")
        elif args[0].lower() == 'ban':
            settypeblacklist = tl(update.effective_message, 'di blokir')
            sql.set_blacklist_strength(chat_id, 5, "0")
        elif args[0].lower() == 'tban':
            if len(args) == 1:
                teks = tl(
                    update.effective_message,
                    """Sepertinya Anda mencoba menetapkan nilai sementara untuk blacklist, tetapi belum menentukan waktu; gunakan `/blacklistmode tban <timevalue>`.

Contoh nilai waktu: 4m = 4 menit, 3h = 3 jam, 6d = 6 hari, 5w = 5 minggu.""")
                send_message(update.effective_message,
                             teks,
                             parse_mode="markdown")
                return ""
            restime = extract_time(msg, args[1])
            if not restime:
                teks = tl(
                    update.effective_message, """Nilai waktu tidak valid!
Contoh nilai waktu: 4m = 4 menit, 3h = 3 jam, 6d = 6 hari, 5w = 5 minggu.""")
                send_message(update.effective_message,
                             teks,
                             parse_mode="markdown")
                return ""
            settypeblacklist = tl(update.effective_message,
                                  'di blokir sementara selama {}').format(
                                      args[1])
            sql.set_blacklist_strength(chat_id, 6, str(args[1]))
        elif args[0].lower() == 'tmute':
            if len(args) == 1:
                teks = tl(
                    update.effective_message,
                    """Sepertinya Anda mencoba menetapkan nilai sementara untuk blacklist, tetapi belum menentukan waktu; gunakan `/blacklistmode tmute <timevalue>`.

Contoh nilai waktu: 4m = 4 menit, 3h = 3 jam, 6d = 6 hari, 5w = 5 minggu.""")
                send_message(update.effective_message,
                             teks,
                             parse_mode="markdown")
                return ""
            restime = extract_time(msg, args[1])
            if not restime:
                teks = tl(
                    update.effective_message, """Nilai waktu tidak valid!
Contoh nilai waktu: 4m = 4 menit, 3h = 3 jam, 6d = 6 hari, 5w = 5 minggu.""")
                send_message(update.effective_message,
                             teks,
                             parse_mode="markdown")
                return ""
            settypeblacklist = tl(update.effective_message,
                                  'di bisukan sementara selama {}').format(
                                      args[1])
            sql.set_blacklist_strength(chat_id, 7, str(args[1]))
        else:
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Saya hanya mengerti off/del/warn/ban/kick/mute/tban/tmute!"
                ))
            return ""
        if conn:
            text = tl(
                update.effective_message,
                "Mode blacklist diubah, Pengguna akan `{}` pada *{}*!").format(
                    settypeblacklist, chat_name)
        else:
            text = tl(update.effective_message,
                      "Mode blacklist diubah, Pengguna akan `{}`!").format(
                          settypeblacklist)
        send_message(update.effective_message, text, parse_mode="markdown")
        return "<b>{}:</b>\n" \
          "<b>Admin:</b> {}\n" \
          "Changed the blacklist mode. will {}.".format(html.escape(chat.title),
                         mention_html(user.id, user.first_name), settypeblacklist)
    else:
        getmode, getvalue = sql.get_blacklist_setting(chat.id)
        if getmode == 0:
            settypeblacklist = tl(update.effective_message, "tidak aktif")
        elif getmode == 1:
            settypeblacklist = tl(update.effective_message, "hapus")
        elif getmode == 2:
            settypeblacklist = tl(update.effective_message, "warn")
        elif getmode == 3:
            settypeblacklist = tl(update.effective_message, "mute")
        elif getmode == 4:
            settypeblacklist = tl(update.effective_message, "kick")
        elif getmode == 5:
            settypeblacklist = tl(update.effective_message, "ban")
        elif getmode == 6:
            settypeblacklist = tl(
                update.effective_message,
                "banned sementara selama {}").format(getvalue)
        elif getmode == 7:
            settypeblacklist = tl(update.effective_message,
                                  "mute sementara selama {}").format(getvalue)
        if conn:
            text = tl(
                update.effective_message,
                "Mode blacklist saat ini disetel ke *{}* pada *{}*.").format(
                    settypeblacklist, chat_name)
        else:
            text = tl(update.effective_message,
                      "Mode blacklist saat ini disetel ke *{}*.").format(
                          settypeblacklist)
        send_message(update.effective_message,
                     text,
                     parse_mode=ParseMode.MARKDOWN)
    return ""
Ejemplo n.º 24
0
def unblacklist(update, context):
    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(context.bot, update, chat, user.id)
    if conn:
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        chat_id = update.effective_chat.id
        if chat.type == "private":
            return
        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:
                send_message(
                    update.effective_message,
                    tl(
                        update.effective_message,
                        "<code>{}</code> dihapus dari daftar hitam di <b>{}</b>!"
                    ).format(html.escape(to_unblacklist[0]), chat_name),
                    parse_mode=ParseMode.HTML)
            else:
                send_message(update.effective_message,
                             "Ini bukan pemicu daftar hitam...!")

        elif successful == len(to_unblacklist):
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "<code>{}</code> Pemicu dihapus dari daftar hitam di <b>{}</b>!"
                ).format(successful, chat_name),
                parse_mode=ParseMode.HTML)

        elif not successful:
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Tidak satu pun pemicu ini ada, sehingga tidak dapat dihapus."
                ).format(successful,
                         len(to_unblacklist) - successful),
                parse_mode=ParseMode.HTML)

        else:
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Pemicu <code>{}</code> dihapus dari daftar hitam. {} Tidak ada, "
                    "jadi tidak dihapus.").format(
                        successful,
                        len(to_unblacklist) - successful),
                parse_mode=ParseMode.HTML)
    else:
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Beri tahu saya kata-kata apa yang ingin Anda hapus dari daftar hitam."
            ))
Ejemplo n.º 25
0
def set_flood_mode(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    msg = update.effective_message  # type: Optional[Message]
    args = context.args

    conn = connected(context.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,
                tl(update.effective_message,
                   "Anda bisa lakukan command ini pada grup, bukan pada 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 = tl(update.effective_message, 'blokir')
            sql.set_flood_strength(chat_id, 1, "0")
        elif args[0].lower() == 'kick':
            settypeflood = tl(update.effective_message, 'tendang')
            sql.set_flood_strength(chat_id, 2, "0")
        elif args[0].lower() == 'mute':
            settypeflood = tl(update.effective_message, 'bisukan')
            sql.set_flood_strength(chat_id, 3, "0")
        elif args[0].lower() == 'tban':
            if len(args) == 1:
                teks = tl(
                    update.effective_message,
                    """Sepertinya Anda mencoba menetapkan nilai sementara untuk anti-banjir, tetapi belum menentukan waktu; gunakan `/setfloodmode tban <timevalue>`.

Contoh nilai waktu: 4m = 4 menit, 3h = 3 jam, 6d = 6 hari, 5w = 5 minggu.""")
                send_message(update.effective_message,
                             teks,
                             parse_mode="markdown")
                return
            settypeflood = tl(update.effective_message,
                              "blokir sementara selama {}").format(args[1])
            sql.set_flood_strength(chat_id, 4, str(args[1]))
        elif args[0].lower() == 'tmute':
            if len(args) == 1:
                teks = tl(
                    update.effective_message,
                    """Sepertinya Anda mencoba menetapkan nilai sementara untuk anti-banjir, tetapi belum menentukan waktu; gunakan `/setfloodmode tban <timevalue>`.

Contoh nilai waktu: 4m = 4 menit, 3h = 3 jam, 6d = 6 hari, 5w = 5 minggu.""")
                send_message(update.effective_message,
                             teks,
                             parse_mode="markdown")
                return
            settypeflood = tl(update.effective_message,
                              'bisukan sementara selama {}').format(args[1])
            sql.set_flood_strength(chat_id, 5, str(args[1]))
        else:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Saya hanya mengerti ban/kick/mute/tban/tmute!"))
            return
        if conn:
            text = tl(
                update.effective_message,
                "Terlalu banyak mengirim pesan sekarang akan menghasilkan `{}` pada *{}*!"
            ).format(settypeflood, chat_name)
        else:
            text = tl(
                update.effective_message,
                "Terlalu banyak mengirim pesan sekarang akan menghasilkan `{}`!"
            ).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 = tl(update.effective_message, 'blokir')
        elif getmode == 2:
            settypeflood = tl(update.effective_message, 'tendang')
        elif getmode == 3:
            settypeflood = tl(update.effective_message, 'bisukan')
        elif getmode == 4:
            settypeflood = tl(update.effective_message,
                              'blokir sementara selama {}').format(getvalue)
        elif getmode == 5:
            settypeflood = tl(update.effective_message,
                              'bisukan sementara selama {}').format(getvalue)
        if conn:
            text = tl(
                update.effective_message,
                "Jika member mengirim pesan beruntun, maka dia akan *di {}* pada *{}*."
            ).format(settypeflood, chat_name)
        else:
            text = tl(
                update.effective_message,
                "Jika member mengirim pesan beruntun, maka dia akan *di {}*."
            ).format(settypeflood)
        send_message(update.effective_message,
                     text,
                     parse_mode=ParseMode.MARKDOWN)
    return ""
Ejemplo n.º 26
0
def set_flood(update, context) -> str:
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    args = context.args

    conn = connected(context.bot, update, chat, user.id, need_admin=True)
    if conn:
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if update.effective_message.chat.type == "private":
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Anda bisa lakukan command ini pada grup, bukan pada PM"))
            return ""
        chat_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title

    if len(args) >= 1:
        val = args[0].lower()
        if val == "off" or val == "no" or val == "0":
            sql.set_flood(chat_id, 0)
            if conn:
                text = tl(
                    update.effective_message,
                    "Antiflood telah dinonaktifkan di *{}*.").format(chat_name)
            else:
                text = tl(update.effective_message,
                          "Antiflood telah dinonaktifkan.")
            send_message(update.effective_message, text, parse_mode="markdown")

        elif val.isdigit():
            amount = int(val)
            if amount <= 0:
                sql.set_flood(chat_id, 0)
                if conn:
                    text = tl(update.effective_message,
                              "Antiflood telah dinonaktifkan di *{}*.").format(
                                  chat_name)
                else:
                    text = tl(update.effective_message,
                              "Antiflood telah dinonaktifkan.")
                return "<b>{}:</b>" \
                       "\n#SETFLOOD" \
                       "\n<b>Admin:</b> {}" \
                       "\nDisable antiflood.".format(html.escape(chat_name), mention_html(user.id, user.first_name))

            elif amount < 3:
                send_message(
                    update.effective_message,
                    tl(
                        update.effective_message,
                        "Antiflood harus baik 0 (dinonaktifkan), atau nomor lebih besar dari 3!"
                    ))
                return ""

            else:
                sql.set_flood(chat_id, amount)
                if conn:
                    text = tl(
                        update.effective_message,
                        "Antiflood telah diperbarui dan diatur menjadi *{}* pada *{}*"
                    ).format(amount, chat_name)
                else:
                    text = tl(
                        update.effective_message,
                        "Antiflood telah diperbarui dan diatur menjadi *{}*"
                    ).format(amount)
                send_message(update.effective_message,
                             text,
                             parse_mode="markdown")
                return "<b>{}:</b>" \
                       "\n#SETFLOOD" \
                       "\n<b>Admin:</b> {}" \
                       "\nSet antiflood to <code>{}</code>.".format(html.escape(chat_name),
                                                                    mention_html(user.id, user.first_name), amount)

        else:
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Argumen tidak dikenal - harap gunakan angka, 'off', atau 'no'."
                ))
    else:
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Gunakan `/setflood nomor` untuk menyetel anti pesan beruntun.\nAtau gunakan `/setflood off` untuk menonaktifkan anti pesan beruntun."
            ),
            parse_mode="markdown")
    return ""
Ejemplo n.º 27
0
def send_rules(update, chat_id, from_pm=False):
    bot = dispatcher.bot
    user = update.effective_user  # type: Optional[User]
    try:
        chat = bot.get_chat(chat_id)
    except BadRequest as excp:
        if excp.message == "Chat not found" and from_pm:
            bot.send_message(
                user.id,
                tl(
                    update.effective_message,
                    "Pintasan aturan untuk obrolan ini belum diatur dengan benar! Mintalah admin untuk "
                    "perbaiki ini."))
            return
        else:
            raise

    conn = connected(bot, update, chat, user.id, need_admin=False)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title

    rules, buttons = button_markdown_parser(sql.get_rules(chat_id))
    try:
        text = tl(update.effective_message,
                  "Peraturan untuk *{}* adalah:\n\n{}").format(
                      escape_markdown(chat.title), rules)
    except TypeError:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda bisa lakukan command ini pada grup, bukan pada PM"))
        return ""

    is_private = sql.get_private_rules(chat_id)

    if from_pm and rules:
        bot.send_message(user.id,
                         text,
                         parse_mode=ParseMode.MARKDOWN,
                         reply_markup=InlineKeyboardMarkup(
                             build_keyboard_alternate(buttons)))
    elif from_pm:
        if conn:
            bot.send_message(
                user.id,
                tl(
                    update.effective_message,
                    "Admin grup belum menetapkan aturan apa pun untuk *{}*. "
                    "Bukan berarti obrolan ini tanpa hukum...!").format(
                        chat_name),
                parse_mode="markdown")
        else:
            bot.send_message(
                user.id,
                tl(
                    update.effective_message,
                    "Admin grup belum menetapkan aturan apa pun untuk obrolan ini. "
                    "Bukan berarti obrolan ini tanpa hukum...!"))
    elif rules:
        if (update.effective_message.chat.type == "private"
                or not is_private) and rules:
            if not is_private:
                send_message(update.effective_message,
                             text,
                             parse_mode=ParseMode.MARKDOWN,
                             reply_markup=InlineKeyboardMarkup(
                                 build_keyboard_alternate(buttons)))
            else:
                bot.send_message(user.id,
                                 text,
                                 parse_mode=ParseMode.MARKDOWN,
                                 reply_markup=InlineKeyboardMarkup(
                                     build_keyboard_alternate(buttons)))
        else:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Hubungi saya di PM untuk mendapatkan aturan grup ini"),
                reply_markup=InlineKeyboardMarkup([[
                    InlineKeyboardButton(text=tl(update.effective_message,
                                                 "Peraturan"),
                                         url="t.me/{}?start={}".format(
                                             bot.username, chat_id))
                ]]))
    else:
        if conn:
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Admin grup belum menetapkan aturan apa pun untuk *{}*. "
                    "Bukan berarti obrolan ini tanpa hukum...!").format(
                        chat_name),
                parse_mode="markdown")
        else:
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Admin grup belum menetapkan aturan apa pun untuk obrolan ini. "
                    "Bukan berarti obrolan ini tanpa hukum...!"))
Ejemplo n.º 28
0
def unlock(update, context) -> str:
    args = context.args
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    if is_user_admin(chat, message.from_user.id):
        if len(args) >= 1:
            ltype = args[0].lower()
            if ltype in LOCK_TYPES:
                # Connection check
                conn = connected(context.bot,
                                 update,
                                 chat,
                                 user.id,
                                 need_admin=True)
                if conn:
                    chat = dispatcher.bot.getChat(conn)
                    chat_id = conn
                    chat_name = chat.title
                    text = tl(
                        update.effective_message,
                        "Tidak terkunci *{}* untuk semua orang pada *{}*!"
                    ).format(ltype, chat_name)
                else:
                    if update.effective_message.chat.type == "private":
                        send_message(
                            update.effective_message,
                            tl(
                                update.effective_message,
                                "Anda bisa lakukan command ini pada grup, bukan pada PM"
                            ))
                        return ""
                    chat = update.effective_chat
                    chat_id = update.effective_chat.id
                    chat_name = update.effective_message.chat.title
                    text = tl(
                        update.effective_message,
                        "Tidak terkunci *{}* untuk semua orang!").format(ltype)
                sql.update_lock(chat.id, ltype, locked=False)
                send_message(update.effective_message,
                             text,
                             parse_mode="markdown")
                return "<b>{}:</b>" \
                       "\n#UNLOCK" \
                       "\n<b>Admin:</b> {}" \
                       "\nUnlocked <code>{}</code>.".format(html.escape(chat.title),
                                                            mention_html(user.id, user.first_name), ltype)

            elif ltype in UNLOCK_CHAT_RESTRICTION:
                # Connection check
                conn = connected(context.bot,
                                 update,
                                 chat,
                                 user.id,
                                 need_admin=True)
                if conn:
                    chat = dispatcher.bot.getChat(conn)
                    chat_id = conn
                    chat_name = chat.title
                    text = tl(
                        update.effective_message,
                        "Izin tidak terkunci *{}* untuk semua orang pada *{}*!"
                    ).format(ltype, chat_name)
                else:
                    if update.effective_message.chat.type == "private":
                        send_message(
                            update.effective_message,
                            tl(
                                update.effective_message,
                                "Anda bisa lakukan command ini pada grup, bukan pada PM"
                            ))
                        return ""
                    chat = update.effective_chat
                    chat_id = update.effective_chat.id
                    chat_name = update.effective_message.chat.title
                    text = tl(
                        update.effective_message,
                        "Izin tidak terkunci *{}* untuk semua orang!").format(
                            ltype)

                current_permission = context.bot.getChat(chat_id).permissions
                context.bot.set_chat_permissions(
                    chat_id=chat_id,
                    permissions=get_permission_list(
                        eval(str(current_permission)),
                        UNLOCK_CHAT_RESTRICTION[ltype.lower()]))

                send_message(update.effective_message,
                             text,
                             parse_mode="markdown")

                return "<b>{}:</b>" \
                       "\n#UNLOCK" \
                       "\n<b>Admin:</b> {}" \
                       "\nUnlocked <code>{}</code>.".format(html.escape(chat.title),
                                                            mention_html(user.id, user.first_name), ltype)
            else:
                send_message(
                    update.effective_message,
                    tl(
                        update.effective_message,
                        "Apa yang Anda coba untuk membuka kunci...? Coba /locktypes untuk daftar kunci yang dapat dikunci"
                    ))

        else:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Apa yang Anda coba untuk buka kunci...?"))

    return ""
Ejemplo n.º 29
0
def unmute(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    args = context.args

    user_id = extract_user(message, args)
    if not user_id or user_id == "error":
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Anda harus memberi saya nama pengguna untuk menyuarakan, atau membalas seseorang untuk disuarakan."
            ))
        return ""

    conn = connected(context.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
        text = tl(update.effective_message,
                  "Pengguna ini sudah bisa untuk berbicara pada *{}*.").format(
                      chat_name)
        text2 = tl(update.effective_message,
                   "Dia telah disuarakan pada *{}*.").format(chat_name)
    else:
        if update.effective_message.chat.type == "private":
            update.effective_send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Anda bisa lakukan command ini pada grup, bukan pada PM"))
            return ""
        chat = update.effective_chat
        chat_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title
        text = tl(update.effective_message,
                  "Pengguna ini sudah bisa untuk berbicara.")
        text2 = "Dia telah disuarakan."

    check = context.bot.getChatMember(chat.id, user.id)
    if check['can_restrict_members'] == False:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda tidak punya hak untuk membatasi seseorang."))
        return ""

    member = chat.get_member(int(user_id))

    if member:
        if is_user_admin(chat, user_id, member=member):
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Dia adalah admin, apa yang Anda harapkan kepada saya?"))
            return ""

        elif 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:
                send_message(update.effective_message,
                             text,
                             parse_mode="markdown")
                return ""
            else:
                context.bot.restrict_chat_member(
                    chat.id,
                    int(user_id),
                    permissions=ChatPermissions(
                        can_send_messages=True,
                        can_send_media_messages=True,
                        can_send_other_messages=True,
                        can_add_web_page_previews=True))
                send_message(update.effective_message,
                             text2,
                             parse_mode="markdown")
                return "<b>{}:</b>" \
                       "\n#UNMUTE" \
                       "\n<b>Admin:</b> {}" \
                       "\n<b>User:</b> {}".format(html.escape(chat.title),
                                                  mention_html(user.id, user.first_name),
                                                  mention_html(member.user.id, member.user.first_name))
    else:
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Pengguna ini bahkan tidak dalam obrolan, menyuarakannya tidak akan membuat mereka berbicara lebih dari "
                "yang sudah mereka lakukan!"))

    return ""
Ejemplo n.º 30
0
def filters(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    msg = update.effective_message  # type: Optional[Message]
    args = msg.text.split(
        None,
        1)  # use python's maxsplit to separate Cmd, keyword, and reply_text

    conn = connected(context.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 = tl(update.effective_message, "catatan lokal")
        else:
            chat_name = chat.title

    if not msg.reply_to_message and len(args) < 2:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda harus memberi nama untuk filter ini!"))
        return

    if msg.reply_to_message:
        if len(args) < 2:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Anda harus memberi nama untuk filter ini!"))
            return
        else:
            keyword = args[1]
    else:
        extracted = split_quotes(args[1])
        if len(extracted) < 1:
            return
        # set trigger -> lower, so as to avoid adding duplicate filters with different cases
        keyword = extracted[0].lower()

    # Add the filter
    # Note: perhaps handlers can be removed somehow using sql.get_chat_filters
    for handler in dispatcher.handlers.get(HANDLER_GROUP, []):
        if handler.filters == (keyword, chat_id):
            dispatcher.remove_handler(handler, HANDLER_GROUP)

    text, file_type, file_id = get_filter_type(msg)
    if not msg.reply_to_message and len(extracted) >= 2:
        offset = len(extracted[1]) - len(
            msg.text)  # set correct offset relative to command + notename
        text, buttons = button_markdown_parser(extracted[1],
                                               entities=msg.parse_entities(),
                                               offset=offset)
        text = text.strip()
        if not text:
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Tidak ada pesan catatan - Anda tidak bisa HANYA menekan tombol, Anda perlu pesan untuk melakukannya!"
                ))
            return

    elif msg.reply_to_message and len(args) >= 2:
        if msg.reply_to_message.text:
            text_to_parsing = msg.reply_to_message.text
        elif msg.reply_to_message.caption:
            text_to_parsing = msg.reply_to_message.caption
        else:
            text_to_parsing = ""
        offset = len(text_to_parsing
                     )  # set correct offset relative to command + notename
        text, buttons = button_markdown_parser(text_to_parsing,
                                               entities=msg.parse_entities(),
                                               offset=offset)
        text = text.strip()

    elif not text and not file_type:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda harus memberi nama untuk filter ini!"))
        return

    elif msg.reply_to_message:
        if msg.reply_to_message.text:
            text_to_parsing = msg.reply_to_message.text
        elif msg.reply_to_message.caption:
            text_to_parsing = msg.reply_to_message.caption
        else:
            text_to_parsing = ""
        offset = len(text_to_parsing
                     )  # set correct offset relative to command + notename
        text, buttons = button_markdown_parser(text_to_parsing,
                                               entities=msg.parse_entities(),
                                               offset=offset)
        text = text.strip()
        if (msg.reply_to_message.text
                or msg.reply_to_message.caption) and not text:
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Tidak ada pesan catatan - Anda tidak bisa HANYA menekan tombol, Anda perlu pesan untuk melakukannya!"
                ))
            return

    else:
        send_message(update.effective_message,
                     tl(update.effective_message, "Invalid filter!"))
        return

    sql.new_add_filter(chat_id, keyword, text, file_type, file_id, buttons)
    # This is an old method
    # sql.add_filter(chat_id, keyword, content, is_sticker, is_document, is_image, is_audio, is_voice, is_video, buttons)

    send_message(update.effective_message,
                 tl(update.effective_message,
                    "Handler '{}' ditambahkan di *{}*!").format(
                        keyword, chat_name),
                 parse_mode=telegram.ParseMode.MARKDOWN)
    raise DispatcherHandlerStop