예제 #1
0
    def enable(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:
            enable_cmd = args[0]
            if enable_cmd.startswith(CMD_STARTERS):
                enable_cmd = enable_cmd[1:]

            if sql.enable_command(chat.id, enable_cmd):
                if conn:
                    text = languages.tl(update.effective_message, "Diaktifkan penggunaan `{}` pada *{}*").format(enable_cmd, chat_name)
                else:
                    text = languages.tl(update.effective_message, "Diaktifkan penggunaan `{}`").format(enable_cmd)
                send_message(update.effective_message, text,
                                                    parse_mode=ParseMode.MARKDOWN)
            else:
                send_message(update.effective_message, languages.tl(update.effective_message, "Apakah itu bahkan dinonaktifkan?"))

        else:
            send_message(update.effective_message, languages.tl(update.effective_message, "Apa yang harus saya aktifkan?"))
예제 #2
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,
                   "You can do this command in groups, not 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,
                    "Wrong markdown text!\nIf you don't know what markdown is, please type `/markdownhelp` in 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,
               "I don't have access to pin message!"))
예제 #3
0
def blackliststicker(update, context):
	msg = update.effective_message  # type: Optional[Message]
	chat = update.effective_chat  # type: Optional[Chat]
	user = update.effective_user  # type: Optional[User]
	args = context.args
		
	conn = connected(context.bot, update, chat, user.id, need_admin=False)
	if conn:
		chat_id = conn
		chat_name = dispatcher.bot.getChat(conn).title
	else:
		if chat.type == "private":
			return
		else:
			chat_id = update.effective_chat.id
			chat_name = chat.title
		
	sticker_list = tl(update.effective_message, "<b>Daftar hitam stiker saat saat ini di {}:</b>\n").format(chat_name)

	all_stickerlist = sql.get_chat_stickers(chat_id)

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

	split_text = split_message(sticker_list)
	for text in split_text:
		if sticker_list == tl(update.effective_message, "<b>Daftar hitam stiker saat saat ini di {}:</b>\n").format(chat_name).format(chat_name):
			send_message(update.effective_message, tl(update.effective_message, "Tidak ada stiker daftar hitam stiker di <b>{}</b>!").format(chat_name), parse_mode=ParseMode.HTML)
			return
	send_message(update.effective_message, text, parse_mode=ParseMode.HTML)
예제 #4
0
def set_blue_text_must_click(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    args = context.args

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

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

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

        else:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Argumen tidak dikenal - harap gunakan 'yes', atau 'no'."))
    else:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Pengaturan untuk penghapus pesan biru saat ini di {}: *{}*").
            format(chat_name,
                   "Enabled" if sql.is_enable(chat_id) else "Disabled"),
            parse_mode="markdown")
예제 #5
0
def add_blackliststicker(update, context):
	msg = update.effective_message  # type: Optional[Message]
	chat = update.effective_chat  # type: Optional[Chat]
	user = update.effective_user  # type: Optional[User]
	words = msg.text.split(None, 1)

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

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

		if added == 0:
			return

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

		if added == 0:
			return

		send_message(update.effective_message, tl(update.effective_message, "Stiker <code>{}</code> ditambahkan ke daftar hitam stiker di <b>{}</b>!").format(trigger, chat_name), parse_mode=ParseMode.HTML)
	else:
		send_message(update.effective_message, tl(update.effective_message, "Beri tahu saya stiker apa yang ingin Anda tambahkan ke daftar hitam stiker."))
