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

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

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

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

		if added == 0:
			return

		if len(to_blacklist) == 1:
			send_message(update.effective_message, tl(update.effective_message, "Sticker <code>{}</code> added to blacklist sticker on <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> sticker added to the sticker blacklist on <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, "Invalid sticker!"))
			return
		try:
			get = bot.getStickerSet(trigger)
			sql.add_to_stickers(chat_id, trigger.lower())
			added += 1
		except BadRequest:
			send_message(update.effective_message, tl(update.effective_message, "Sticker `{}` can not be found!").format(trigger), parse_mode="markdown")

		if added == 0:
			return

		send_message(update.effective_message, tl(update.effective_message, "Sticker <code>{}</code> added to blacklist sticker on <b>{}</b>!").format(trigger, chat_name), parse_mode=ParseMode.HTML)
	else:
		send_message(update.effective_message, tl(update.effective_message, "Tell me what stickers you want to add to the sticker blacklist."))
Esempio n. 2
0
def connection_chat(bot: Bot, update: Update):

    chat = update.effective_chat
    user = update.effective_user

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

    conn = connected(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":
            return
        chat = update.effective_chat
        chat_name = update.effective_message.chat.title

    if conn:
        message = "You are currently connected with {}.\n".format(chat_name)
    else:
        message = "You are currently not connected in any group.\n"
    send_message(update.effective_message, message, parse_mode="markdown")
Esempio n. 3
0
def set_language(bot, update):
    msg = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]

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

    getlang = sql.get_lang(chat.id)
    if getlang == 'None' or not getlang:
        if msg.from_user.language_code:
            sql.set_lang(msg.chat.id, msg.from_user.language_code)
            getlang = msg.from_user.language_code
        else:
            if msg.chat.type == "private":
                sql.set_lang(msg.chat.id, 'en')
                getlang = 'en'
            else:
                sql.set_lang(msg.chat.id, 'id')
                getlang = 'id'
    loaded_langs = []
    counter = 0

    for x in LOADED_LANGS_ID:
        if counter % 2 == 0:
            loaded_langs.append(
                InlineKeyboardButton(LANGS_TEXT[x],
                                     callback_data="set_lang({})".format(x)))
        else:
            loaded_langs.append(
                InlineKeyboardButton(LANGS_TEXT[x],
                                     callback_data="set_lang({})".format(x)))
        counter += 1

    loaded_langs = list(zip(loaded_langs[::2], loaded_langs[1::2]))

    keyboard = InlineKeyboardMarkup(loaded_langs)

    if chat.title:
        chatname = chat.title
    else:
        if chat.type == "private":
            chatname = user.first_name
        else:
            chatname = tl(update.effective_message, "obrolan saat ini")

    send_message(
        update.effective_message,
        tl(msg,
           "Bahasa di *{}* saat ini adalah:\n{}.\n\nPilih bahasa:").format(
               chatname, LANGS_TEXT[getlang]),
        parse_mode="markdown",
        reply_markup=keyboard)
Esempio n. 4
0
def help_connect_chat(bot: Bot, update: Update):

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

    if update.effective_message.chat.type != "private":
        send_message(update.effective_message,
                     "PM me with that command to get help.")
        return
    else:
        send_message(update.effective_message,
                     "All commands",
                     parse_mode="markdown")
Esempio n. 5
0
def disconnect_chat(bot: Bot, update: Update):

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

    if update.effective_chat.type == 'private':
        disconnection_status = sql.disconnect(
            update.effective_message.from_user.id)
        if disconnection_status:
            sql.disconnected_chat = send_message(update.effective_message,
                                                 "Disconnected from chat!")
        else:
            send_message(update.effective_message, "You're not connected!")
    else:
        send_message(update.effective_message,
                     "This command is only available in PM.")
Esempio n. 6
0
def connected(bot, update, chat, user_id, need_admin=True):

    user = update.effective_user
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id)

    if spam == True:
        return

    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) or (
                user.id in DEV_USERS):
            if need_admin == True:
                if getstatusadmin.status in (
                        'administrator', 'creator'
                ) or user_id in SUDO_USERS or user.id in DEV_USERS:
                    return conn_id
                else:
                    send_message(
                        update.effective_message,
                        "You must be an admin in the connected group!")
                    raise Exception("Not admin!")
            else:
                return conn_id
        else:
            send_message(
                update.effective_message,
                "The group changed the connection rights or you are no longer an admin.\nI've disconnected you."
            )
            disconnect_chat(bot, update)
            raise Exception("Not admin!")
    else:
        return False
