Esempio n. 1
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)
Esempio n. 2
0
def report_alt(update, context) -> str:
	message = update.effective_message  # type: Optional[Message]
	chat = update.effective_chat  # type: Optional[Chat]
	user = update.effective_user  # type: Optional[User]

	if chat and message.reply_to_message and sql.chat_should_report(chat.id):
		reported_user = message.reply_to_message.from_user
		admin_list = chat.get_administrators()

		msg = tl(update.effective_message, "<b>{}:</b>" \
			  "\n<b>Pengguna yang dilaporkan:</b> {} (<code>{}</code>)" \
			  "\n<b>Dilaporkan oleh:</b> {} (<code>{}</code>)").format(html.escape(chat.title),
																	  mention_html(
																		  reported_user.id,
																		  reported_user.first_name),
																	  reported_user.id,
																	  mention_html(user.id,
																				   user.first_name),
																	  user.id)
		all_admins = []
		for admin in admin_list:
			if admin.user.is_bot:  # don't tag bot
				continue

			if sql.user_should_report(admin.user.id):
				all_admins.append("<a href='tg://user?id={}'>⁣</a>".format(admin.user.id))

		context.bot.send_message(chat.id, tl(update.effective_message, "⚠️ {} <b>telah di laporkan ke admin!</b>{}").format(
					mention_html(reported_user.id, reported_user.first_name),
					"".join(all_admins)), parse_mode=ParseMode.HTML, reply_to_message_id=message.reply_to_message.message_id)
		return msg

	return ""