예제 #6
0
def add_warn_filter(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    msg = update.effective_message  # type: Optional[Message]
    user = update.effective_user  # type: Optional[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

    args = msg.text.split(
        None,
        1)  # use python's maxsplit to separate Cmd, keyword, and reply_text

    if len(args) < 2:
        return

    extracted = split_quotes(args[1])

    if len(extracted) >= 2:
        # set trigger -> lower, so as to avoid adding duplicate filters with different cases
        keyword = extracted[0].lower()
        content = extracted[1]

    else:
        return

    # Note: perhaps handlers can be removed somehow using sql.get_chat_filters
    for handler in dispatcher.handlers.get(WARN_HANDLER_GROUP, []):
        if handler.filters == (keyword, chat.id):
            dispatcher.remove_handler(handler, WARN_HANDLER_GROUP)

    sql.add_warn_filter(chat.id, keyword, content)

    if conn:
        text = tl(
            update.effective_message,
            "Peringatkan handler yang ditambahkan untuk '{}' pada *{}*!"
        ).format(keyword, chat_name)
    else:
        text = tl(
            update.effective_message,
            "Peringatkan handler yang ditambahkan untuk '{}'!").format(keyword)
    send_message(update.effective_message, text, parse_mode="markdown")
    raise DispatcherHandlerStop
예제 #7
0
def list_warn_filters(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 = 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

    all_handlers = sql.get_chat_warn_triggers(chat.id)

    if not all_handlers:
        if conn:
            text = tl(
                update.effective_message,
                "Tidak ada filter peringatan aktif di *{}*!").format(chat_name)
        else:
            text = tl(update.effective_message,
                      "Tidak ada filter peringatan aktif di sini!")
        send_message(update.effective_message, text, parse_mode="markdown")
        return

    filter_list = tl(update.effective_message, "CURRENT_WARNING_FILTER_STRING")
    if conn:
        filter_list = filter_list.replace(
            tl(update.effective_message, 'obrolan ini'),
            tl(update.effective_message, 'obrolan *{}*').format(chat_name))
    for keyword in all_handlers:
        entry = " - {}\n".format(html.escape(keyword))
        if len(entry) + len(filter_list) > telegram.MAX_MESSAGE_LENGTH:
            send_message(update.effective_message,
                         filter_list,
                         parse_mode=ParseMode.HTML)
            filter_list = entry
        else:
            filter_list += entry

    if not filter_list == tl(update.effective_message,
                             "CURRENT_WARNING_FILTER_STRING"):
        send_message(update.effective_message,
                     filter_list,
                     parse_mode=ParseMode.HTML)
예제 #8
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)
        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

        text = build_curr_disabled(chat.id)
        send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN)
예제 #9
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."
            ))
예제 #10
0
def lock_warns(update, context):
	args = context.args
	chat = update.effective_chat  # type: Optional[Chat]
	user = update.effective_user

	# Connection check
	conn = connected(context.bot, update, chat, user.id, need_admin=True)
	if conn:
		chat = dispatcher.bot.getChat(conn)
		chat_id = conn
		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)
예제 #11
0
def timeout_mode(update, context):
	chat = update.effective_chat  # type: Optional[Chat]
	user = update.effective_user  # type: Optional[User]
	msg = update.effective_message  # type: Optional[Message]
	args = context.args

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

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

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

    conn = connected(context.bot, update, chat, user.id)
    if not conn == False:
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        chat_id = update.effective_chat.id
        if chat.type == "private":
            chat_name = tl(update.effective_message, "catatan lokal")
        else:
            chat_name = chat.title

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

    chat_filters = sql.get_chat_triggers(chat_id)

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

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

    send_message(
        update.effective_message,
        "Itu bukan filter aktif - jalankan /filter untuk semua filter aktif.")
예제 #13
0
def flood(update, context):
    chat = update.effective_chat
    user = update.effective_user

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

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

    conn = connected(context.bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if update.effective_message.chat.type == "private":
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "You can do this command in groups, not PM"))
            return ""
        chat = update.effective_chat
        chat_name = update.effective_message.chat.title

    if chat.username:
        send_message(update.effective_message, chat.username)
    elif chat.type == chat.SUPERGROUP or chat.type == chat.CHANNEL:
        bot_member = chat.get_member(context.bot.id)
        if bot_member.can_invite_users:
            invitelink = context.bot.exportChatInviteLink(chat.id)
            send_message(update.effective_message, invitelink)
        else:
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "I don't have access to the invite link, try changing my permissions!"
                ))
    else:
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "I can only give you invite links for supergroups and channels, sorry!"
            ))
