Exemple #1
0
def list_locks(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

    # 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

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

    send_message(update.effective_message, res, parse_mode=ParseMode.MARKDOWN)
Exemple #2
0
def add_url(bot, update, args):
    spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    if len(args) >= 1:
        chat = update.effective_chat

        tg_chat_id = str(update.effective_chat.id)

        tg_feed_link = args[0]

        link_processed = parse(tg_feed_link)

        # check if link is a valid RSS Feed link
        if link_processed.bozo == 0:
            if len(link_processed.entries[0]) >= 1:
                tg_old_entry_link = link_processed.entries[0].link
            else:
                tg_old_entry_link = ""

            # gather the row which contains exactly that telegram group ID and link for later comparison
            row = sql.check_url_availability(tg_chat_id, tg_feed_link)

            # check if there's an entry already added to DB by the same user in the same group with the same link
            if row:
                send_message(update.effective_message, tl(update.effective_message, "URL ini sudah ditambahkan"))
            else:
                sql.add_url(tg_chat_id, tg_feed_link, tg_old_entry_link)

                send_message(update.effective_message, tl(update.effective_message, "URL ditambahkan ke langganan"))
        else:
            send_message(update.effective_message, tl(update.effective_message, "Tautan ini bukan tautan Umpan RSS"))
    else:
        send_message(update.effective_message, tl(update.effective_message, "URL hilang"))
Exemple #3
0
def leavechat(bot: Bot, update: Update, args: List[int]):
    if args:
        chat_id = int(args[0])
    else:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda sepertinya tidak mengacu pada obrolan"))
    try:
        chat = bot.getChat(chat_id)
        titlechat = bot.get_chat(chat_id).title
        bot.sendMessage(
            chat_id, tl(update.effective_message, "Selamat tinggal semua 😁"))
        bot.leaveChat(chat_id)
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Saya telah keluar dari grup {}").format(titlechat))

    except BadRequest as excp:
        if excp.message == "Chat not found":
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Sepertinya saya sudah keluar atau di tendang di grup tersebut"
                ))
        else:
            return
Exemple #4
0
def clear_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

    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

    chat_id = update.effective_chat.id
    sql.set_rules(chat_id, "")
    send_message(update.effective_message,
                 tl(update.effective_message, "Berhasil membersihkan aturan!"))
Exemple #5
0
def disconnect_chat(bot, update):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return

    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"))
Exemple #6
0
def about_bio(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

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

    user_id = extract_user(message, args)
    if user_id:
        user = bot.get_chat(user_id)
    else:
        user = message.from_user

    info = sql.get_user_bio(user.id)

    if info:
        send_message(update.effective_message,
                     "*{}*:\n{}".format(user.first_name,
                                        escape_markdown(info)),
                     parse_mode=ParseMode.MARKDOWN)
    elif message.reply_to_message:
        username = user.first_name
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "{} belum memiliki pesan tentang dirinya sendiri!").format(
                   username))
    else:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda belum memiliki bio set tentang diri Anda!"))
Exemple #7
0
def get_settings(bot: Bot, update: Update):
    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)

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

    # 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(
                                       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)
Exemple #8
0
def connection_chat(bot, update):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]

    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 = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if update.effective_message.chat.type != "private":
            return
        chat = update.effective_chat
        chat_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title

    if conn:
        teks = languages.tl(
            update.effective_message,
            "Saat ini Anda terhubung dengan {}.\n").format(chat_name)
    else:
        teks = languages.tl(update.effective_message,
                            "Saat ini Anda tidak terhubung dengan grup.\n")
    teks += languages.tl(update.effective_message, "supportcmd")
    send_message(update.effective_message, teks, parse_mode="markdown")
Exemple #9
0
def reply_afk(bot: Bot, update: Update):
    message = update.effective_message  # type: Optional[Message]

    entities = message.parse_entities([MessageEntity.TEXT_MENTION, MessageEntity.MENTION])
    if message.entities and entities:
        for ent in entities:
            if ent.type == MessageEntity.TEXT_MENTION:
                user_id = ent.user.id
                fst_name = ent.user.first_name
                
            elif ent.type == MessageEntity.MENTION:
                user_id = get_user_id(message.text[ent.offset:ent.offset + ent.length])
                if not user_id:
                    # Should never happen, since for a user to become AFK they must have spoken. Maybe changed username?
                    return
                try:
                    chat = bot.get_chat(user_id)
                except BadRequest:
                    print("Error: Could not fetch userid {} for AFK module".off dulu yekan(user_id))
                    return
                fst_name = chat.first_name
                
            else:   
                return

            if sql.is_afk(user_id):
                valid, reason = sql.check_afk_status(user_id)
                if valid:
                    if not reason:
                        res = tl(update.effective_message, "{} sedang AFK!").off dulu yekan(fst_name)
                    else:
                        res = tl(update.effective_message, "{} sedang AFK!\nKarena : {}").off dulu yekan(fst_name, reason)
                    send_message(update.effective_message, res)
