Esempio n. 1
0
def add_blacklist(update, context):
	msg = update.effective_message  # type: Optional[Message]
	chat = update.effective_chat  # type: Optional[Chat]
	user = update.effective_user  # type: Optional[User]
	words = msg.text.split(None, 1)

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

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

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

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

	else:
		send_message(update.effective_message, tl(update.effective_message, "Beri tahu saya kata-kata apa yang ingin Anda hapus dari daftar hitam."))
Esempio n. 2
0
def purge(update, context):
    args = context.args
    msg = update.effective_message  # type: Optional[Message]
    if msg.reply_to_message:
        user = update.effective_user  # type: Optional[User]
        chat = update.effective_chat  # type: Optional[Chat]
        if user_can_delete(chat, user, context.bot.id):
            message_id = msg.reply_to_message.message_id
            if args and args[0].isdigit():
                delete_to = message_id + int(args[0])
            else:
                delete_to = msg.message_id - 1
            for m_id in range(delete_to, message_id - 1,
                              -1):  # Reverse iteration over message ids
                try:
                    context.bot.deleteMessage(chat.id, m_id)
                except BadRequest as err:
                    if err.message == "Message can't be deleted":
                        send_message(
                            update.effective_message,
                            tl(
                                update.effective_message,
                                "Tidak dapat menghapus semua pesan. Pesannya mungkin terlalu lama, saya mungkin "
                                "tidak memiliki hak menghapus, atau ini mungkin bukan supergrup."
                            ))

                    elif err.message != "Message to delete not found":
                        LOGGER.exception("Error while purging chat messages.")

            try:
                msg.delete()
            except BadRequest as err:
                if err.message == "Message can't be deleted":
                    send_message(
                        update.effective_message,
                        tl(
                            update.effective_message,
                            "Tidak dapat menghapus semua pesan. Pesannya mungkin terlalu lama, saya mungkin "
                            "tidak memiliki hak menghapus, atau ini mungkin bukan supergrup."
                        ))

                elif err.message != "Message to delete not found":
                    LOGGER.exception("Error while purging chat messages.")

            send_message(update.effective_message,
                         tl(update.effective_message, "Pembersihan selesai."))
            return "<b>{}:</b>" \
                   "\n#PURGE" \
                   "\n<b>Admin:</b> {}" \
                   "\nPurged <code>{}</code> messages.".format(html.escape(chat.title),
                                                               mention_html(user.id, user.first_name),
                                                               delete_to - message_id)

    else:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Balas pesan untuk memilih tempat mulai membersihkan."))

    return ""
Esempio n. 3
0
def donate(update, context):
    user = update.effective_message.from_user
    chat = update.effective_chat  # type: Optional[Chat]

    if chat.type == "private":
        update.effective_message.reply_text(tl(update.effective_message,
                                               DONATE_STRING),
                                            parse_mode=ParseMode.MARKDOWN,
                                            disable_web_page_preview=True)

        if OWNER_ID != 388576209 and DONATION_LINK:
            update.effective_message.reply_text(tl(
                update.effective_message,
                "Anda juga dapat menyumbang kepada orang yang saat ini menjalankan saya "
                "[disini]({})").format(DONATION_LINK),
                                                parse_mode=ParseMode.MARKDOWN)

    else:
        try:
            context.bot.send_message(user.id,
                                     tl(update.effective_message,
                                        DONATE_STRING),
                                     parse_mode=ParseMode.MARKDOWN,
                                     disable_web_page_preview=True)

            update.effective_message.reply_text(
                tl(update.effective_message,
                   "Saya sudah PM Anda tentang donasi untuk pencipta saya!"))
        except Unauthorized:
            update.effective_message.reply_text(
                tl(
                    update.effective_message,
                    "Hubungi saya di PM dulu untuk mendapatkan informasi donasi."
                ))