예제 #15
0
def list_handlers(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]

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

    all_handlers = sql.get_chat_triggers(chat_id)

    if not all_handlers:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Tidak ada filter di {}!").format(chat_name))
        return

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

    send_message(update.effective_message,
                 filter_list.format(chat_name),
                 parse_mode=telegram.ParseMode.MARKDOWN)
예제 #16
0
def unpin(update, context):
    chat = update.effective_chat
    user = update.effective_user  # type: Optional[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,
                tl(update.effective_message,
                   "You can do this command in groups, not PM"))
            return ""
        chat = update.effective_chat
        chat_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title

    try:
        context.bot.unpinChatMessage(chat.id)
        if conn:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "I have unpin the message in the group {}").format(
                       chat_name))
    except BadRequest as excp:
        if excp.message == "Chat_not_modified":
            pass
        else:
            raise

    return "<b>{}:</b>" \
        "\n#UNPINNED" \
        "\n<b>Admin:</b> {}".format(html.escape(chat.title),
               mention_html(user.id, user.first_name))
예제 #17
0
def list_locks(update, context):
	chat = update.effective_chat  # type: Optional[Chat]
	user = update.effective_user

	# Connection check
	conn = connected(context.bot, update, chat, user.id, need_admin=True)
	if conn:
		chat = dispatcher.bot.getChat(conn)
		chat_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)
