Esempio n. 1
0
def ban(bot: Bot, update: Update, args: List[str]) -> str:
    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]

    spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message)
    if spam == True:
        return

    user_id, reason = extract_user_and_text(message, args)

    conn = connected(bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if update.effective_message.chat.type == "private":
            send_message(update.effective_message, 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 = bot.getChatMember(chat_id, 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 = 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 == 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:
            bot.kickChatMember(chat_id, user_id)
            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:
                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 ""
Esempio n. 2
0
def kick(bot: Bot, update: Update, args: List[str]) -> str:
    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]

    spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message)
    if spam == True:
        return

    user_id, reason = extract_user_and_text(message, args)

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

    conn = connected(bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if update.effective_message.chat.type == "private":
            send_message(update.effective_message, 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 = bot.getChatMember(chat_id, 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 = 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 == 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 == bot.id:
        send_message(update.effective_message, tl(update.effective_message, "Yahhh aku tidak akan melakukan itu 😝"))
        return ""

    check = 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 = 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:
            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:
                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 ""
Esempio n. 3
0
def save(bot: Bot, update: Update):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    conn = connected(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 = "catatan lokal"
        else:
            chat_name = chat.title

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

    checktext = msg.text.split()
    if msg.reply_to_message:
        if len(checktext) <= 1:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Anda harus memberi nama untuk catatan ini!"))
            return
    else:
        if len(checktext) <= 2:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Anda harus memberi nama untuk catatan ini!"))
            return

    note_name, text, data_type, content, buttons = get_note_type(msg)

    if data_type is None:
        send_message(update.effective_message,
                     tl(update.effective_message, "Tidak ada catatan!"))
        return

    if len(text.strip()) == 0:
        text = "`" + note_name + "`"

    sql.add_note_to_db(chat_id,
                       note_name,
                       text,
                       data_type,
                       buttons=buttons,
                       file=content)
    if conn:
        savedtext = tl(
            update.effective_message,
            "Ok, catatan `{note_name}` disimpan di *{chat_name}*.").format(
                note_name=note_name, chat_name=chat_name)
    else:
        savedtext = tl(
            update.effective_message,
            "Ok, catatan `{note_name}` disimpan.").format(note_name=note_name)
    try:
        send_message(update.effective_message,
                     savedtext,
                     parse_mode=ParseMode.MARKDOWN)
    except BadRequest:
        if conn:
            savedtext = tl(
                update.effective_message,
                "Ok, catatan <code>{note_name}</code> disimpan di <b>{chat_name}</b>."
            ).format(note_name=note_name, chat_name=chat_name)
        else:
            savedtext = tl(
                update.effective_message,
                "Ok, catatan <code>{note_name}</code> disimpan.").format(
                    note_name=note_name)
        send_message(update.effective_message,
                     savedtext,
                     parse_mode=ParseMode.HTML)
Esempio n. 4
0
def temp_ban(bot: Bot, update: Update, args: List[str]) -> str:
    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]

    spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message)
    if spam == True:
        return

    user_id, reason = extract_user_and_text(message, args)

    conn = connected(bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if update.effective_message.chat.type == "private":
            send_message(update.effective_message, 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 = bot.getChatMember(chat_id, 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 = 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 == 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:
            bot.kickChatMember(chat_id, user_id, until_date=bantime)
            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)
            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 ""
Esempio n. 5
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...!"))
Esempio n. 6
0
def blacklist_mode(bot: Bot, update: Update, args: List[str]):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    msg = update.effective_message  # type: Optional[Message]

    conn = connected(bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if update.effective_message.chat.type == "private":
            send_message(
                update.effective_message,
                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 ""
Esempio n. 7
0
def unlock(bot: Bot, update: Update, args: List[str]) -> str:
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    if is_user_admin(chat, message.from_user.id):
        if len(args) >= 1:
            if args[0] in LOCK_TYPES:
                # Connection check
                conn = connected(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(args[0], 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(
                                  args[0])
                sql.update_lock(chat.id, args[0], 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), args[0])

            elif args[0] in RESTRICTION_TYPES:
                # Connection check
                conn = connected(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(args[0], 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(
                                  args[0])
                sql.update_restriction(chat.id, args[0], locked=False)
                """
                members = users_sql.get_chat_members(chat.id)
                if args[0] == "messages":
                    unrestr_members(bot, chat.id, members, media=False, other=False, previews=False)

                elif args[0] == "media":
                    unrestr_members(bot, chat.id, members, other=False, previews=False)

                elif args[0] == "other":
                    unrestr_members(bot, chat.id, members, previews=False)

                elif args[0] == "previews":
                    unrestr_members(bot, chat.id, members)

                elif args[0] == "all":
                    unrestr_members(bot, chat.id, members, True, True, True, True)
                """
                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), args[0])
            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 ""
Esempio n. 8
0
def set_flood(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return

    conn = connected(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 ""
Esempio n. 9
0
def list_notes(bot: Bot, update: Update):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    conn = connected(bot, update, chat, user.id, need_admin=False)
    if conn:
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
        msg = tl(update.effective_message,
                 "*Catatan di {}:*\n").format(chat_name)
    else:
        chat_id = update.effective_chat.id
        if chat.type == "private":
            chat_name = ""
            msg = tl(update.effective_message, "*Catatan lokal:*\n")
        else:
            chat_name = chat.title
            msg = tl(update.effective_message,
                     "*Catatan di {}:*\n").format(chat_name)

    note_list = sql.get_all_chat_notes(chat_id)

    for note in note_list:
        note_name = " - `{}`\n".format(note.name)
        if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH:
            send_message(update.effective_message,
                         msg,
                         parse_mode=ParseMode.MARKDOWN)
            msg = ""
        msg += note_name

    if msg == tl(update.effective_message,
                 "*Catatan di {}:*\n").format(chat_name) or msg == tl(
                     update.effective_message, "*Catatan lokal:*\n"):
        if conn:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Tidak ada catatan di obrolan *{}*!").format(chat_name),
                parse_mode="markdown")
        else:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Tidak ada catatan di obrolan ini!"))

    elif len(msg) != 0:
        msg += tl(
            update.effective_message,
            "\nAnda dapat mengambil catatan ini dengan menggunakan `/get notename`, atau `#notename`"
        )
        try:
            send_message(update.effective_message,
                         msg,
                         parse_mode=ParseMode.MARKDOWN)
        except BadRequest:
            if chat.type == "private":
                chat_name = ""
                msg = tl(update.effective_message, "<b>Catatan lokal:</b>\n")
            else:
                chat_name = chat.title
                msg = tl(update.effective_message,
                         "<b>Catatan di {}:</b>\n").format(chat_name)
            for note in note_list:
                note_name = " - <code>{}</code>\n".format(note.name)
                if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH:
                    send_message(update.effective_message,
                                 msg,
                                 parse_mode=ParseMode.MARKDOWN)
                    msg = ""
                msg += note_name
            msg += tl(
                update.effective_message,
                "\nAnda dapat mengambil catatan ini dengan menggunakan <code>/get notename</code>, atau <code>#notename</code>"
            )
            send_message(update.effective_message,
                         msg,
                         parse_mode=ParseMode.HTML)
Esempio n. 10
0
def lock(bot: Bot, update: Update, args: List[str]) -> str:
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    if can_delete(chat,
                  bot.id) or update.effective_message.chat.type == "private":
        if len(args) >= 1:
            if args[0] in LOCK_TYPES:
                # Connection check
                conn = connected(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,
                        "Terkunci *{}* pesan untuk semua non-admin pada *{}*!"
                    ).format(args[0], 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,
                        "Terkunci *{}* pesan untuk semua non-admin!").format(
                            args[0])
                sql.update_lock(chat.id, args[0], locked=True)
                send_message(update.effective_message,
                             text,
                             parse_mode="markdown")

                return "<b>{}:</b>" \
                       "\n#LOCK" \
                       "\n<b>Admin:</b> {}" \
                       "\nLocked <code>{}</code>.".format(html.escape(chat.title),
                                                          mention_html(user.id, user.first_name), args[0])

            elif args[0] in RESTRICTION_TYPES:
                # Connection check
                conn = connected(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,
                        "Terkunci *{}* pesan untuk semua non-admin pada *{}*!"
                    ).format(args[0], 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,
                        "Terkunci *{}* pesan untuk semua non-admin!").format(
                            args[0])
                sql.update_restriction(chat.id, args[0], locked=True)
                if args[0] == "previews":
                    members = users_sql.get_chat_members(str(chat.id))
                    restr_members(bot,
                                  chat.id,
                                  members,
                                  messages=True,
                                  media=True,
                                  other=True)

                send_message(update.effective_message,
                             text,
                             parse_mode="markdown")
                return "<b>{}:</b>" \
                       "\n#LOCK" \
                       "\n<b>Admin:</b> {}" \
                       "\nLocked <code>{}</code>.".format(html.escape(chat.title),
                                                          mention_html(user.id, user.first_name), args[0])

            else:
                send_message(
                    update.effective_message,
                    tl(
                        update.effective_message,
                        "Apa yang Anda coba untuk kunci...? Coba /locktypes untuk daftar kunci yang dapat dikunci"
                    ))
        else:
            send_message(
                update.effective_message,
                tl(update.effective_message, "Apa yang Anda ingin kunci...?"))

    else:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Saya bukan admin, atau tidak punya hak menghapus."))

    return ""
Esempio n. 11
0
def private_note(bot: Bot, update: Update, args: List[str]):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    conn = connected(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"):
            if len(args) >= 2:
                if args[1] == "del":
                    sql.private_note(str(chat_id), True, True)
                    send_message(
                        update.effective_message,
                        tl(
                            update.effective_message,
                            "Private Note di *aktifkan*, ketika pengguna mengambil catatan, pesan catatan akan dikirim ke PM dan pesan pengguna akan segera di hapus."
                        ),
                        parse_mode="markdown")
                else:
                    sql.private_note(str(chat_id), True, False)
                    send_message(
                        update.effective_message,
                        tl(
                            update.effective_message,
                            "Private Note di *aktifkan*, ketika pengguna mengambil catatan, pesan catatan akan dikirim ke PM."
                        ),
                        parse_mode="markdown")
            else:
                sql.private_note(str(chat_id), True, False)
                send_message(
                    update.effective_message,
                    tl(
                        update.effective_message,
                        "Private Note di *aktifkan*, ketika pengguna mengambil catatan, pesan catatan akan dikirim ke PM."
                    ),
                    parse_mode="markdown")
        elif args[0] in ("no", "off"):
            sql.private_note(str(chat_id), False, False)
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Private Note di *non-aktifkan*, pesan catatan 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, is_delete = sql.get_private_note(chat_id)
        print(is_private, is_delete)
        send_message(update.effective_message,
                     tl(update.effective_message,
                        "Pengaturan Private Note di {}: *{}*{}").format(
                            chat_name, "Enabled" if is_private else "Disabled",
                            " - *Hash will be deleted*" if is_delete else ""),
                     parse_mode="markdown")
Esempio n. 12
0
def get(bot, update, notename, show_none=True, no_format=False):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    conn = connected(bot, update, chat, user.id, need_admin=False)
    if conn:
        chat_id = conn
        send_id = user.id
    else:
        chat_id = update.effective_chat.id
        send_id = chat_id

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

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

        if note.is_reply:
            if MESSAGE_DUMP:
                try:
                    bot.forward_message(chat_id=chat_id,
                                        from_chat_id=MESSAGE_DUMP,
                                        message_id=note.value)
                except BadRequest as excp:
                    if excp.message == "Message to forward not found":
                        send_message(
                            update.effective_message,
                            tl(
                                update.effective_message,
                                "Pesan ini tampaknya telah hilang - saya akan menghapusnya "
                                "dari daftar catatan Anda."))
                        sql.rm_note(chat_id, notename)
                    else:
                        raise
            else:
                try:
                    bot.forward_message(chat_id=chat_id,
                                        from_chat_id=chat_id,
                                        message_id=note.value)
                except BadRequest as excp:
                    if excp.message == "Message to forward not found":
                        send_message(
                            update.effective_message,
                            tl(
                                update.effective_message,
                                "Sepertinya pengirim asli dari catatan ini telah dihapus "
                                "pesan mereka - maaf! Dapatkan admin bot Anda untuk mulai menggunakan "
                                "pesan dump untuk menghindari ini. Saya akan menghapus catatan ini dari "
                                "catatan tersimpan Anda."))
                        sql.rm_note(chat_id, notename)
                    else:
                        raise
        else:
            text = note.value
            keyb = []
            parseMode = ParseMode.MARKDOWN
            buttons = sql.get_buttons(chat_id, notename)
            if no_format:
                parseMode = None
                text += revert_buttons(buttons)
            else:
                keyb = build_keyboard(buttons)

            keyboard = InlineKeyboardMarkup(keyb)

            try:
                is_private, is_delete = sql.get_private_note(chat.id)
                if note.msgtype in (sql.Types.BUTTON_TEXT, sql.Types.TEXT):
                    try:
                        if is_delete:
                            update.effective_message.delete()
                        if is_private:
                            bot.send_message(user.id,
                                             text,
                                             parse_mode=parseMode,
                                             disable_web_page_preview=True,
                                             reply_markup=keyboard)
                        else:
                            bot.send_message(send_id,
                                             text,
                                             reply_to_message_id=reply_id,
                                             parse_mode=parseMode,
                                             disable_web_page_preview=True,
                                             reply_markup=keyboard)
                    except BadRequest as excp:
                        if excp.message == "Wrong http url":
                            failtext = tl(
                                update.effective_message,
                                "Kesalahan: URL pada tombol tidak valid! Harap perbaruhi catatan ini."
                            )
                            failtext += "\n\n```\n{}```".format(
                                note.value + revert_buttons(buttons))
                            send_message(update.effective_message,
                                         failtext,
                                         parse_mode="markdown")
                        elif excp.message == "Button_url_invalid":
                            failtext = tl(
                                update.effective_message,
                                "Kesalahan: URL pada tombol tidak valid! Harap perbaruhi catatan ini."
                            )
                            failtext += "\n\n```\n{}```".format(
                                note.value + revert_buttons(buttons))
                            send_message(update.effective_message,
                                         failtext,
                                         parse_mode="markdown")
                        elif excp.message == "Message can't be deleted":
                            pass
                        elif excp.message == "Have no rights to send a message":
                            pass
                    except Unauthorized as excp:
                        send_message(
                            update.effective_message,
                            tl(
                                update.effective_message,
                                "Hubungi saya di PM dulu untuk mendapatkan catatan ini."
                            ),
                            parse_mode="markdown")
                        pass
                else:
                    try:
                        if is_delete:
                            update.effective_message.delete()
                        if is_private:
                            ENUM_FUNC_MAP[note.msgtype](
                                user.id,
                                note.file,
                                caption=text,
                                parse_mode=parseMode,
                                disable_web_page_preview=True,
                                reply_markup=keyboard)
                        else:
                            ENUM_FUNC_MAP[note.msgtype](
                                send_id,
                                note.file,
                                caption=text,
                                reply_to_message_id=reply_id,
                                parse_mode=parseMode,
                                disable_web_page_preview=True,
                                reply_markup=keyboard)
                    except BadRequest as excp:
                        if excp.message == "Message can't be deleted":
                            pass
                        elif excp.message == "Have no rights to send a message":
                            pass
                    except Unauthorized as excp:
                        send_message(
                            update.effective_message,
                            tl(
                                update.effective_message,
                                "Hubungi saya di PM dulu untuk mendapatkan catatan ini."
                            ),
                            parse_mode="markdown")
                        pass

            except BadRequest as excp:
                if excp.message == "Entity_mention_user_invalid":
                    send_message(
                        update.effective_message,
                        tl(
                            update.effective_message,
                            "Sepertinya Anda mencoba menyebutkan seseorang yang belum pernah saya lihat sebelumnya. "
                            "Jika kamu benar-benar ingin menyebutkannya, meneruskan salah satu pesan mereka kepada saya, "
                            "dan saya akan dapat untuk menandai mereka!"))
                elif FILE_MATCHER.match(note.value):
                    send_message(
                        update.effective_message,
                        tl(
                            update.effective_message,
                            "Catatan ini adalah file yang salah diimpor dari bot lain - saya tidak bisa menggunakan "
                            "ini. Jika Anda benar-benar membutuhkannya, Anda harus menyimpannya lagi. "
                            "Sementara itu, saya akan menghapusnya dari daftar catatan Anda."
                        ))
                    sql.rm_note(chat_id, notename)
                else:
                    send_message(
                        update.effective_message,
                        tl(
                            update.effective_message,
                            "Catatan ini tidak dapat dikirim karena formatnya salah."
                        ))
                    LOGGER.exception(
                        "Tidak dapat menguraikan pesan #%s di obrolan %s",
                        notename, str(chat_id))
                    LOGGER.warning("Pesan itu: %s", str(note.value))
        return
    elif show_none:
        send_message(update.effective_message,
                     tl(update.effective_message, "Catatan ini tidak ada"))
Esempio n. 13
0
def clear(bot: Bot, update: Update, args: List[str]):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    conn = connected(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 = "local notes"
        else:
            chat_name = chat.title

    if len(args) >= 1:
        catatan = []
        catatangagal = []
        for x in range(len(args)):
            notename = args[x]
            if sql.rm_note(chat_id, notename):
                catatan.append(notename)
            else:
                catatangagal.append(notename)
        if len(catatan) >= 1 and len(catatangagal) == 0:
            if conn:
                rtext = tl(
                    update.effective_message,
                    "Catatan di *{chat_name}* untuk `{note_name}` dihapus 😁"
                ).format(chat_name=chat_name, note_name=", ".join(catatan))
            else:
                rtext = tl(update.effective_message,
                           "Catatan `{note_name}` dihapus 😁").format(
                               note_name=", ".join(catatan))
            try:
                send_message(update.effective_message,
                             rtext,
                             parse_mode=ParseMode.MARKDOWN)
            except BadRequest:
                if conn:
                    rtext = tl(
                        update.effective_message,
                        "Catatan di <b>{chat_name}</b> untuk <code>{note_name}</code> dihapus 😁"
                    ).format(chat_name=chat_name, note_name=", ".join(catatan))
                else:
                    rtext = tl(
                        update.effective_message,
                        "Catatan <code>{note_name}</code> dihapus 😁").format(
                            note_name=", ".join(catatan))
                send_message(update.effective_message,
                             rtext,
                             parse_mode=ParseMode.HTML)
        elif len(catatangagal) >= 0 and len(catatan) == 0:
            if conn:
                rtext = tl(
                    update.effective_message,
                    "Catatan di *{chat_name}* untuk `{fnote_name}` gagal dihapus!"
                ).format(chat_name=chat_name,
                         fnote_name=", ".join(catatangagal))
            else:
                rtext = tl(update.effective_message,
                           "Catatan `{fnote_name}` gagal dihapus!").format(
                               fnote_name=", ".join(catatangagal))
            try:
                send_message(update.effective_message,
                             rtext,
                             parse_mode=ParseMode.MARKDOWN)
            except BadRequest:
                if conn:
                    rtext = tl(
                        update.effective_message,
                        "Catatan di <b>{chat_name}</b> untuk <code>{fnote_name}</code> gagal dihapus!"
                    ).format(chat_name=chat_name,
                             fnote_name=", ".join(catatangagal))
                else:
                    rtext = tl(
                        update.effective_message,
                        "Catatan <code>{fnote_name}</code> gagal dihapus!"
                    ).format(fnote_name=", ".join(catatangagal))
                send_message(update.effective_message,
                             tl(update.effective_message, rtext),
                             parse_mode=ParseMode.HTML)
        else:
            if conn:
                rtext = tl(
                    update.effective_message,
                    "Catatan di *{chat_name}* untuk `{note_name}` dihapus 😁\nCatatan `{fnote_name}` gagal dihapus!"
                ).format(chat_name=chat_name,
                         note_name=", ".join(catatan),
                         fnote_name=", ".join(catatangagal))
            else:
                rtext = tl(
                    update.effective_message,
                    "Catatan `{note_name}` dihapus 😁\nCatatan `{fnote_name}` gagal dihapus!"
                ).format(note_name=", ".join(catatan),
                         fnote_name=", ".join(catatangagal))
            try:
                send_message(update.effective_message,
                             rtext,
                             parse_mode=ParseMode.MARKDOWN)
            except BadRequest:
                if conn:
                    rtext = tl(
                        update.effective_message,
                        "Catatan di <b>{chat_name}</b> untuk <code>{note_name}</code> dihapus 😁\nCatatan <code>{fnote_name}</code> gagal dihapus!"
                    ).format(chat_name=chat_name,
                             note_name=", ".join(catatan),
                             fnote_name=", ".join(catatangagal))
                else:
                    rtext = tl(
                        update.effective_message,
                        "Catatan <code>{note_name}</code> dihapus 😁\nCatatan <code>{fnote_name}</code> gagal dihapus!"
                    ).format(note_name=", ".join(catatan),
                             fnote_name=", ".join(catatangagal))
                send_message(update.effective_message,
                             tl(update.effective_message, rtext),
                             parse_mode=ParseMode.HTML)

    else:
        send_message(update.effective_message,
                     tl(update.effective_message, "Apa yang ingin dihapus?"))
Esempio n. 14
0
def unban(bot: Bot, update: Update, args: List[str]) -> str:
    message = update.effective_message  # type: Optional[Message]
    user = update.effective_user  # type: Optional[User]
    chat = update.effective_chat  # type: Optional[Chat]

    spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message)
    if spam == True:
        return

    user_id, reason = extract_user_and_text(message, args)

    conn = connected(bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if update.effective_message.chat.type == "private":
            send_message(update.effective_message, 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 = bot.getChatMember(chat_id, 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 = 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 == 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 = 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:
        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
Esempio n. 15
0
def lock_warns(bot: Bot, update: Update, args: List[str]):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user

    # Connection check
    conn = connected(bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = 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_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title

    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)
Esempio n. 16
0
def set_flood_mode(bot: Bot, update: Update, args: List[str]):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    msg = update.effective_message  # type: Optional[Message]

    conn = connected(bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if update.effective_message.chat.type == "private":
            send_message(
                update.effective_message,
                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 ""
Esempio n. 17
0
def unmute(bot: Bot, update: Update, args: List[str]) -> str:
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]

    user_id = extract_user(message, args)
    if not user_id:
        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(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 = 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:
                bot.restrict_chat_member(chat.id,
                                         int(user_id),
                                         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 ""
Esempio n. 18
0
def set_rules(bot: Bot, update: Update):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    chat = update.effective_chat
    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(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."))
Esempio n. 19
0
def temp_mute(bot: Bot, update: Update, args: List[str]) -> str:
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]

    user_id, reason = extract_user_and_text(message, args)

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

    conn = connected(bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if update.effective_message.chat.type == "private":
            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 == bot.id:
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Saya tidak akan membisukan diri saya sendiri, apakah kamu gila?"
            ))
        return ""

    check = 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:
            bot.restrict_chat_member(chat.id,
                                     user_id,
                                     until_date=mutetime,
                                     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 ""
Esempio n. 20
0
def unblacklist(bot: Bot, update: Update):
    msg = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    words = msg.text.split(None, 1)

    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return

    conn = connected(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."
            ))
Esempio n. 21
0
def mute(bot: Bot, update: Update, args: List[str]) -> str:
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]

    user_id = extract_user(message, args)
    if not user_id:
        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(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 == bot.id:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Saya tidak akan membungkam diri saya sendiri!"))
        return ""

    check = 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:
            bot.restrict_chat_member(chat.id, user_id, 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 ""
Esempio n. 22
0
def unblackliststicker(bot: Bot, update: Update):
    msg = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    words = msg.text.split(None, 1)

    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return

    conn = connected(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."
            ))
Esempio n. 23
0
def set_blue_text_must_click(bot: Bot, update: Update, args):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return

    conn = connected(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")