Esempio n. 7
0
def blackliststicker(bot: Bot, update: Update, args: List[str]):
	msg = update.effective_message  # type: Optional[Message]
	chat = update.effective_chat  # type: Optional[Chat]
	user = update.effective_user  # type: Optional[User]

	spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message)
	if spam == True:
		return
		
	conn = connected(bot, update, chat, user.id, need_admin=False)
	if conn:
		chat_id = conn
		chat_name = dispatcher.bot.getChat(conn).title
	else:
		if chat.type == "private":
			return
		else:
			chat_id = update.effective_chat.id
			chat_name = chat.title
		
	sticker_list = tl(update.effective_message, "<b>Blacklist of stickers currently at {}:</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>Blacklist of stickers currently at{}:</b>\n").format(chat_name).format(chat_name):
			send_message(update.effective_message, tl(update.effective_message, "No sticker blacklist sticker on<b>{}</b>!").format(chat_name), parse_mode=ParseMode.HTML)
			return
	send_message(update.effective_message, text, parse_mode=ParseMode.HTML)
Esempio n. 8
0
def connect_chat(bot: Bot, update: Update, args: List[str]):

    chat = update.effective_chat
    user = update.effective_user

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

    if update.effective_chat.type == 'private':
        if len(args) >= 1:
            try:
                connect_chat = int(args[0])
                getstatusadmin = bot.get_chat_member(
                    connect_chat, update.effective_message.from_user.id)
            except ValueError:
                try:
                    connect_chat = str(args[0])
                    get_chat = bot.getChat(connect_chat)
                    connect_chat = get_chat.id
                    getstatusadmin = bot.get_chat_member(
                        connect_chat, update.effective_message.from_user.id)
                except BadRequest:
                    send_message(update.effective_message, "Invalid Chat ID!")
                    return
            except BadRequest:
                send_message(update.effective_message, "Invalid Chat ID!")
                return

            isadmin = getstatusadmin.status in ('administrator', 'creator')
            ismember = getstatusadmin.status in ('member')
            isallow = sql.allow_connect_to_chat(connect_chat)

            if (isadmin) or (isallow and ismember) or (
                    user.id in SUDO_USERS) or (user.id in DEV_USERS):
                connection_status = sql.connect(
                    update.effective_message.from_user.id, connect_chat)
                if connection_status:
                    conn_chat = dispatcher.bot.getChat(
                        connected(bot, update, chat, user.id,
                                  need_admin=False))
                    chat_name = conn_chat.title
                    send_message(
                        update.effective_message,
                        "Successfully connected to *{}*. Use /connection for see current available commands."
                        .format(chat_name),
                        parse_mode=ParseMode.MARKDOWN)
                    sql.add_history_conn(user.id, str(conn_chat.id), chat_name)
                else:
                    send_message(update.effective_message,
                                 "Connection failed!")
            else:
                send_message(update.effective_message,
                             "Connection to this chat is not allowed!")
        else:
            gethistory = sql.get_history_conn(user.id)
            if gethistory:
                buttons = [
                    InlineKeyboardButton(text="❎ Close button",
                                         callback_data="connect_close"),
                    InlineKeyboardButton(text="🧹 Clear history",
                                         callback_data="connect_clear")
                ]
            else:
                buttons = []
            conn = connected(bot, update, chat, user.id, need_admin=False)
            if conn:
                connectedchat = dispatcher.bot.getChat(conn)
                text = "You are connected to *{}* (`{}`)".format(
                    connectedchat.title, conn)
                buttons.append(
                    InlineKeyboardButton(text="πŸ”Œ Disconnect",
                                         callback_data="connect_disconnect"))
            else:
                text = "Write the chat ID or tag to connect!"
            if gethistory:
                text += "\n\n*Connection history:*\n"
                text += "β•’β•β•β•γ€Œ *Info* 」\n"
                text += "β”‚  Sorted: `Newest`\n"
                text += "β”‚\n"
                buttons = [buttons]
                for x in sorted(gethistory.keys(), reverse=True):
                    htime = time.strftime("%d/%m/%Y", time.localtime(x))
                    text += "β•žβ•γ€Œ *{}* 」\nβ”‚   `{}`\nβ”‚   `{}`\n".format(
                        gethistory[x]['chat_name'], gethistory[x]['chat_id'],
                        htime)
                    text += "β”‚\n"
                    buttons.append([
                        InlineKeyboardButton(
                            text=gethistory[x]['chat_name'],
                            callback_data="connect({})".format(
                                gethistory[x]['chat_id']))
                    ])
                text += "β•˜β•β•γ€Œ Total {} Chats 」".format(
                    str(len(gethistory)) +
                    " (max)" if len(gethistory) == 5 else str(len(gethistory)))
                conn_hist = InlineKeyboardMarkup(buttons)
            elif buttons:
                conn_hist = InlineKeyboardMarkup([buttons])
            else:
                conn_hist = None
            send_message(update.effective_message,
                         text,
                         parse_mode="markdown",
                         reply_markup=conn_hist)

    else:
        getstatusadmin = bot.get_chat_member(
            chat.id, update.effective_message.from_user.id)
        isadmin = getstatusadmin.status in ('administrator', 'creator')
        ismember = getstatusadmin.status in ('member')
        isallow = sql.allow_connect_to_chat(chat.id)
        if (isadmin) or (isallow and ismember) or (user.id in SUDO_USERS) or (
                user.id in DEV_USERS):
            connection_status = sql.connect(
                update.effective_message.from_user.id, chat.id)
            if connection_status:
                chat_name = dispatcher.bot.getChat(chat.id).title
                send_message(
                    update.effective_message,
                    "Successfully connected to *{}*.".format(chat_name),
                    parse_mode=ParseMode.MARKDOWN)
                try:
                    sql.add_history_conn(user.id, str(chat.id), chat_name)
                    bot.send_message(
                        update.effective_message.from_user.id,
                        "You have connected with *{}*. Use /connection for see current available commands."
                        .format(chat_name),
                        parse_mode="markdown")
                except BadRequest:
                    pass
                except Unauthorized:
                    pass
            else:
                send_message(update.effective_message, "Connection failed!")
        else:
            send_message(update.effective_message,
                         "Connection to this chat is not allowed!")