Esempio n. 3
0
def __chat_settings__(chat_id, user_id):
    administrators = dispatcher.bot.getChatAdministrators(chat_id)
    chat = dispatcher.bot.getChat(chat_id)
    text = "Admin in *{}*:".format(chat.title or "chat ini")
    for admin in administrators:
        user = admin.user
        status = admin.status
        if user.first_name == '':
            name = tl(user_id, "☠ 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 🔱 Admin:".format(name)
    for admin in administrators:
        user = admin.user
        status = admin.status
        if user.first_name == '':
            name = tl(user_id, "☠ 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)
    text += tl(user_id, "\n\nYou are *{}*").format(
        dispatcher.bot.get_chat_member(chat_id, user_id).status)
    return text
Esempio n. 4
0
def connection_chat(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=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")
Esempio n. 5
0
def button(update, context):
    query = update.callback_query  # type: Optional[CallbackQuery]
    user = update.effective_user  # type: Optional[User]
    match = re.match(r"rm_warn\((.+?)\)", query.data)
    if match:
        user_id = match.group(1)
        chat = update.effective_chat  # type: Optional[Chat]
        res = sql.remove_warn(user_id, chat.id)
        if res:
            update.effective_message.edit_text(tl(
                update.effective_message,
                "Peringatkan dihapus oleh {}.").format(
                    mention_html(user.id, user.first_name)),
                                               parse_mode=ParseMode.HTML)
            user_member = chat.get_member(user_id)
            return "<b>{}:</b>" \
                   "\n#UNWARN" \
                   "\n<b>Admin:</b> {}" \
                   "\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title),
                                                                mention_html(user.id, user.first_name),
                                                                mention_html(user_member.user.id, user_member.user.first_name),
                                                                user_member.user.id)
        else:
            update.effective_message.edit_text(tl(
                update.effective_message,
                "Pengguna sudah tidak memiliki peringatan.").format(
                    mention_html(user.id, user.first_name)),
                                               parse_mode=ParseMode.HTML)

    return ""
Esempio n. 6
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?"))
Esempio n. 7
0
 def __chat_settings__(chat_id, user_id):
     log_channel = sql.get_chat_log_channel(chat_id)
     if log_channel:
         log_channel_info = dispatcher.bot.get_chat(log_channel)
         return tl(user_id, "Grup ini memiliki semua log yang dikirim ke: {} (`{}`)").format(escape_markdown(log_channel_info.title),
                                                                         log_channel)
     return tl(user_id, "Tidak ada saluran masuk yang ditetapkan untuk grup ini!")
Esempio n. 8
0
def connected(bot, update, chat, user_id, need_admin=True):
    user = update.effective_user  # type: Optional[User]

    if chat.type == chat.PRIVATE and sql.get_connected_chat(user_id):
        conn_id = sql.get_connected_chat(user_id).chat_id
        getstatusadmin = bot.get_chat_member(
            conn_id, update.effective_message.from_user.id)
        isadmin = getstatusadmin.status in ('administrator', 'creator')
        ismember = getstatusadmin.status in ('member')
        isallow = sql.allow_connect_to_chat(conn_id)
        if (isadmin) or (isallow and ismember) or (user.id in SUDO_USERS):
            if need_admin == True:
                if getstatusadmin.status in (
                        'administrator', 'creator') or user_id in SUDO_USERS:
                    return conn_id
                else:
                    send_message(
                        update.effective_message,
                        languages.tl(
                            update.effective_message,
                            "Anda harus menjadi admin dalam grup yang terhubung!"
                        ))
            else:
                return conn_id
        else:
            send_message(
                update.effective_message,
                languages.tl(
                    update.effective_message,
                    "Grup mengubah koneksi hak atau Anda bukan admin lagi.\nSaya putuskan koneksi Anda."
                ))
            disconnect_chat(update, bot)
    else:
        return False
Esempio n. 9
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!"))
Esempio n. 10
0
def purge(update, context):
    args = context.args
    msg = update.effective_message  # type: Optional[Message]
    if msg.reply_to_message:
        user = update.effective_user  # type: Optional[User]
        chat = update.effective_chat  # type: Optional[Chat]
        if user_can_delete(chat, user, context.bot.id):
            message_id = msg.reply_to_message.message_id
            if args and args[0].isdigit():
                delete_to = message_id + int(args[0])
            else:
                delete_to = msg.message_id - 1
            for m_id in range(delete_to, message_id - 1,
                              -1):  # Reverse iteration over message ids
                try:
                    context.bot.deleteMessage(chat.id, m_id)
                except BadRequest as err:
                    if err.message == "Message can't be deleted":
                        send_message(
                            update.effective_message,
                            tl(
                                update.effective_message,
                                "Tidak dapat menghapus semua pesan. Pesannya mungkin terlalu lama, saya mungkin "
                                "tidak memiliki hak menghapus, atau ini mungkin bukan supergrup."
                            ))

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

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

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

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

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

    return ""
Esempio n. 11
0
    def setlog(update, context):
        message = update.effective_message  # type: Optional[Message]
        chat = update.effective_chat  # type: Optional[Chat]
        if chat.type == chat.CHANNEL:
            send_message(update.effective_message, tl(update.effective_message, "Sekarang, teruskan /setlog ke grup yang Anda ingin ikat saluran ini!"))

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

        else:
            send_message(update.effective_message, tl(update.effective_message, "Langkah-langkah untuk mengatur saluran log adalah:\n"
                               " - tambahkan bot ke saluran yang diinginkan\n"
                               " - Kirimkan /setlog ke saluran\n"
                               " - Teruskan /setlog ke grup\n"))
Esempio n. 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(context.bot, report_target)
		if not a:
			context.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:
				context.bot.unbanChatMember(report_chat, report_target)
				context.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)
				context.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:
				context.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:
				context.bot.kickChatMember(report_chat, report_target)
				context.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)
				context.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:
				context.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:
				context.bot.deleteMessage(report_chat, report_target)
				context.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:
				context.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":
		context.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)