예제 #18
0
def blacklist_mode(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    msg = update.effective_message  # type: Optional[Message]
    args = context.args

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

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

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

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

    conn = connected(context.bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_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 ""
예제 #21
0
def unmute(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    args = context.args

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

    conn = connected(context.bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
        text = tl(update.effective_message,
                  "Pengguna ini sudah bisa untuk berbicara pada *{}*.").format(
                      chat_name)
        text2 = tl(update.effective_message,
                   "Dia telah disuarakan pada *{}*.").format(chat_name)
    else:
        if update.effective_message.chat.type == "private":
            update.effective_send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Anda bisa lakukan command ini pada grup, bukan pada PM"))
            return ""
        chat = update.effective_chat
        chat_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title
        text = tl(update.effective_message,
                  "Pengguna ini sudah bisa untuk berbicara.")
        text2 = tl(update.effective_message, "He has been unmuted.")

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

    member = chat.get_member(int(user_id))

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

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

    return ""
예제 #22
0
def unblackliststicker(update, context):
	msg = update.effective_message  # type: Optional[Message]
	chat = update.effective_chat  # type: Optional[Chat]
	user = update.effective_user  # type: Optional[User]
	words = msg.text.split(None, 1)

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


	if len(words) > 1:
		text = words[1].replace('https://t.me/addstickers/', '')
		to_unblacklist = list(set(trigger.strip() for trigger in text.split("\n") if trigger.strip()))
		successful = 0
		for trigger in to_unblacklist:
			success = sql.rm_from_stickers(chat_id, trigger.lower())
			if success:
				successful += 1

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

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

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

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

		if success:
			send_message(update.effective_message, tl(update.effective_message, "Stiker <code>{}</code> dihapus dari daftar hitam di <b>{}</b>!").format(trigger, chat_name),
							   parse_mode=ParseMode.HTML)
		else:
			send_message(update.effective_message, tl(update.effective_message, "{} tidak ada di daftar hitam stiker...!").format(trigger))
	else:
		send_message(update.effective_message, tl(update.effective_message, "Beri tahu saya stiker apa yang ingin Anda tambahkan ke daftar hitam stiker."))
예제 #23
0
def filters(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    msg = update.effective_message  # type: Optional[Message]
    args = msg.text.split(
        None,
        1)  # use python's maxsplit to separate Cmd, keyword, and reply_text

    conn = connected(context.bot, update, chat, user.id)
    if not conn == False:
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        chat_id = update.effective_chat.id
        if chat.type == "private":
            chat_name = tl(update.effective_message, "catatan lokal")
        else:
            chat_name = chat.title

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

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

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

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

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

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

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

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

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

    send_message(update.effective_message,
                 tl(update.effective_message,
                    "Handler '{}' ditambahkan di *{}*!").format(
                        keyword, chat_name),
                 parse_mode=telegram.ParseMode.MARKDOWN)
    raise DispatcherHandlerStop
예제 #24
0
def temp_mute(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    args = context.args

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

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

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

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

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

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

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

    if not reason:
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Anda belum menetapkan waktu untuk menonaktifkan pengguna ini!"
            ))
        return ""

    split_reason = reason.split(None, 1)

    time_val = split_reason[0].lower()
    if len(split_reason) > 1:
        reason = split_reason[1]
    else:
        reason = ""

    mutetime = extract_time(message, time_val)

    if not mutetime:
        return ""

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

    try:
        if member.can_send_messages is None or member.can_send_messages:
            context.bot.restrict_chat_member(
                chat.id,
                user_id,
                until_date=mutetime,
                permissions=ChatPermissions(can_send_messages=False))
            if conn:
                text = tl(update.effective_message,
                          "Dibisukan untuk *{}* pada *{}*!").format(
                              time_val, chat_name)
            else:
                text = tl(update.effective_message,
                          "Dibisukan untuk *{}*!").format(time_val)
            send_message(update.effective_message, text, parse_mode="markdown")
            return log
        else:
            send_message(
                update.effective_message,
                tl(update.effective_message, "Pengguna ini sudah dibungkam."))

    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            send_message(update.effective_message,
                         tl(update.effective_message,
                            "Dibisukan untuk *{}*!").format(time_val),
                         quote=False)
            return log
        else:
            LOGGER.warning(update)
            LOGGER.exception("ERROR muting user %s in chat %s (%s) due to %s",
                             user_id, chat.title, chat.id, excp.message)
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Yah sial, aku tidak bisa membisukan pengguna itu."))

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

    user_id = extract_user(message, args)
    if not user_id or user_id == "error":
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "You'll need to either give me a username to mute, or reply to someone to be muted."
            ))
        return ""

    conn = connected(context.bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
        text = tl(update.effective_message,
                  "Muted on *{}*! 😆").format(chat_name)
    else:
        if update.effective_message.chat.type == "private":
            update.effective_send_message(
                update.effective_message,
                tl(update.effective_message,
                   "You can do this command in groups, not PM"))
            return ""
        chat = update.effective_chat
        chat_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title
        text = tl(update.effective_message, "Muted! 😆")

    if user_id == context.bot.id:
        send_message(update.effective_message,
                     tl(update.effective_message, "I'm not muting myself!"))
        return ""

    check = context.bot.getChatMember(chat.id, user.id)
    if check['can_restrict_members'] == False:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "You have no right to restrict someone."))
        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,
                   "Afraid I can't stop an admin from talking!"))

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

        else:
            send_message(
                update.effective_message,
                tl(update.effective_message, "This user is already muted!"))
    else:
        send_message(
            update.effective_message,
            tl(update.effective_message, "This user isn't in the chat!"))

    return ""