Esempio n. 9
0
def blacklist_mode(bot: Bot, update: Update, args: List[str]):
	spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message)
	if spam == True:
		return
	chat = update.effective_chat  # type: Optional[Chat]
	user = update.effective_user  # type: Optional[User]
	msg = update.effective_message  # type: Optional[Message]

	conn = connected(bot, update, chat, user.id, need_admin=True)
	if conn:
		chat = dispatcher.bot.getChat(conn)
		chat_id = conn
		chat_name = dispatcher.bot.getChat(conn).title
	else:
		if update.effective_message.chat.type == "private":
			send_message(update.effective_message, tl(update.effective_message, "You can do this command in the group, not the 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, 'turn off')
			sql.set_blacklist_strength(chat_id, 0, "0")
		elif args[0].lower() == 'del' or args[0].lower() == 'delete':
			settypeblacklist = tl(update.effective_message, 'left, the message will be deleted')
			sql.set_blacklist_strength(chat_id, 1, "0")
		elif args[0].lower() == 'warn':
			settypeblacklist = tl(update.effective_message, 'warn')
			sql.set_blacklist_strength(chat_id, 2, "0")
		elif args[0].lower() == 'mute':
			settypeblacklist = tl(update.effective_message, 'mute')
			sql.set_blacklist_strength(chat_id, 3, "0")
		elif args[0].lower() == 'kick':
			settypeblacklist = tl(update.effective_message, 'kick')
			sql.set_blacklist_strength(chat_id, 4, "0")
		elif args[0].lower() == 'ban':
			settypeblacklist = tl(update.effective_message, 'ban')
			sql.set_blacklist_strength(chat_id, 5, "0")
		elif args[0].lower() == 'tban':
			if len(args) == 1:
				teks = tl(update.effective_message, """It looks like you are trying to set a temporary value for the sticker blacklist, but have not determined the time yet; Use `/blstickermode tban <timevalue>`.

Example time value: 4m = 4 minute, 3h = 3 hour, 6d = 6 day, 5w = 5 Sunday.""")
				send_message(update.effective_message, teks, parse_mode="markdown")
				return
			settypeblacklist = tl(update.effective_message, 'temporarily blocked for {}').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, """It looks like you are trying to set a temporary value for the sticker blacklist, but have not determined the time yet; Use `/blstickermode tmute <timevalue>`.

Example time value: 4m = 4 minute, 3h = 3 hour, 6d = 6 day, 5w = 5 sunday.""")
				send_message(update.effective_message, teks, parse_mode="markdown")
				return
			settypeblacklist = tl(update.effective_message, 'temporarily blocked for {}').format(args[1])
			sql.set_blacklist_strength(chat_id, 7, str(args[1]))
		else:
			send_message(update.effective_message, tl(update.effective_message, "I only understood off/del/warn/ban/kick/mute/tban/tmute!"))
			return
		if conn:
			text = tl(update.effective_message, "The blacklist sticker mode is changed, User will `{}` on *{}*!").format(settypeblacklist, chat_name)
		else:
			text = tl(update.effective_message, "The blacklist sticker mode is changed, User will `{}`!").format(settypeblacklist)
		send_message(update.effective_message, text, parse_mode="markdown")
		return "<b>{}:</b>\n" \
				"<b>Admin:</b> {}\n" \
				"Changed sticker 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, "not active")
		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, "temporarily banned for {}").format(getvalue)
		elif getmode == 7:
			settypeblacklist = tl(update.effective_message, "temporary mute for {}").format(getvalue)
		if conn:
			text = tl(update.effective_message, "The blacklist sticker mode is currently set to *{}* on *{}*.").format(settypeblacklist, chat_name)
		else:
			text = tl(update.effective_message, "The blacklist mode is currently set to *{}*.").format(settypeblacklist)
		send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN)
	return ""