Esempio n. 13
0
def start(update, context):
    if update.effective_chat.type == "private":
        args = context.args
        if len(args) >= 1:
            if args[0].lower() == "help":
                send_help(update.effective_chat.id, tl(update.effective_message, HELP_STRINGS))

            elif args[0].lower() == "get_notes":
                update.effective_message.reply_text(tl(update.effective_message, "Now you can get notes in group."))

            elif args[0].lower().startswith("stngs_"):
                match = re.match("stngs_(.*)", args[0].lower())
                chat = dispatcher.bot.getChat(match.group(1))

                if is_user_admin(chat, update.effective_user.id):
                    send_settings(match.group(1), update.effective_user.id, False)
                else:
                    send_settings(match.group(1), update.effective_user.id, True)

            elif args[0][1:].isdigit() and "rules" in IMPORTED:
                IMPORTED["rules"].send_rules(update, args[0], from_pm=True)

            elif args[0][:4] == "wiki":
                wiki = args[0].split("-")[1].replace('_', ' ')
                message = update.effective_message
                getlang = langsql.get_lang(message)
                if getlang == "pt":
                    wikipedia.set_lang("pt")
                pagewiki = wikipedia.page(wiki)
                judul = pagewiki.title
                summary = pagewiki.summary
                if len(summary) >= 4096:
                    summary = summary[:4000]+"..."
                message.reply_text("<b>{}</b>\n{}".format(judul, summary), parse_mode=ParseMode.HTML,
                    reply_markup=InlineKeyboardMarkup(
                            [[InlineKeyboardButton(text=tl(update.effective_message, "Read on Wikipedia"), url=pagewiki.url)]]))

            elif args[0][:6].lower() == "verify":
                chat_id = args[0].split("_")[1]
                verify_welcome(update, context, chat_id)

            elif args[0][:6].lower() == "verify":
                chat_id = args[0].split("_")[1]
                verify_welcome(update, context, chat_id)

        else:
            first_name = update.effective_user.first_name
            buttons = InlineKeyboardMarkup(
                [[InlineKeyboardButton(text="📃 Half_SATAN's Docs", url="https://telegra.ph/")],
                [InlineKeyboardButton(text="⚙️ Connections", callback_data="main_connect")],
                [InlineKeyboardButton(text="🇺🇸 Language", callback_data="main_setlang"), InlineKeyboardButton(text="❓ Help", callback_data="help_back")]])
            update.effective_message.reply_text(
                tl(update.effective_message, PM_START_TEXT).format(escape_markdown(first_name), escape_markdown(context.bot.first_name), OWNER_ID),
                disable_web_page_preview=True,
                parse_mode=ParseMode.MARKDOWN,
                reply_markup=buttons)
    else:
        update.effective_message.reply_text(tl(update.effective_message, "Is there anything I can help? 😊"))
Esempio n. 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(chat_id, "Tidak ada perintah yang dinonaktifkan!")

        result = ""
        for cmd in disabled:
            result += " - `{}`\n".format(escape_markdown(cmd))
        return languages.tl(chat_id, "Perintah-perintah berikut saat ini dibatasi:\n{}").format(result)
Esempio n. 15
0
 def list_cmds(update, context):
     if DISABLE_CMDS + DISABLE_OTHER:
         result = ""
         for cmd in set(DISABLE_CMDS + DISABLE_OTHER):
             result += " - `{}`\n".format(escape_markdown(cmd))
         send_message(update.effective_message, languages.tl(update.effective_message, "Perintah berikut dapat diubah:\n{}").format(result),
                                             parse_mode=ParseMode.MARKDOWN)
     else:
         send_message(update.effective_message, languages.tl(update.effective_message, "Tidak ada perintah yang dapat dinonaktifkan."))
Esempio n. 16
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
Esempio n. 17
0
    def unsetlog(update, context):
        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:
            context.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!"))
Esempio n. 18
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, "This log channel has been deleted - unsetting."))
                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\nFormatting has been disabled due to an unexpected error."))
Esempio n. 19
0
def add_blacklist(update, context):
    msg = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    words = msg.text.split(None, 1)

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

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

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

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

    else:
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Beri tahu saya kata-kata apa yang ingin Anda hapus dari daftar hitam."
            ))