예제 #26
0
def permanent_pin_set(update, context):
    user = update.effective_user  # type: Optional[User]
    chat = update.effective_chat  # type: Optional[Chat]
    args = context.args

    conn = connected(context.bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        if not args:
            get_permapin = sql.get_permapin(chat_id)
            text_maker = tl(update.effective_message,
                            "Permanen pin saat ini di atur: `{}`").format(
                                bool(int(get_permapin)))
            if get_permapin:
                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)
                text_maker += tl(
                    update.effective_message,
                    "\nUntuk menonaktifkan permanen pin: `/permanentpin off`")
                text_maker += tl(
                    update.effective_message,
                    "\n\n[Pesan permanen pin ada disini]({})").format(old_pin)
            send_message(update.effective_message,
                         tl(update.effective_message, text_maker),
                         parse_mode="markdown")
            return ""
        prev_message = args[0]
        if prev_message == "off":
            sql.set_permapin(chat_id, 0)
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Permanen pin telah di nonaktifkan!"))
            return
        if "/" in prev_message:
            prev_message = prev_message.split("/")[-1]
    else:
        if update.effective_message.chat.type == "private":
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "You can do this command in groups, not PM"))
            return ""
        chat = update.effective_chat
        chat_id = update.effective_chat.id
        if update.effective_message.reply_to_message:
            prev_message = update.effective_message.reply_to_message.message_id
        elif len(args) >= 1 and args[0] == "off":
            sql.set_permapin(chat.id, 0)
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Permanen pin telah di nonaktifkan!"))
            return
        else:
            get_permapin = sql.get_permapin(chat_id)
            text_maker = tl(update.effective_message,
                            "Permanen pin saat ini di atur: `{}`").format(
                                bool(int(get_permapin)))
            if get_permapin:
                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)
                text_maker += tl(
                    update.effective_message,
                    "\nUntuk menonaktifkan permanen pin: `/permanentpin off`")
                text_maker += tl(
                    update.effective_message,
                    "\n\n[Pesan permanen pin ada disini]({})").format(old_pin)
            send_message(update.effective_message,
                         text_maker,
                         parse_mode="markdown")
            return ""

    is_group = chat.type != "private" and chat.type != "channel"

    if prev_message and is_group:
        sql.set_permapin(chat.id, prev_message)
        send_message(
            update.effective_message,
            tl(update.effective_message, "Permanent pin berhasil di atur!"))
        return "<b>{}:</b>" \
            "\n#PERMANENT_PIN" \
            "\n<b>Admin:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name))

    return ""
예제 #27
0
def demote(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    message = update.effective_message  # type: Optional[Message]
    user = update.effective_user  # type: Optional[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,
                tl(update.effective_message,
                   "You can do this command in groups, not PM"))
            return ""
        chat = update.effective_chat
        chat_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title

    user_id = extract_user(message, args)
    if not user_id:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "You don't seem to be referring to a user."))
        return ""
    if user_id == "error":
        send_message(update.effective_message,
                     tl(update.effective_message, "Error: Unknown user!"))
        return ""

    user_member = chat.get_member(user_id)
    if user_member.status == 'creator':
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "This person CREATED the chat, how would I demote them?"))
        return ""

    if not user_member.status == 'administrator':
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "How am I going to demote someone who hasn't been promoted?"))
        return ""

    if user_id == context.bot.id:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "I can't demote myself! Get an admin to do it for me."))
        return ""

    try:
        context.bot.promoteChatMember(int(chat.id),
                                      int(user_id),
                                      can_change_info=False,
                                      can_post_messages=False,
                                      can_edit_messages=False,
                                      can_delete_messages=False,
                                      can_invite_users=False,
                                      can_restrict_members=False,
                                      can_pin_messages=False,
                                      can_promote_members=False)
        send_message(
            update.effective_message,
            tl(update.effective_message, "Successfully demoted! 😎"))
        return "<b>{}:</b>" \
            "\n#DEMOTED" \
            "\n<b>Admin:</b> {}" \
            "\n<b>User:</b> {}".format(html.escape(chat.title),
                  mention_html(user.id, user.first_name),
                  mention_html(user_member.user.id, user_member.user.first_name))

    except BadRequest:
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Could not demote. I might not be admin, or the admin status "
                "was appointed by another user, so I can't act upon them!"))
        return ""