Exemple #10
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
Exemple #11
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!")
Exemple #12
0
def buttonask(bot, update):
	query = update.callback_query
	splitter = query.data.replace("ak_", "").split("+")
	isyes = splitter[1].split('|')[0]
	report_chat = splitter[1].split('|')[1].split('=')[0]
	report_target = splitter[1].split('|')[1].split('=')[1]
	chat = update.effective_chat
	msg = CURRENT_REPORT.get(str(report_chat))
	userinfo = CURRENT_REPORT.get(str(report_chat)+"user")
	key = CURRENT_REPORT.get(str(report_chat)+"key")

	if isyes == "y":
		a, b = user_protection_checker(bot, report_target)
		if not a:
			bot.edit_message_text(text=msg + b,
							  chat_id=query.message.chat_id,
							  message_id=query.message.message_id, parse_mode=ParseMode.HTML)
			return
		if splitter[0] == "1":
			try:
				bot.unbanChatMember(report_chat, report_target)
				bot.sendMessage(report_chat, text=tl(update.effective_message, "{} telah di tendang!\nOleh: {}").format(\
					mention_markdown(userinfo['id'], userinfo['name']), mention_markdown(chat.id, chat.first_name)), \
					parse_mode=ParseMode.MARKDOWN)
				bot.edit_message_text(text=msg + tl(update.effective_message, "\n\n{} telah di tendang!").format(mention_html(userinfo['id'], userinfo['name'])),
							  chat_id=query.message.chat_id,
							  message_id=query.message.message_id, parse_mode=ParseMode.HTML)
			except Exception as err:
				bot.edit_message_text(text=msg + "\n\nError: {}".format(err),
							  chat_id=query.message.chat_id,
							  message_id=query.message.message_id, parse_mode=ParseMode.HTML)
		elif splitter[0] == "2":
			try:
				bot.kickChatMember(report_chat, report_target)
				bot.sendMessage(report_chat, text=tl(update.effective_message, "{} telah di banned!\nOleh: {}").format(\
					mention_markdown(userinfo['id'], userinfo['name']), mention_markdown(chat.id, chat.first_name)), \
					parse_mode=ParseMode.MARKDOWN)
				bot.edit_message_text(text=msg + tl(update.effective_message, "\n\n{} telah di banned!").format(mention_html(userinfo['id'], userinfo['name'])),
							  chat_id=query.message.chat_id,
							  message_id=query.message.message_id, parse_mode=ParseMode.HTML)
			except Exception as err:
				bot.edit_message_text(text=msg + "\n\nError: {}".format(err),
							  chat_id=query.message.chat_id,
							  message_id=query.message.message_id, parse_mode=ParseMode.HTML)
		elif splitter[0] == "3":
			try:
				bot.deleteMessage(report_chat, report_target)
				bot.edit_message_text(text=msg + tl(update.effective_message, "\n\nPesan dihapus!"),
							  chat_id=query.message.chat_id,
							  message_id=query.message.message_id, parse_mode=ParseMode.HTML)
			except Exception as err:
				bot.edit_message_text(text=msg + "\n\nError: {}".format(err),
							  chat_id=query.message.chat_id,
							  message_id=query.message.message_id, parse_mode=ParseMode.HTML)
	elif isyes == "n":
		bot.edit_message_text(text=msg,
							  chat_id=query.message.chat_id,
							  message_id=query.message.message_id, parse_mode=ParseMode.HTML,
							  reply_markup=key)
Exemple #13
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)
Exemple #14
0
    def build_curr_disabled(chat_id: Union[str, int]) -> str:
        disabled = sql.get_all_disabled(chat_id)
        if not disabled:
            return languages.tl(update.effective_message, "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)
Exemple #15
0
def add_blacklist(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_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."
            ))
Exemple #16
0
def ramalan(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
    text = ""
    if random.randint(1, 10) >= 7:
        text += random.choice(tl(update.effective_message, "RAMALAN_FIRST"))
    text += random.choice(tl(update.effective_message, "RAMALAN_STRINGS"))
    send_message(update.effective_message, text)
Exemple #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)
Exemple #18
0
def set_about_bio(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

    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!"))
Exemple #19
0
def blacklist(bot: Bot, update: Update, args: List[str]):
    msg = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]

    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=False)
    if conn:
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if chat.type == "private":
            return
        else:
            chat_id = update.effective_chat.id
            chat_name = chat.title

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

    all_blacklisted = sql.get_chat_blacklist(chat_id)

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

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

    split_text = split_message(filter_list)
    for text in split_text:
        if filter_list == tl(
                update.effective_message,
                "<b>Kata daftar hitam saat ini di {}:</b>\n").format(
                    chat_name):
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Tidak ada pesan daftar hitam di <b>{}</b>!").format(
                       chat_name),
                parse_mode=ParseMode.HTML)
            return
        send_message(update.effective_message, text, parse_mode=ParseMode.HTML)