Esempio n. 4
0
def get_time_alt(update, context):
    args = context.args
    if args:
        location = " ".join(args)
        if location.lower() == context.bot.first_name.lower():
            send_message(update.effective_message, "Selalu ada waktu banned untukku!")
            context.bot.send_sticker(update.effective_chat.id, BAN_STICKER)
            return

        res = requests.get('https://dev.virtualearth.net/REST/v1/timezone/?query={}&key={}'.format(location, MAPS_API))

        if res.status_code == 200:
            loc = res.json()
            if len(loc['resourceSets'][0]['resources'][0]['timeZoneAtLocation']) == 0:
                send_message(update.effective_message, tl(update.effective_message, "Lokasi tidak di temukan!"))
                return
            placename = loc['resourceSets'][0]['resources'][0]['timeZoneAtLocation'][0]['placeName']
            localtime = loc['resourceSets'][0]['resources'][0]['timeZoneAtLocation'][0]['timeZone'][0]['convertedTime']['localTime']
            if lang_sql.get_lang(update.effective_chat.id) == "id":
                locale.setlocale(locale.LC_TIME, 'id_ID.UTF-8')
                time = datetime.strptime(localtime, '%Y-%m-%dT%H:%M:%S').strftime("%H:%M:%S hari %A, %d %B")
            else:
                time = datetime.strptime(localtime, '%Y-%m-%dT%H:%M:%S').strftime("%H:%M:%S %A, %d %B")
            send_message(update.effective_message, tl(update.effective_message, "Sekarang pukul `{}` di `{}`").format(time, placename), parse_mode="markdown")
    else:
        send_message(update.effective_message, tl(update.effective_message, "Gunakan `/time nama daerah`\nMisal: `/time jakarta`"), parse_mode="markdown")