예제 #28
0
def promote(update, context):
    chat_id = update.effective_chat.id
    message = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    args = context.args

    conn = connected(context.bot, update, chat, user.id, need_admin=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,
                   "You can do this command in groups, not PM"))
            return ""
        chat = update.effective_chat
        chat_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title

    user_id = extract_user(message, args)
    if not user_id:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "You don't seem to be referring to a user."))
        return ""
    if user_id == "error":
        send_message(update.effective_message,
                     tl(update.effective_message, "Error: Unknown user!"))
        return ""

    user_member = chat.get_member(user_id)
    if user_member.status == 'administrator' or user_member.status == 'creator':
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "How am I meant to promote someone that's already an admin?"))
        return ""

    if user_id == context.bot.id:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "I can't promote myself! Get an admin to do it for me."))
        return ""

    # set same perms as bot - bot can't assign higher perms than itself!
    bot_member = chat.get_member(context.bot.id)

    try:
        context.bot.promote_chat_member(
            chat_id,
            user_id,
            # can_change_info=bot_member.can_change_info,
            can_post_messages=bot_member.can_post_messages,
            can_edit_messages=bot_member.can_edit_messages,
            can_delete_messages=bot_member.can_delete_messages,
            can_invite_users=bot_member.can_invite_users,
            can_restrict_members=bot_member.can_restrict_members,
            can_pin_messages=bot_member.can_pin_messages,
            # can_promote_members=bot_member.can_promote_members
        )
    except BadRequest as error:
        if error.message == "Bot_groups_blocked":
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Failed to promote: Bot was locked"))
        else:
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Cannot promote users, maybe I am not admin or do not have permission to promote users."
                ))
        return

    send_message(update.effective_message,
                 tl(update.effective_message, "Successfully promoted! 😉"))

    return "<b>{}:</b>" \
        "\n#PROMOTED" \
        "\n<b>Admin:</b> {}" \
        "\n<b>User:</b> {}".format(html.escape(chat.title),
              mention_html(user.id, user.first_name),
              mention_html(user_member.user.id, user_member.user.first_name))
예제 #29
0
def adminlist(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    args = context.args

    conn = connected(context.bot, update, chat, user.id, need_admin=False)
    if conn:
        chat = 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,
                   "You can do this command in groups, not PM"))
            return ""
        chat = update.effective_chat
        chat_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title

    administrators = context.bot.getChatAdministrators(chat_id)
    text = tl(update.effective_message, "Admin in *{}*:").format(
        update.effective_chat.title
        or tl(update.effective_message, "chat ini"))
    for admin in administrators:
        user = admin.user
        status = admin.status
        if user.first_name == '':
            name = tl(update.effective_message, "☠ Deleted Account")
        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 🔱 Admins:".format(name)
    for admin in administrators:
        user = admin.user
        status = admin.status
        if user.first_name == '':
            name = tl(update.effective_message, "☠ Deleted Account")
        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)

    try:
        send_message(update.effective_message,
                     text,
                     parse_mode=ParseMode.MARKDOWN)
    except BadRequest:
        send_message(update.effective_message,
                     text,
                     parse_mode=ParseMode.MARKDOWN,
                     quote=False)
예제 #30
0
def pin(update, context):
    user = update.effective_user  # type: Optional[User]
    chat = update.effective_chat  # type: Optional[Chat]
    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
        if len(args) <= 1:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Use /pin <notify/loud/silent/violent> <message link>"))
            return ""
        prev_message = args[1]
        if "/" in prev_message:
            prev_message = prev_message.split("/")[-1]
    else:
        if update.effective_message.chat.type == "private":
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "You can do this command in groups, not PM"))
            return ""
        chat = update.effective_chat
        chat_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title
        if update.effective_message.reply_to_message:
            prev_message = update.effective_message.reply_to_message.message_id
        else:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Reply to a message for pin that message in this group"))
            return ""

    is_group = chat.type != "private" and chat.type != "channel"

    is_silent = True
    if len(args) >= 1:
        is_silent = not (args[0].lower() == 'silent' or args[0].lower()
                         == 'off' or args[0].lower() == 'mute')

    if prev_message and is_group:
        try:
            context.bot.pinChatMessage(chat.id,
                                       prev_message,
                                       disable_notification=is_silent)
            if conn:
                send_message(
                    update.effective_message,
                    tl(update.effective_message,
                       "I have pinned messages in the group {}").format(
                           chat_name))
        except BadRequest as excp:
            if excp.message == "Chat_not_modified":
                pass
            else:
                raise
        return "<b>{}:</b>" \
            "\n#PINNED" \
            "\n<b>Admin:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name))

    return ""