Esempio n. 20
0
    def logging(update, context):
        message = update.effective_message  # type: Optional[Message]
        chat = update.effective_chat  # type: Optional[Chat]

        log_channel = sql.get_chat_log_channel(chat.id)
        if log_channel:
            log_channel_info = context.bot.get_chat(log_channel)
            send_message(update.effective_message, 
                tl(update.effective_message, "These group have all logs sent to: {} (`{}`)").format(escape_markdown(log_channel_info.title),
                                                                         log_channel),
                parse_mode=ParseMode.MARKDOWN)

        else:
            send_message(update.effective_message, tl(update.effective_message, "Tidak ada saluran log yang telah ditetapkan untuk grup ini!"))
Esempio n. 21
0
def log_user(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    msg = update.effective_message  # type: Optional[Message]
    """text = msg.text if msg.text else ""
                uid = msg.from_user.id
                uname = msg.from_user.name
                print("{} | {} | {} | {}".format(text, uname, uid, chat.title))"""
    fed_id = fedsql.get_fed_id(chat.id)
    if fed_id:
        user = update.effective_user
        if user:
            fban, fbanreason, fbantime = fedsql.get_fban_user(fed_id, user.id)
            if fban:
                send_message(update.effective_message, languages.tl(update.effective_message, "Pengguna ini dilarang di federasi saat ini!\nAlasan: `{}`").format(fbanreason), parse_mode="markdown")
                try:
                    context.bot.kick_chat_member(chat.id, user.id)
                except:
                	print("Fban: cannot banned this user")

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

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

    if msg.forward_from:
        sql.update_user(msg.forward_from.id,
                        msg.forward_from.username)
Esempio n. 22
0
def shout(update, context):
    message = update.effective_message
    chat = update.effective_chat
    args = context.args

    noreply = False
    if message.reply_to_message:
        data = message.reply_to_message.text
    elif args:
        noreply = True
        data = " ".join(args)
    else:
        noreply = True
        data = tl(chat.id, "I need a message to meme.")

    msg = "```"
    result = []
    result.append(' '.join([s for s in data]))
    for pos, symbol in enumerate(data[1:]):
        result.append(symbol + ' ' + '  ' * pos + symbol)
    result = list("\n".join(result))
    result[0] = data[0]
    result = "".join(result)
    msg = "```\n" + result + "```"
    return update.effective_message.reply_text(msg, parse_mode="MARKDOWN")
Esempio n. 23
0
def deepfryer(update, context):
    message = update.effective_message
    chat = update.effective_chat
    if message.reply_to_message:
        data = message.reply_to_message.photo
        data2 = message.reply_to_message.sticker
    else:
        data = []
        data2 = []

    # check if message does contain media and cancel when not
    if not data and not data2:
        message.reply_text(tl(chat.id, "What am I supposed to do with this?!"))
        return

    # download last photo (highres) as byte array
    if data:
        photodata = data[len(data) - 1].get_file().download_as_bytearray()
        image = Image.open(io.BytesIO(photodata))
    elif data2:
        sticker = context.bot.get_file(data2.file_id)
        sticker.download('cache/sticker.png')
        image = Image.open("cache/sticker.png")

    # the following needs to be executed async (because dumb lib)
    bot = context.bot
    loop = asyncio.new_event_loop()
    loop.run_until_complete(
        process_deepfry(image, message.reply_to_message, bot, context))
    loop.close()
Esempio n. 24
0
def permanent_pin(update, context):
    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 == context.bot.id:
        try:
            to_del = context.bot.pinChatMessage(chat.id,
                                                get_permapin,
                                                disable_notification=True)
        except BadRequest:
            sql.set_permapin(chat.id, 0)
            if chat.username:
                old_pin = "https://t.me/{}/{}".format(chat.username,
                                                      get_permapin)
            else:
                old_pin = "https://t.me/c/{}/{}".format(
                    str(chat.id)[4:], get_permapin)
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "*Permanent pin error:*\nI can't pin messages here!\nMake sure I'm admin and can pin messages.\n\nPermanent pin disabled now, [here is your old pinned message]({})"
                ).format(old_pin),
                parse_mode="markdown")
            return

        if to_del:
            try:
                context.bot.deleteMessage(chat.id, message.message_id + 1)
            except BadRequest:
                print("Permanent pin error: cannot delete pin msg")