Esempio n. 5
0
def permapin(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    args = context.args

    conn = connected(context.bot, update, chat, user.id, need_admin=False)
    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

    text, data_type, content, buttons = get_message_type(message)
    tombol = build_keyboard_alternate(buttons)
    try:
        message.delete()
    except BadRequest:
        pass
    if str(data_type) in ('Types.BUTTON_TEXT', 'Types.TEXT'):
        try:
            sendingmsg = context.bot.send_message(
                chat_id,
                text,
                parse_mode="markdown",
                disable_web_page_preview=True,
                reply_markup=InlineKeyboardMarkup(tombol))
        except BadRequest:
            context.bot.send_message(
                chat_id,
                tl(
                    update.effective_message,
                    "Teks markdown salah!\nJika anda tidak tahu apa itu markdown, silahkan ketik `/markdownhelp` pada PM."
                ),
                parse_mode="markdown")
            return
    else:
        sendingmsg = ENUM_FUNC_MAP[str(data_type)](
            chat_id,
            content,
            caption=text,
            parse_mode="markdown",
            disable_web_page_preview=True,
            reply_markup=InlineKeyboardMarkup(tombol))
    try:
        context.bot.pinChatMessage(chat_id, sendingmsg.message_id)
    except BadRequest:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Saya tidak punya akses untuk pin pesan!"))
Esempio n. 6
0
def clear_rules(update, context):
    chat = update.effective_chat
    chat_id = update.effective_chat.id
    user = update.effective_user

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

    chat_id = update.effective_chat.id
    sql.set_rules(chat_id, "")
    send_message(update.effective_message,
                 tl(update.effective_message, "Berhasil membersihkan aturan!"))
Esempio n. 7
0
def __chat_settings__(chat_id, user_id):
    administrators = dispatcher.bot.getChatAdministrators(chat_id)
    chat = dispatcher.bot.getChat(chat_id)
    text = "Admin di *{}*:".format(chat.title or "chat ini")
    for admin in administrators:
        user = admin.user
        status = admin.status
        if user.first_name == '':
            name = tl(user_id, "☠ Akun Terhapus")
        else:
            name = "{}".format(
                mention_markdown(
                    user.id, user.first_name + " " + (user.last_name or "")))
        #if user.username:
        #    name = escape_markdown("@" + user.username)
        if status == "creator":
            text += "\n 👑 Creator:"
            text += "\n` • `{} \n\n 🔱 Admin:".format(name)
    for admin in administrators:
        user = admin.user
        status = admin.status
        if user.first_name == '':
            name = tl(user_id, "☠ Akun Terhapus")
        else:
            name = "{}".format(
                mention_markdown(
                    user.id, user.first_name + " " + (user.last_name or "")))
        #if user.username:
        #    name = escape_markdown("@" + user.username)
        if status == "administrator":
            text += "\n` • `{}".format(name)
    text += tl(user_id, "\n\nKamu adalah *{}*").format(
        dispatcher.bot.get_chat_member(chat_id, user_id).status)
    return text
Esempio n. 8
0
def set_about_bio(update, context):
    message = update.effective_message  # type: Optional[Message]
    sender = update.effective_user  # type: Optional[User]
    if message.reply_to_message:
        repl_message = message.reply_to_message
        user_id = repl_message.from_user.id
        if user_id == message.from_user.id:
            send_message(update.effective_message, tl(update.effective_message, "Ha, Anda tidak dapat mengatur bio Anda sendiri! Anda berada di bawah belas kasihan orang lain di sini..."))
            return
        elif user_id == bot.id and sender.id not in SUDO_USERS:
            send_message(update.effective_message, tl(update.effective_message, "Umm ... yah, saya hanya mempercayai pengguna sudo untuk mengatur bio saya."))
            return

        text = message.text
        bio = text.split(None, 1)  # use python's maxsplit to only remove the cmd, hence keeping newlines.
        if len(bio) == 2:
            if len(bio[1]) < MAX_MESSAGE_LENGTH // 4:
                sql.set_user_bio(user_id, bio[1])
                send_message(update.effective_message, tl(update.effective_message, "Bio {} diperbarui!").format(repl_message.from_user.first_name))
            else:
                send_message(update.effective_message, 
                    tl(update.effective_message, "Biografi harus di bawah {} karakter! Anda mencoba mengatur {}.").format(
                        MAX_MESSAGE_LENGTH // 4, len(bio[1])))
    else:
        send_message(update.effective_message, tl(update.effective_message, "Balas pesan seseorang untuk mengatur bio mereka!"))
Esempio n. 9
0
def slap(update, context):
    args = context.args
    msg = update.effective_message  # type: Optional[Message]

    # reply to correct message
    reply_text = msg.reply_to_message.reply_text if msg.reply_to_message else msg.reply_text

    # get user who sent message
    #if msg.from_user.username:
    #    curr_user = "******" + escape_markdown(msg.from_user.username)
    #else:
    curr_user = "******".format(mention_markdown(msg.from_user.id, msg.from_user.first_name))

    user_id = extract_user(update.effective_message, args)
    if user_id and user_id != "error":
        slapped_user = context.bot.get_chat(user_id)
        user1 = curr_user
        #if slapped_user.username:
        #    user2 = "@" + escape_markdown(slapped_user.username)
        #else:
        user2 = "{}".format(mention_markdown(slapped_user.id, slapped_user.first_name))

    # if no target found, bot targets the sender
    else:
        user1 = "{}".format(mention_markdown(context.bot.id, context.bot.first_name))
        user2 = curr_user

    temp = random.choice(tl(update.effective_message, "SLAP_TEMPLATES"))
    item = random.choice(tl(update.effective_message, "ITEMS"))
    hit = random.choice(tl(update.effective_message, "HIT"))
    throw = random.choice(tl(update.effective_message, "THROW"))

    repl = temp.format(user1=user1, user2=user2, item=item, hits=hit, throws=throw)

    send_message(update.effective_message, repl, parse_mode=ParseMode.MARKDOWN)
Esempio n. 10
0
def __chat_settings__(chat_id, user_id):
    limit = sql.get_flood_limit(chat_id)
    if limit == 0:
        return tl(user_id,
                  "Saat ini *Tidak* menegakkan pengendalian pesan beruntun.")
    else:
        return tl(user_id,
                  "Anti Pesan Beruntun diatur ke `{}` pesan.").format(limit)
Esempio n. 11
0
def ungban(update, context):
    message = update.effective_message  # type: Optional[Message]
    args = context.args

    user_id = extract_user(message, args)
    if not user_id:
        send_message(update.effective_message, tl(update.effective_message, "Anda sepertinya tidak mengacu pada pengguna."))
        return
    if user_id == "error":
        send_message(update.effective_message, tl(update.effective_message, "Error: Unknown user!"))
        return ""

    user_chat = context.bot.get_chat(user_id)
    if user_chat.type != 'private':
        send_message(update.effective_message, tl(update.effective_message, "Itu bukan pengguna!"))
        return

    if not sql.is_user_gbanned(user_id):
        send_message(update.effective_message, tl(update.effective_message, "Pengguna ini tidak dilarang secara global!"))
        return

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

    send_message(update.effective_message, tl(update.effective_message, "Saya akan berikan {} kesempatan kedua, secara global.").format(user_chat.first_name))

    send_to_list(context.bot, SUDO_USERS + SUPPORT_USERS,
                 tl(update.effective_message, "{} telah menghapus larangan global untuk pengguna {}").format(mention_html(banner.id, banner.first_name),
                                                   mention_html(user_chat.id, user_chat.first_name)),
                 html=True)

    sql.ungban_user(user_id)

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

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

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

        except BadRequest as excp:
            if excp.message in UNGBAN_ERRORS:
                pass
            else:
                send_message(update.effective_message, tl(update.effective_message, "Tidak dapat menghapus larangan secara global karena: {}").format(excp.message))
                context.bot.send_message(OWNER_ID, tl(update.effective_message, "Tidak dapat menghapus larangan secara global karena: {}").format(excp.message))
                return
        except TelegramError:
            pass

    send_to_list(context.bot, SUDO_USERS + SUPPORT_USERS, tl(update.effective_message, "Menghapus larangan global selesai!"))

    send_message(update.effective_message, tl(update.effective_message, "Orang ini telah dihapus larangannya."))
Esempio n. 12
0
def disconnect_chat(update, context):
    if update.effective_chat.type == 'private':
        disconnection_status = sql.disconnect(update.effective_message.from_user.id)
        if disconnection_status:
           sql.disconnected_chat = send_message(update.effective_message, languages.tl(update.effective_message, "Terputus dari obrolan!"))
        else:
           send_message(update.effective_message, languages.tl(update.effective_message, "Anda tidak terkoneksi!"))
    else:
        send_message(update.effective_message, languages.tl(update.effective_message, "Penggunaan terbatas hanya untuk PM"))
Esempio n. 13
0
    def setlog(update, context):
        message = update.effective_message  # type: Optional[Message]
        chat = update.effective_chat  # type: Optional[Chat]
        if chat.type == chat.CHANNEL:
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Sekarang, teruskan /setlog ke grup yang Anda ingin ikat saluran ini!"
                ))

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

            try:
                context.bot.send_message(
                    message.forward_from_chat.id,
                    tl(
                        update.effective_message,
                        "Saluran ini telah ditetapkan sebagai saluran log untuk {}."
                    ).format(chat.title or chat.first_name))
            except Unauthorized as excp:
                if excp.message == "Forbidden: bot is not a member of the channel chat":
                    context.bot.send_message(
                        chat.id,
                        tl(
                            update.effective_message,
                            "Gagal menyetel saluran log!\nSaya mungkin bukan admin di channel tersebut."
                        ))
                    sql.stop_chat_logging(chat.id)
                    return
                else:
                    LOGGER.exception("ERROR in setting the log channel.")

            context.bot.send_message(
                chat.id,
                tl(update.effective_message, "Berhasil mengatur saluran log!"))

        else:
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Langkah-langkah untuk mengatur saluran log adalah:\n"
                    " - tambahkan bot ke saluran yang diinginkan\n"
                    " - Kirimkan /setlog ke saluran\n"
                    " - Teruskan /setlog ke grup\n"))