Esempio n. 10
0
def unblackliststicker(bot: Bot, update: Update):
	msg = update.effective_message  # type: Optional[Message]
	chat = update.effective_chat  # type: Optional[Chat]
	user = update.effective_user  # type: Optional[User]
	words = msg.text.split(None, 1)

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

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


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

		if len(to_unblacklist) == 1:
			if successful:
				send_message(update.effective_message, tl(update.effective_message, "Sticker <code>{}</code> removed from the blacklist at <b>{}</b>!").format(html.escape(to_unblacklist[0]), chat_name),
							   parse_mode=ParseMode.HTML)
			else:
				send_message(update.effective_message, tl(update.effective_message, "This isn't on the sticker blacklist ...!"))

		elif successful == len(to_unblacklist):
			send_message(update.effective_message, tl(update.effective_message, "Sticker <code>{}</code> I removed it from the blacklist at <b>{}</b>!").format(
					successful, chat_name), parse_mode=ParseMode.HTML)

		elif not successful:
			send_message(update.effective_message, tl(update.effective_message, "None of these stickers exist, so they cannot be removed.").format(
					successful, len(to_unblacklist) - successful), parse_mode=ParseMode.HTML)

		else:
			send_message(update.effective_message, tl(update.effective_message, 
				"Sticker <code>{}</code> removed from the blacklist. {} There is no, "
				"so it's not deleted.").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, "Invalid sticker!"))
			return
		success = sql.rm_from_stickers(chat_id, trigger.lower())

		if success:
			send_message(update.effective_message, tl(update.effective_message, "Sticker <code>{}</code> removed from the blacklist at <b>{}</b>!").format(trigger, chat_name),
							   parse_mode=ParseMode.HTML)
		else:
			send_message(update.effective_message, tl(update.effective_message, "{} not on the sticker blacklist ...!").format(trigger))
	else:
		send_message(update.effective_message, tl(update.effective_message, "Tell me what stickers you want to add to the sticker blacklist."))