Esempio n. 25
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
Esempio n. 26
0
 def pin_rights(update, context, *args, **kwargs):
     if update.effective_chat.get_member(context.bot.id).can_pin_messages:
         return func(update, context, *args, **kwargs)
     else:
         update.effective_message.reply_text(
             languages.tl(
                 update.effective_message, "I can't pin messages here! "
                 "Make sure I'm admin and can pin messages."))
Esempio n. 27
0
def pat(update, context):
    args = context.args
    chat_id = update.effective_chat.id
    msg = str(update.message.text)
    try:
        msg = msg.split(" ", 1)[1]
    except IndexError:
        msg = ""
    msg_id = update.effective_message.reply_to_message.message_id if update.effective_message.reply_to_message else update.effective_message.message_id
    pats = []
    pats = json.loads(urllib.request.urlopen(urllib.request.Request(
    'http://headp.at/js/pats.json',
    headers={'User-Agent': 'Mozilla/5.0 (X11; U; Linux i686) '
         'Gecko/20071127 Firefox/2.0.0.11'}
    )).read().decode('utf-8'))
    if "@" in msg and len(msg) > 5:
        context.bot.send_photo(chat_id, f'https://headp.at/pats/{urllib.parse.quote(random.choice(pats))}', caption=msg)
    else:
        context.bot.send_photo(chat_id, f'https://headp.at/pats/{urllib.parse.quote(random.choice(pats))}', reply_to_message_id=msg_id)
    #if msg.from_user.username:
    #    curr_user = "******" + escape_markdown(msg.from_user.username)
    #else:
    curr_user = "******".format(mention_markdown(msg.from_user.id, msg.from_user.first_name))

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

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

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

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

    send_message(update.effective_message, repl, parse_mode=ParseMode.MARKDOWN)
Esempio n. 28
0
def stickerid(update, context):
    msg = update.effective_message
    if msg.reply_to_message and msg.reply_to_message.sticker:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Hai {}, Id stiker yang anda balas adalah :\n```{}```").format(
                   mention_markdown(msg.from_user.id,
                                    msg.from_user.first_name),
                   msg.reply_to_message.sticker.file_id),
            parse_mode=ParseMode.MARKDOWN)
    else:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Tolong balas pesan stiker untuk mendapatkan id stiker"),
            parse_mode=ParseMode.MARKDOWN)
Esempio n. 29
0
    def disable_del(update, context):
        msg = update.effective_message
        chat = update.effective_chat

        if len(msg.text.split()) >= 2:
            args = msg.text.split(None, 1)[1]
            if args == "yes" or args == "on" or args == "ya":
                sql.disabledel_set(chat.id, True)
                send_message(update.effective_message, languages.tl(update.effective_message, "Ketika command di nonaktifkan, maka saya *akan menghapus* pesan command tsb."), parse_mode="markdown")
                return
            elif args == "no" or args == "off":
                sql.disabledel_set(chat.id, False)
                send_message(update.effective_message, languages.tl(update.effective_message, "Saya *tidak akan menghapus* pesan dari command yang di nonaktifkan."), parse_mode="markdown")
                return
            else:
                send_message(update.effective_message, languages.tl(update.effective_message, "Argumen tidak dikenal - harap gunakan 'yes', atau 'no'."))
        else:
            send_message(update.effective_message, languages.tl(update.effective_message, "Opsi disable del saat ini: *{}*").format("Enabled" if sql.is_disable_del(chat.id) else "Disabled"), parse_mode="markdown")
Esempio n. 30
0
 def delete_rights(update, context, *args, **kwargs):
     if can_delete(update.effective_chat, context.bot.id):
         return func(update, context, *args, **kwargs)
     else:
         update.effective_message.reply_text(
             languages.tl(
                 update.effective_message, "I can't delete messages here! "
                 "Make sure I'm admin and can delete other user's messages."
             ))