Esempio n. 14
0
def help_connect_chat(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    args = context.args

    if update.effective_message.chat.type != "private":
        send_message(update.effective_message, languages.tl(update.effective_message, "PM saya dengan command itu untuk mendapatkan bantuan Koneksi"))
        return
    else:
        send_message(update.effective_message, languages.tl(update.effective_message, "supportcmd"), parse_mode="markdown")
Esempio n. 15
0
 def __chat_settings__(chat_id, user_id):
     log_channel = sql.get_chat_log_channel(chat_id)
     if log_channel:
         log_channel_info = dispatcher.bot.get_chat(log_channel)
         return tl(
             user_id,
             "Grup ini memiliki semua log yang dikirim ke: {} (`{}`)"
         ).format(escape_markdown(log_channel_info.title), log_channel)
     return tl(user_id,
               "Tidak ada saluran masuk yang ditetapkan untuk grup ini!")
Esempio n. 16
0
def kickme(update, context):
    user_id = update.effective_message.from_user.id
    if is_user_admin(update.effective_chat, user_id):
        send_message(update.effective_message, tl(update.effective_message, "Saya berharap saya bisa... tetapi Anda seorang admin 😒"))
        return

    res = update.effective_chat.unban_member(user_id)  # unban on current user = kick
    if res:
        send_message(update.effective_message, tl(update.effective_message, "Tidak masalah 😊"))
    else:
        send_message(update.effective_message, tl(update.effective_message, "Hah? Aku tidak bisa 🙄"))
Esempio n. 17
0
def __user_info__(user_id, chat_id):
    if user_id == dispatcher.bot.id:
        return languages.tl(
            chat_id,
            """Saya telah melihatnya... Wow. Apakah mereka menguntit saya? Mereka ada di semua tempat yang sama dengan saya... oh. Ini aku."""
        )
    num_chats = sql.get_user_num_chats(user_id)
    return languages.tl(
        chat_id,
        """Saya telah melihatnya <code>{}</code> obrolan total.""").format(
            num_chats)
Esempio n. 18
0
def set_about_me(update, context):
    message = update.effective_message  # type: Optional[Message]
    user_id = message.from_user.id
    text = message.text
    info = text.split(None, 1)  # use python's maxsplit to only remove the cmd, hence keeping newlines.
    if len(info) == 2:
        if len(info[1]) < MAX_MESSAGE_LENGTH // 4:
            sql.set_user_me_info(user_id, info[1])
            send_message(update.effective_message, tl(update.effective_message, "Info Anda Diperbarui!"))
        else:
            send_message(update.effective_message, 
                tl(update.effective_message, "Info Anda harus di bawah {} karakter! Kamu punya {}.").format(MAX_MESSAGE_LENGTH // 4, len(info[1])))
Esempio n. 19
0
    def build_curr_disabled(chat_id: Union[str, int]) -> str:
        disabled = sql.get_all_disabled(chat_id)
        if not disabled:
            return languages.tl(chat_id,
                                "Tidak ada perintah yang dinonaktifkan!")

        result = ""
        for cmd in disabled:
            result += " - `{}`\n".format(escape_markdown(cmd))
        return languages.tl(
            chat_id,
            "Perintah-perintah berikut saat ini dibatasi:\n{}").format(result)
Esempio n. 20
0
    def disable(update, context):
        chat = update.effective_chat  # type: Optional[Chat]
        user = update.effective_user
        args = context.args

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

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

            if disable_cmd in set(DISABLE_CMDS + DISABLE_OTHER):
                sql.disable_command(chat.id, disable_cmd)
                if conn:
                    text = languages.tl(
                        update.effective_message,
                        "Menonaktifkan penggunaan `{}` pada *{}*").format(
                            disable_cmd, chat_name)
                else:
                    text = languages.tl(
                        update.effective_message,
                        "Menonaktifkan penggunaan `{}`").format(disable_cmd)
                send_message(update.effective_message,
                             text,
                             parse_mode=ParseMode.MARKDOWN)
            else:
                send_message(
                    update.effective_message,
                    languages.tl(update.effective_message,
                                 "Perintah itu tidak bisa dinonaktifkan"))

        else:
            send_message(
                update.effective_message,
                languages.tl(update.effective_message,
                             "Apa yang harus saya nonaktifkan?"))
Esempio n. 21
0
def list_notes(update, context):
	chat = update.effective_chat  # type: Optional[Chat]
	user = update.effective_user  # type: Optional[User]
	conn = connected(context.bot, update, chat, user.id, need_admin=False)
	if conn:
		chat_id = conn
		chat_name = dispatcher.bot.getChat(conn).title
		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. 22
0
def __user_info__(user_id, chat_id):
    bio = html.escape(sql.get_user_bio(user_id) or "")
    me = html.escape(sql.get_user_me_info(user_id) or "")
    if bio and len(bio) > 500:
        bio = bio[:500]
    if me and len(me) > 500:
        me = me[:500]
    if bio and me:
        return tl(chat_id, "<b>Tentang pengguna:</b>\n{me}\n<b>Apa yang orang lain katakan:</b>\n{bio}").format(me=me, bio=bio)
    elif bio:
        return tl(chat_id, "<b>Apa yang orang lain katakan:</b>\n{bio}\n").format(me=me, bio=bio)
    elif me:
        return tl(chat_id, "<b>Tentang pengguna:</b>\n{me}").format(me=me, bio=bio)
    else:
        return ""
Esempio n. 23
0
def unblacklist(update, context):
	msg = update.effective_message  # type: Optional[Message]
	chat = update.effective_chat  # type: Optional[Chat]
	user = update.effective_user  # type: Optional[User]
	words = msg.text.split(None, 1)

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


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

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

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

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

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

    # ONLY send settings in PM
    if chat.type != chat.PRIVATE:
        if is_user_admin(chat, user.id):
            text = tl(
                update.effective_message,
                "Klik di sini untuk mendapatkan pengaturan obrolan ini, serta milik Anda."
            )
            msg.reply_text(text,
                           reply_markup=InlineKeyboardMarkup([[
                               InlineKeyboardButton(
                                   text="Pengaturan",
                                   url="t.me/{}?start=stngs_{}".format(
                                       context.bot.username, chat.id))
                           ]]))
        # else:
        #     text = tl(update.effective_message, "Klik di sini untuk memeriksa pengaturan Anda.")

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

        text = build_curr_disabled(chat.id)
        send_message(update.effective_message,
                     text,
                     parse_mode=ParseMode.MARKDOWN)
Esempio n. 26
0
 def list_cmds(update, context):
     if DISABLE_CMDS + DISABLE_OTHER:
         result = ""
         for cmd in set(DISABLE_CMDS + DISABLE_OTHER):
             result += " - `{}`\n".format(escape_markdown(cmd))
         send_message(
             update.effective_message,
             languages.tl(
                 update.effective_message,
                 "Perintah berikut dapat diubah:\n{}").format(result),
             parse_mode=ParseMode.MARKDOWN)
     else:
         send_message(
             update.effective_message,
             languages.tl(update.effective_message,
                          "Tidak ada perintah yang dapat dinonaktifkan."))
Esempio n. 27
0
def log_user(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    msg = update.effective_message  # type: Optional[Message]
    """text = msg.text if msg.text else ""
                uid = msg.from_user.id
                uname = msg.from_user.name
                print("{} | {} | {} | {}".format(text, uname, uid, chat.title))"""
    fed_id = fedsql.get_fed_id(chat.id)
    if fed_id:
        user = update.effective_user
        if user:
            fban, fbanreason, fbantime = fedsql.get_fban_user(fed_id, user.id)
            if fban:
                send_message(
                    update.effective_message,
                    languages.tl(
                        update.effective_message,
                        "Pengguna ini dilarang di federasi saat ini!\nAlasan: `{}`"
                    ).format(fbanreason),
                    parse_mode="markdown")
                try:
                    context.bot.kick_chat_member(chat.id, user.id)
                except:
                    print("Fban: cannot banned this user")

    sql.update_user(msg.from_user.id, msg.from_user.username, chat.id,
                    chat.title)

    if msg.reply_to_message:
        sql.update_user(msg.reply_to_message.from_user.id,
                        msg.reply_to_message.from_user.username, chat.id,
                        chat.title)

    if msg.forward_from:
        sql.update_user(msg.forward_from.id, msg.forward_from.username)
Esempio n. 28
0
def permanent_pin(update, context):
    user = update.effective_user  # type: Optional[User]
    chat = update.effective_chat  # type: Optional[Chat]
    message = update.effective_message
    args = context.args

    get_permapin = sql.get_permapin(chat.id)
    if get_permapin and not user.id == context.bot.id:
        try:
            to_del = context.bot.pinChatMessage(chat.id,
                                                get_permapin,
                                                disable_notification=True)
        except BadRequest:
            sql.set_permapin(chat.id, 0)
            if chat.username:
                old_pin = "https://t.me/{}/{}".format(chat.username,
                                                      get_permapin)
            else:
                old_pin = "https://t.me/c/{}/{}".format(
                    str(chat.id)[4:], get_permapin)
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "*Permanen pin error:*\nSaya tidak bisa menyematkan pesan di sini!\nPastikan saya admin dan dapat pin pesan.\n\nPermanen pin di nonaktifkan, [pesan permanen pin lama ada disini]({})"
                ).format(old_pin),
                parse_mode="markdown")
            return

        if to_del:
            try:
                context.bot.deleteMessage(chat.id, message.message_id + 1)
            except BadRequest:
                print("Permanent pin error: cannot delete pin msg")
Esempio n. 29
0
def private_rules(update, context):
    args = context.args
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    conn = connected(context.bot, update, chat, user.id)
    if conn:
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        chat_id = update.effective_chat.id
        if chat.type == "private":
            chat_name = chat.title
        else:
            chat_name = chat.title

    if len(args) >= 1:
        if args[0] in ("yes", "on", "ya"):
            sql.private_rules(str(chat_id), True)
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Private Rules di *aktifkan*, pesan peraturan akan di kirim di PM."
                ),
                parse_mode="markdown")
        elif args[0] in ("no", "off"):
            sql.private_rules(str(chat_id), False)
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Private Rules di *non-aktifkan*, pesan peraturan akan di kirim di grup."
                ),
                parse_mode="markdown")
        else:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Argumen tidak dikenal - harap gunakan 'yes', atau 'no'."))
    else:
        is_private = sql.get_private_rules(chat_id)
        send_message(update.effective_message,
                     tl(update.effective_message,
                        "Pengaturan Private Rules di {}: *{}*").format(
                            chat_name,
                            "Enabled" if is_private else "Disabled"),
                     parse_mode="markdown")
Esempio n. 30
0
def cmd_get(update, context):
	args = context.args
	if len(args) >= 2 and args[1].lower() == "noformat":
		get(context.bot, update, args[0], show_none=True, no_format=True)
	elif len(args) >= 1:
		get(context.bot, update, args[0], show_none=True)
	else:
		send_message(update.effective_message, tl(update.effective_message, "Get apa?"))