Exemple #20
0
    def list_cmds(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

        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."))
Exemple #21
0
    def send_log(bot: Bot, log_chat_id: str, orig_chat_id: str, result: str):
        try:
            bot.send_message(log_chat_id, result, parse_mode=ParseMode.HTML)
        except BadRequest as excp:
            if excp.message == "Chat not found":
                bot.send_message(orig_chat_id, tl(update.effective_message, "Saluran log ini telah dihapus - tidak bisa dibuka."))
                sql.stop_chat_logging(orig_chat_id)
            else:
                LOGGER.warning(excp.message)
                LOGGER.warning(result)
                LOGGER.exception("Could not parse")

                bot.send_message(log_chat_id, result + tl(update.effective_message, "\n\nMemformat telah dinonaktifkan karena kesalahan tak terduga."))
Exemple #22
0
def private_rules(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"):
            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")
Exemple #23
0
    def unsetlog(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
        message = update.effective_message  # type: Optional[Message]
        chat = update.effective_chat  # type: Optional[Chat]

        log_channel = sql.stop_chat_logging(chat.id)
        if log_channel:
            bot.send_message(log_channel, tl(update.effective_message, "Channel telah dibatalkan tautannya {}").format(chat.title))
            send_message(update.effective_message, tl(update.effective_message, "Log saluran telah dinonaktifkan."))

        else:
            send_message(update.effective_message, tl(update.effective_message, "Belum ada saluran log yang ditetapkan!"))
Exemple #24
0
def stop_filter(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    args = update.effective_message.text.split(None, 1)

    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 not conn == False:
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        chat_id = update.effective_chat.id
        if chat.type == "private":
            chat_name = tl(update.effective_message, "catatan lokal")
        else:
            chat_name = chat.title

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

    chat_filters = sql.get_chat_triggers(chat_id)

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

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

    send_message(
        update.effective_message,
        "Itu bukan filter aktif - jalankan /filter untuk semua filter aktif.")
Exemple #25
0
def get_time_alt(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
    if args:
        location = " ".join(args)
        if location.lower() == bot.first_name.lower():
            send_message(update.effective_message,
                         "Selalu ada waktu banned untukku!")
            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")
Exemple #26
0
def ungban(bot: Bot, update: Update, args: List[str]):
    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 sepertinya tidak mengacu pada pengguna."))
        return

    user_chat = 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(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 = bot.get_chat_member(chat_id, user_id)
            if member.status == 'kicked':
                bot.unban_chat_member(chat_id, user_id)

        except BadRequest as excp:
            if excp.message in UNGBAN_ERRORS:
                pass
            else:
                send_message(update.effective_message, tl(update.effective_message, "Tidak dapat menghapus larangan secara global karena: {}").format(excp.message))
                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(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."))
Exemple #27
0
def kickme(bot: Bot, update: Update):
    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

    spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message)
    if spam == True:
        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 🙄"))
Exemple #28
0
def flood(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    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=False)
    if conn:
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if update.effective_message.chat.type == "private":
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Anda bisa lakukan command ini pada grup, bukan pada PM"))
            return
        chat_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title

    limit = sql.get_flood_limit(chat_id)
    if limit == 0:
        if conn:
            text = tl(
                update.effective_message,
                "Saat ini saya tidak memberlakukan pengendalian pesan beruntun pada *{}*!"
            ).format(chat_name)
        else:
            text = tl(
                update.effective_message,
                "Saat ini saya tidak memberlakukan pengendalian pesan beruntun"
            )
        send_message(update.effective_message, text, parse_mode="markdown")
    else:
        if conn:
            text = tl(
                update.effective_message,
                "Saat ini saya melarang pengguna jika mereka mengirim lebih dari *{}* pesan berturut-turut pada *{}*."
            ).format(limit, chat_name)
        else:
            text = tl(
                update.effective_message,
                "Saat ini saya melarang pengguna jika mereka mengirim lebih dari *{}* pesan berturut-turut."
            ).format(limit)
        send_message(update.effective_message, text, parse_mode="markdown")
Exemple #29
0
def log_user(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    msg = update.effective_message  # type: Optional[Message]
    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:
                    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)
Exemple #30
0
def permanent_pin(bot: Bot, update: Update):
    user = update.effective_user  # type: Optional[User]
    chat = update.effective_chat  # type: Optional[Chat]
    message = update.effective_message

    get_permapin = sql.get_permapin(chat.id)
    if get_permapin and not user.id == bot.id:
        try:
            to_del = 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:
                bot.deleteMessage(chat.id, message.message_id + 1)
            except BadRequest:
                print("Permanent pin error: cannot delete pin msg")