Esempio n. 1
0
def set_warn_limit(bot: Bot, update: Update, args: List[str]) -> str:
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id)
    if spam == True:
        return update.effective_message.reply_text(
            "Saya kecewa dengan anda, saya tidak akan mendengar kata-kata anda sekarang!"
        )
    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":
            update.effective_message.reply_text(
                "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].isdigit():
            if int(args[0]) < 3:
                msg.reply_text("Batas peringatan minimum adalah 3!")
            else:
                sql.set_warn_limit(chat.id, int(args[0]))
                if conn:
                    text = "Diperbarui batas untuk diperingatkan {} pada *{}*".format(
                        args[0], chat_name)
                else:
                    text = "Diperbarui batas untuk diperingatkan {}".format(
                        args[0])
                msg.reply_text(text, parse_mode="markdown")
                return "<b>{}:</b>" \
                       "\n#SET_WARN_LIMIT" \
                       "\n<b>Admin:</b> {}" \
                       "\nSetel batas peringatan ke <code>{}</code>".format(html.escape(chat.title),
                                                                        mention_html(user.id, user.first_name), args[0])
        else:
            msg.reply_text("Beri aku angkanya!")
    else:
        limit, soft_warn = sql.get_warn_setting(chat.id)
        if conn:
            text = "Batas peringatan saat ini adalah {} pada *{}*".format(
                limit, chat_name)
        else:
            text = "Batas peringatan saat ini adalah {}".format(limit)
        msg.reply_text(text, parse_mode="markdown")
    return ""
Esempio n. 2
0
def warns(bot: Bot, update: Update, args: List[str]):
    spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    message = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]

    conn = connected(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":
            update.effective_message.reply_text(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

    user_id = extract_user(message, args) or update.effective_user.id
    result = sql.get_warns(user_id, chat.id)

    if result and result[0] != 0:
        num_warns, reasons = result
        limit, soft_warn, warn_mode = sql.get_warn_setting(chat.id)

        if reasons:
            if conn:
                text = tl(update.effective_message, "Pengguna ini memiliki {}/{} peringatan pada *{}*, untuk alasan berikut:").format(num_warns, limit, chat_name)
            else:
                text = tl(update.effective_message, "Pengguna ini memiliki {}/{} peringatan, untuk alasan berikut:").format(num_warns, limit)
            for reason in reasons:
                text += "\n - {}".format(reason)

            msgs = split_message(text)
            for msg in msgs:
                update.effective_message.reply_text(msg, parse_mode="markdown")
        else:
            if conn:
                update.effective_message.reply_text(
                    tl(update.effective_message, "Pengguna ini memiliki {}/{} peringatan pada *{}*, tetapi tidak ada alasan untuk itu.").format(num_warns, limit, chat_name), parse_mode="markdown")
            else:
                update.effective_message.reply_text(
                    tl(update.effective_message, "Pengguna ini memiliki {}/{} peringatan, tetapi tidak ada alasan untuk itu.").format(num_warns, limit))
    else:
        if conn:
            update.effective_message.reply_text(tl(update.effective_message, "Pengguna ini belum mendapatkan peringatan apa pun pada *{}*!").format(chat_name), parse_mode="markdown")
        else:
            update.effective_message.reply_text(tl(update.effective_message, "Pengguna ini belum mendapatkan peringatan apa pun!"))
Esempio n. 3
0
def __chat_settings_btn__(chat_id, user_id):
    limit, soft_warn = sql.get_warn_setting(chat_id)
    button = []
    button.append([
        InlineKeyboardButton(text="➖",
                             callback_data="set_wlim=-|{}".format(chat_id)),
        InlineKeyboardButton(text="Limit {}".format(limit),
                             callback_data="set_wlim=?|{}".format(chat_id)),
        InlineKeyboardButton(text="➕",
                             callback_data="set_wlim=+|{}".format(chat_id))
    ])
    button.append([
        InlineKeyboardButton(
            text="{}".format("❎ Tendang" if soft_warn else "⛔️ Blokir"),
            callback_data="set_wlim=exec|{}".format(chat_id))
    ])
    return button
Esempio n. 4
0
def set_warn_limit(update, context) -> str:
    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].isdigit():
            if int(args[0]) < 3:
                send_message(update.effective_message, tl(update.effective_message, "Batas peringatan minimum adalah 3!"))
            else:
                sql.set_warn_limit(chat.id, int(args[0]))
                if conn:
                    text = tl(update.effective_message, "Diperbarui batas untuk diperingatkan {} pada *{}*").format(args[0], chat_name)
                else:
                    text = tl(update.effective_message, "Diperbarui batas untuk diperingatkan {}").format(args[0])
                send_message(update.effective_message, text, parse_mode="markdown")
                return "<b>{}:</b>" \
                       "\n#SET_WARN_LIMIT" \
                       "\n<b>Admin:</b> {}" \
                       "\nSet the warn limit to <code>{}</code>".format(html.escape(chat.title),
                                                                        mention_html(user.id, user.first_name), args[0])
        else:
            send_message(update.effective_message, tl(update.effective_message, "Beri aku angkanya!"))
    else:
        limit, soft_warn, warn_mode = sql.get_warn_setting(chat.id)
        if conn:
            text = tl(update.effective_message, "Batas peringatan saat ini adalah {} pada *{}*").format(limit, chat_name)
        else:
            text = tl(update.effective_message, "Batas peringatan saat ini adalah {}").format(limit)
        send_message(update.effective_message, text, parse_mode="markdown")
    return ""
Esempio n. 5
0
def export_data(update, context):
	msg = update.effective_message  # type: Optional[Message]
	user = update.effective_user  # type: Optional[User]

	chat_id = update.effective_chat.id
	chat = update.effective_chat
	current_chat_id = update.effective_chat.id
	chat_data = context.chat_data

	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

	jam = time.time()
	new_jam = jam + 43200
	cek = get_chat(chat_id, chat_data)
	if cek.get('status'):
		if jam <= int(cek.get('value')):
			waktu = time.strftime("%H:%M:%S %d/%m/%Y", time.localtime(cek.get('value')))
			send_message(update.effective_message, tl(update.effective_message, "Anda dapat mencadangan data sekali dalam 12 jam!\n[Orang ini](tg://user?id={}) sudah mencadangan data\nAnda dapat mencadangan data lagi pada `{}`").format(cek.get('user'), waktu), parse_mode=ParseMode.MARKDOWN)
			return
		else:
			if user.id != OWNER_ID:
				put_chat(chat_id, user.id, new_jam, chat_data)
	else:
		if user.id != OWNER_ID:
			put_chat(chat_id, user.id, new_jam, chat_data)


	# Backup version
	# Revision: 07/07/2019
	backup_ver = 1
	bot_base = "Emilia"

	# Make sure this backup is for this bot
	bot_id = context.bot.id

	# Backuping antiflood
	flood_mode, flood_duration = antifloodsql.get_flood_setting(chat_id)
	flood_limit = antifloodsql.get_flood_limit(chat_id)
	antiflood = {'flood_mode': flood_mode, 'flood_duration': flood_duration, 'flood_limit': flood_limit}

	# Backuping blacklists
	all_blacklisted = blacklistsql.get_chat_blacklist(chat_id)
	blacklist_mode, blacklist_duration = blacklistsql.get_blacklist_setting(chat.id)
	blacklists = {'blacklist_mode': blacklist_mode, 'blacklist_duration': blacklist_duration, 'blacklists': all_blacklisted}

	# Backuping blacklists sticker
	all_blsticker = blackliststksql.get_chat_stickers(chat_id)
	blsticker_mode, blsticker_duration = blacklistsql.get_blacklist_setting(chat.id)
	blstickers = {'blsticker_mode': blsticker_mode, 'blsticker_duration': blsticker_duration, 'blstickers': all_blsticker}

	# Backuping disabled
	cmd_disabled = disabledsql.get_all_disabled(chat_id)
	disabled = {'disabled': cmd_disabled}

	# Backuping filters
	all_filters = filtersql.get_chat_triggers(chat_id)
	filters_gen = []
	for x in all_filters:
		filt = filtersql.get_filter(chat.id, x)
		if filt.is_sticker:
			filt_type = 1
		elif filt.is_document:
			filt_type = 2
		elif filt.is_image:
			filt_type = 3
		elif filt.is_audio:
			filt_type = 4
		elif filt.is_voice:
			filt_type = 5
		elif filt.is_video:
			filt_type = 6
		elif filt.has_markdown:
			filt_type = 0
		else:
			filt_type = 7
		filters_gen.append({"name": x, "reply": filt.reply, "type": filt_type})
	filters = {'filters': filters_gen}

	# Backuping greetings msg and config
	greetings = {}
	pref, welcome_m, cust_content, welcome_type = welcsql.get_welc_pref(chat_id)
	if not welcome_m:
		welcome_m = ""
	if not cust_content:
		cust_content = ""
	buttons = welcsql.get_welc_buttons(chat_id)
	welcome_m += revert_buttons(buttons)
	greetings["welcome"] = {"enable": pref, "text": welcome_m, "content": cust_content, "type": welcome_type}

	pref, goodbye_m, cust_content, goodbye_type = welcsql.get_gdbye_pref(chat_id)
	if not goodbye_m:
		goodbye_m = ""
	if not cust_content:
		cust_content = ""
	buttons = welcsql.get_gdbye_buttons(chat_id)
	goodbye_m += revert_buttons(buttons)
	greetings["goodbye"] = {"enable": pref, "text": goodbye_m, "content": cust_content, "type": goodbye_type}

	curr = welcsql.clean_service(chat_id)
	greetings["clean_service"] = curr

	getcur, cur_value, extra_verify, timeout, timeout_mode, cust_text = welcsql.welcome_security(chat_id)
	greetings["security"] = {"enable": getcur, "text": cust_text, "time": cur_value, "extra_verify": extra_verify, "timeout": timeout, "timeout_mode": timeout_mode}

	# Backuping chat language
	getlang = langsql.get_lang(chat_id)
	language = {"language": getlang}

	# Backuping locks
	curr_locks = locksql.get_locks(chat_id)
	curr_restr = locksql.get_restr(chat_id)

	if curr_locks:
		locked_lock = {
			"sticker": curr_locks.sticker,
			"audio": curr_locks.audio,
			"voice": curr_locks.voice,
			"document": curr_locks.document,
			"video": curr_locks.video,
			"contact": curr_locks.contact,
			"photo": curr_locks.photo,
			"gif": curr_locks.gif,
			"url": curr_locks.url,
			"bots": curr_locks.bots,
			"forward": curr_locks.forward,
			"game": curr_locks.game,
			"location": curr_locks.location,
			"rtl": curr_locks.rtl
		}
	else:
		locked_lock = {}

	if curr_restr:
		locked_restr = {
			"messages": curr_restr.messages,
			"media": curr_restr.media,
			"other": curr_restr.other,
			"previews": curr_restr.preview,
			"all": all([curr_restr.messages, curr_restr.media, curr_restr.other, curr_restr.preview])
		}
	else:
		locked_restr = {}

	lock_warn = locksql.get_lockconf(chat_id)

	locks = {'lock_warn': lock_warn, 'locks': locked_lock, 'restrict': locked_restr}

	# Backuping notes
	note_list = notesql.get_all_chat_notes(chat_id)
	notes = []
	for note in note_list:
		buttonlist = ""
		note_tag = note.name
		note_type = note.msgtype
		getnote = notesql.get_note(chat_id, note.name)
		if not note.value:
			note_data = ""
		else:
			tombol = notesql.get_buttons(chat_id, note_tag)
			keyb = []
			buttonlist = ""
			for btn in tombol:
				if btn.same_line:
					buttonlist += "[{}](buttonurl:{}:same)\n".format(btn.name, btn.url)
				else:
					buttonlist += "[{}](buttonurl:{})\n".format(btn.name, btn.url)
			note_data = "{}\n\n{}".format(note.value, buttonlist)
		note_file = note.file
		if not note_file:
			note_file = ""
		notes.append({"note_tag": note_tag, "note_data": note_data, "note_file": note_file, "note_type": note_type})

	# Backuping reports
	get_report = reportsql.user_should_report(chat_id)
	report = {'report': get_report}

	# Backuping rules
	getrules = rulessql.get_rules(chat_id)
	rules = {"rules": getrules}

	# Backuping warns config and warn filters
	warn_limit, _, warn_mode = warnssql.get_warn_setting(chat_id)
	all_handlers = warnssql.get_chat_warn_triggers(chat_id)
	all_warn_filter = []
	for x in all_handlers:
		warnreply = warnssql.get_warn_filter(chat_id, x)
		all_warn_filter.append({'name': x, 'reason': warnreply.reply})
	if not warn_mode:
		warn_mode = ""
	# Get all warnings in current chat
	allwarns = warnssql.get_allwarns(chat_id)
	warns = {"warn_limit": warn_limit, "warn_mode": warn_mode, "warn_filters": all_warn_filter, "chat_warns": allwarns}


	# Parsing backups
	backup = {"bot_id": bot_id, "bot_base": bot_base, "antiflood": antiflood, "blacklists": blacklists, "blstickers": blstickers, "disabled": disabled, "filters": filters, "greetings": greetings, "language": language, "locks": locks, "notes": notes, "report": report, "rules": rules, "warns": warns, "version": backup_ver}


	all_backups = json.dumps(backup, indent=4, cls=SetEncoder)
	f = open("{}-Emilia.backup".format(chat_id), "w")
	f.write(str(all_backups))
	f.close()
	context.bot.sendChatAction(current_chat_id, "upload_document")
	tgl = time.strftime("%H:%M:%S - %d/%m/%Y", time.localtime(time.time()))
	try:
		context.bot.sendMessage(TEMPORARY_DATA, "*Berhasil mencadangan untuk:*\nNama chat: `{}`\nID chat: `{}`\nPada: `{}`".format(chat.title, chat_id, tgl), parse_mode=ParseMode.MARKDOWN)
	except BadRequest:
		pass
	send = context.bot.sendDocument(current_chat_id, document=open('{}-Emilia.backup'.format(chat_id), 'rb'), caption=tl(update.effective_message, "*Berhasil mencadangan untuk:*\nNama chat: `{}`\nID chat: `{}`\nPada: `{}`\n\nNote: cadangan ini khusus untuk bot ini, jika di import ke bot lain maka catatan dokumen, video, audio, voice, dan lain-lain akan hilang").format(chat.title, chat_id, tgl), timeout=360, reply_to_message_id=msg.message_id, parse_mode=ParseMode.MARKDOWN)
	try:
		# Send to temp data for prevent unexpected issue
		context.bot.sendDocument(TEMPORARY_DATA, document=send.document.file_id, caption=tl(update.effective_message, "*Berhasil mencadangan untuk:*\nNama chat: `{}`\nID chat: `{}`\nPada: `{}`\n\nNote: cadangan ini khusus untuk bot ini, jika di import ke bot lain maka catatan dokumen, video, audio, voice, dan lain-lain akan hilang").format(chat.title, chat_id, tgl), timeout=360, parse_mode=ParseMode.MARKDOWN)
	except BadRequest:
		pass
	os.remove("{}-Emilia.backup".format(chat_id)) # Cleaning file
Esempio n. 6
0
def set_warn_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() in ("kick", "soft"):
            sql.set_warn_mode(chat.id, 1)
            if conn:
                text = tl(
                    update.effective_message,
                    "Terlalu banyak peringatan sekarang akan menghasilkan tendangan pada *{}*! Pengguna akan dapat bergabung lagi."
                ).format(chat_name)
            else:
                text = tl(
                    update.effective_message,
                    "Terlalu banyak peringatan sekarang akan menghasilkan tendangan! Pengguna akan dapat bergabung lagi."
                )
            send_message(update.effective_message, text, parse_mode="markdown")
            return "<b>{}:</b>\n" \
                   "<b>Admin:</b> {}\n" \
                   "Has changed the final warning to kick.".format(html.escape(chat.title),
                                                                            mention_html(user.id, user.first_name))

        elif args[0].lower() in ("ban", "banned", "hard"):
            sql.set_warn_mode(chat.id, 2)
            if conn:
                text = tl(
                    update.effective_message,
                    "Terlalu banyak peringatan akan menghasilkan blokir pada *{}*!"
                ).format(chat_name)
            else:
                text = tl(
                    update.effective_message,
                    "Terlalu banyak peringatan akan menghasilkan blokir!")
            send_message(update.effective_message, text, parse_mode="markdown")
            return "<b>{}:</b>\n" \
                   "<b>Admin:</b> {}\n" \
                   "Has changed the final warning to banned.".format(html.escape(chat.title),
                                                                                  mention_html(user.id,
                                                                                               user.first_name))

        elif args[0].lower() in ("mute"):
            sql.set_warn_mode(chat.id, 3)
            if conn:
                text = tl(
                    update.effective_message,
                    "Terlalu banyak peringatan akan menghasilkan bisukan pada *{}*!"
                ).format(chat_name)
            else:
                text = tl(
                    update.effective_message,
                    "Terlalu banyak peringatan akan menghasilkan bisukan!")
            send_message(update.effective_message, text, parse_mode="markdown")
            return "<b>{}:</b>\n" \
                   "<b>Admin:</b> {}\n" \
                   "Has changed the final warning to mute.".format(html.escape(chat.title),
                                                                                  mention_html(user.id,
                                                                                               user.first_name))

        else:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Saya hanya mengerti kick/ban/mute!"))
    else:
        limit, soft_warn, warn_mode = sql.get_warn_setting(chat.id)
        if not soft_warn:
            if not warn_mode:
                if conn:
                    text = tl(
                        update.effective_message,
                        "Peringatan saat ini disetel ke *tendangan* pengguna saat melampaui batas pada *{}*."
                    ).format(chat_name)
                else:
                    text = tl(
                        update.effective_message,
                        "Peringatan saat ini disetel ke *tendangan* pengguna saat melampaui batas."
                    )
            elif warn_mode == 1:
                if conn:
                    text = tl(
                        update.effective_message,
                        "Peringatan saat ini disetel ke *tendangan* pengguna saat melampaui batas pada *{}*."
                    ).format(chat_name)
                else:
                    text = tl(
                        update.effective_message,
                        "Peringatan saat ini disetel ke *tendangan* pengguna saat melampaui batas."
                    )
            elif warn_mode == 2:
                if conn:
                    text = tl(
                        update.effective_message,
                        "Peringatan saat ini disetel ke *blokir* pengguna saat melampaui batas pada *{}*."
                    ).format(chat_name)
                else:
                    text = tl(
                        update.effective_message,
                        "Peringatan saat ini disetel ke *blokir* pengguna saat melampaui batas."
                    )
            elif warn_mode == 3:
                if conn:
                    text = tl(
                        update.effective_message,
                        "Peringatan saat ini disetel ke *bisukan* pengguna saat melampaui batas pada *{}*."
                    ).format(chat_name)
                else:
                    text = tl(
                        update.effective_message,
                        "Peringatan saat ini disetel ke *bisukan* pengguna saat melampaui batas."
                    )
            send_message(update.effective_message,
                         text,
                         parse_mode=ParseMode.MARKDOWN)
        else:
            if conn:
                text = tl(
                    update.effective_message,
                    "Peringatan saat ini disetel untuk *blokir* pengguna saat melampaui batas pada *{}*."
                ).format(chat_name)
            else:
                text = tl(
                    update.effective_message,
                    "Peringatan saat ini disetel untuk *blokir* pengguna saat melampaui batas."
                )
            send_message(update.effective_message,
                         text,
                         parse_mode=ParseMode.MARKDOWN)
    return ""
Esempio n. 7
0
def set_warn_strength(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() in ("on", "yes"):
            sql.set_warn_strength(chat.id, False)
            if conn:
                text = "Terlalu banyak peringatan sekarang akan menghasilkan blokir pada *{}*!".format(
                    chat_name)
            else:
                text = "Terlalu banyak peringatan sekarang akan menghasilkan blokir!"
            send_message(update.effective_message, text, parse_mode="markdown")
            return "<b>{}:</b>\n" \
                   "<b>Admin:</b> {}\n" \
                   "Telah mengaktifkan peringatan yang kuat. Pengguna akan diblokir.".format(html.escape(chat.title),
                                                                            mention_html(user.id, user.first_name))

        elif args[0].lower() in ("off", "no"):
            sql.set_warn_strength(chat.id, True)
            if conn:
                text = "Terlalu banyak peringatan akan menghasilkan tendangan pada *{}*! Pengguna akan dapat bergabung lagi.".format(
                    chat_name)
            else:
                text = "Terlalu banyak peringatan akan menghasilkan tendangan! Pengguna akan dapat bergabung lagi."
            send_message(update.effective_message, text, parse_mode="markdown")
            return "<b>{}:</b>\n" \
                   "<b>Admin:</b> {}\n" \
                   "Telah menonaktifkan peringatan kuat. Pengguna hanya akan ditendang.".format(html.escape(chat.title),
                                                                                  mention_html(user.id,
                                                                                               user.first_name))

        else:
            send_message(update.effective_message,
                         "Saya hanya mengerti on/yes/no/off!")
    else:
        limit, soft_warn, warn_mode = sql.get_warn_setting(chat.id)
        if soft_warn:
            if conn:
                text = "Peringatan saat ini disetel ke *tendangan* pengguna saat melampaui batas pada *{}*.".format(
                    chat_name)
            else:
                text = "Peringatan saat ini disetel ke *tendangan* pengguna saat melampaui batas."
            send_message(update.effective_message,
                         text,
                         parse_mode=ParseMode.MARKDOWN)
        else:
            if conn:
                text = "Peringatan saat ini disetel untuk *diblokir* pengguna saat melampaui batas pada *{}*.".format(
                    chat_name)
            else:
                text = "Peringatan saat ini disetel untuk *diblokir* pengguna saat melampaui batas."
            send_message(update.effective_message,
                         text,
                         parse_mode=ParseMode.MARKDOWN)
    return ""
Esempio n. 8
0
def warn(user: User,
         chat: Chat,
         reason: str,
         message: Message,
         warner: User = None,
         conn=False) -> str:
    if is_user_admin(chat, user.id):
        return ""

    if warner:
        warner_tag = mention_html(warner.id, warner.first_name)
    else:
        warner_tag = tl(chat.id, "Filter peringatan otomatis.")

    limit, soft_warn, warn_mode = sql.get_warn_setting(chat.id)
    num_warns, reasons = sql.warn_user(user.id, chat.id, reason)
    if num_warns >= limit:
        sql.reset_warns(user.id, chat.id)
        if not soft_warn:
            if not warn_mode:
                chat.unban_member(user.id)
                reply = tl(chat.id,
                           "{} peringatan, {} telah ditendang!").format(
                               limit, mention_html(user.id, user.first_name))
            elif warn_mode == 1:
                chat.unban_member(user.id)
                reply = tl(chat.id,
                           "{} peringatan, {} telah ditendang!").format(
                               limit, mention_html(user.id, user.first_name))
            elif warn_mode == 2:
                chat.kick_member(user.id)
                reply = tl(chat.id,
                           "{} peringatan, {} telah diblokir!").format(
                               limit, mention_html(user.id, user.first_name))
            elif warn_mode == 3:
                message.bot.restrict_chat_member(chat.id,
                                                 user.id,
                                                 can_send_messages=False)
                reply = tl(chat.id,
                           "{} peringatan, {} telah dibisukan!").format(
                               limit, mention_html(user.id, user.first_name))
        else:
            chat.kick_member(user.id)
            reply = tl(chat.id, "{} peringatan, {} telah diblokir!").format(
                limit, mention_html(user.id, user.first_name))

        for warn_reason in reasons:
            reply += "\n - {}".format(html.escape(warn_reason))

        message.bot.send_sticker(chat.id,
                                 BAN_STICKER)  # banhammer marie sticker
        keyboard = None
        log_reason = "<b>{}:</b>" \
                     "\n#WARN_BAN" \
                     "\n<b>Admin:</b> {}" \
                     "\n<b>User:</b> {} (<code>{}</code>)" \
                     "\n<b>Reason:</b> {}"\
                     "\n<b>Counts:</b> <code>{}/{}</code>".format(html.escape(chat.title),
                                                                  warner_tag,
                                                                  mention_html(user.id, user.first_name),
                                                                  user.id, reason, num_warns, limit)

    else:
        keyboard = InlineKeyboardMarkup([[
            InlineKeyboardButton(tl(chat.id, "Hapus peringatan"),
                                 callback_data="rm_warn({})".format(user.id)),
            InlineKeyboardButton(tl(chat.id, "Peraturan"),
                                 url="t.me/{}?start={}".format(
                                     dispatcher.bot.username, chat.id))
        ]])

        if num_warns + 1 == limit:
            if not warn_mode:
                action_mode = tl(chat.id, "tendang")
            elif warn_mode == 1:
                action_mode = tl(chat.id, "tendang")
            elif warn_mode == 2:
                action_mode = tl(chat.id, "blokir")
            elif warn_mode == 3:
                action_mode = tl(chat.id, "bisukan")
            reply = tl(
                chat.id,
                "{} punya {}/{} peringatan... Jika anda di peringati lagi maka kamu akan di {}!"
            ).format(mention_html(user.id, user.first_name), num_warns, limit,
                     action_mode)
        else:
            reply = tl(chat.id,
                       "{} punya {}/{} peringatan... Hati-hati!").format(
                           mention_html(user.id, user.first_name), num_warns,
                           limit)
        if reason:
            reply += tl(chat.id,
                        "\nAlasan pada peringatan terakhir:\n{}").format(
                            html.escape(reason))

        log_reason = "<b>{}:</b>" \
                     "\n#WARN" \
                     "\n<b>Admin:</b> {}" \
                     "\n<b>User:</b> {} (<code>{}</code>)" \
                     "\n<b>Reason:</b> {}"\
                     "\n<b>Counts:</b> <code>{}/{}</code>".format(html.escape(chat.title),
                                                                  warner_tag,
                                                                  mention_html(user.id, user.first_name),
                                                                  user.id, reason, num_warns, limit)

    try:
        if conn:
            send_message_raw(chat.id,
                             reply,
                             reply_markup=keyboard,
                             parse_mode=ParseMode.HTML)
        else:
            send_message_raw(chat.id,
                             reply,
                             reply_to_message_id=message.message_id,
                             reply_markup=keyboard,
                             parse_mode=ParseMode.HTML)
        #send_message(update.effective_message, reply, reply_markup=keyboard, parse_mode=ParseMode.HTML)
    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            if conn:
                message.bot.sendMessage(chat.id,
                                        reply,
                                        reply_markup=keyboard,
                                        parse_mode=ParseMode.HTML)
            else:
                try:
                    message.bot.sendMessage(
                        chat.id,
                        reply,
                        reply_to_message_id=message.message_id,
                        reply_markup=keyboard,
                        parse_mode=ParseMode.HTML,
                        quote=False)
                except BadRequest:
                    message.bot.sendMessage(chat.id,
                                            reply,
                                            reply_markup=keyboard,
                                            parse_mode=ParseMode.HTML,
                                            quote=False)
            #send_message(update.effective_message, reply, reply_markup=keyboard, parse_mode=ParseMode.HTML, quote=False)
        else:
            raise
    return log_reason
Esempio n. 9
0
def __chat_settings__(chat_id, user_id):
    num_warn_filters = sql.num_warn_chat_filters(chat_id)
    limit, soft_warn, warn_mode = sql.get_warn_setting(chat_id)
    return tl(user_id, "Obrolan ini mempunyai `{}` saringan peringatkan. Dibutuhkan `{}` peringatan " \
           "sebelum pengguna akan mendapatkan *{}*.").format(num_warn_filters, limit, "tendangan" if soft_warn else "pemblokiran")
Esempio n. 10
0
def WARN_EDITBTN(bot: Bot, update: Update):
    query = update.callback_query
    user = update.effective_user
    print("User {} clicked button WARN EDIT".format(user.id))
    qdata = query.data.split("=")[1].split("|")[0]
    chat_id = query.data.split("|")[1]
    if qdata == "?":
        bot.answerCallbackQuery(
            query.id,
            "Batas dari peringatan. Jika peringatan melewati batas maka akan di eksekusi.",
            show_alert=True)
    if qdata == "-":
        button = []
        limit, soft_warn = sql.get_warn_setting(chat_id)
        limit = int(limit) - 1
        if limit <= 2:
            bot.answerCallbackQuery(query.id,
                                    "Batas limit Tidak boleh kurang dari 3",
                                    show_alert=True)
            return
        sql.set_warn_limit(chat_id, int(limit))
        chat = bot.get_chat(chat_id)
        text = "*{}* memiliki pengaturan berikut untuk modul *Peringatan*:\n\n".format(
            escape_markdown(chat.title))
        text += "Batas maksimal peringatan telah di setel menjadi `{}`. Dibutuhkan `{}` peringatan " \
           "sebelum pengguna akan mendapatkan *{}*.".format(limit, limit, "tendangan" if soft_warn else "pemblokiran")
        button.append([
            InlineKeyboardButton(
                text="➖", callback_data="set_wlim=-|{}".format(chat_id)),
            InlineKeyboardButton(
                text="Limit {}".format(limit),
                callback_data="set_wlim=?|{}".format(chat_id)),
            InlineKeyboardButton(text="➕",
                                 callback_data="set_wlim=+|{}".format(chat_id))
        ])
        button.append([
            InlineKeyboardButton(
                text="{}".format("❎ Tendang" if soft_warn else "⛔️ Blokir"),
                callback_data="set_wlim=exec|{}".format(chat_id))
        ])
        button.append([
            InlineKeyboardButton(
                text="Kembali", callback_data="stngs_back({})".format(chat_id))
        ])
        query.message.edit_text(text=text,
                                parse_mode=ParseMode.MARKDOWN,
                                reply_markup=InlineKeyboardMarkup(button))
        bot.answer_callback_query(query.id)
    if qdata == "+":
        button = []
        limit, soft_warn = sql.get_warn_setting(chat_id)
        limit = int(limit) + 1
        if limit <= 0:
            bot.answerCallbackQuery(query.id,
                                    "Batas limit Tidak boleh kurang dari 0",
                                    show_alert=True)
            return
        sql.set_warn_limit(chat_id, int(limit))
        chat = bot.get_chat(chat_id)
        text = "*{}* memiliki pengaturan berikut untuk modul *Peringatan*:\n\n".format(
            escape_markdown(chat.title))
        text += "Batas maksimal peringatan telah di setel menjadi `{}`. Dibutuhkan `{}` peringatan " \
           "sebelum pengguna akan mendapatkan *{}*.".format(limit, limit, "tendangan" if soft_warn else "pemblokiran")
        button.append([
            InlineKeyboardButton(
                text="➖", callback_data="set_wlim=-|{}".format(chat_id)),
            InlineKeyboardButton(
                text="Limit {}".format(limit),
                callback_data="set_wlim=?|{}".format(chat_id)),
            InlineKeyboardButton(text="➕",
                                 callback_data="set_wlim=+|{}".format(chat_id))
        ])
        button.append([
            InlineKeyboardButton(
                text="{}".format("❎ Tendang" if soft_warn else "⛔️ Blokir"),
                callback_data="set_wlim=exec|{}".format(chat_id))
        ])
        button.append([
            InlineKeyboardButton(
                text="Kembali", callback_data="stngs_back({})".format(chat_id))
        ])
        query.message.edit_text(text=text,
                                parse_mode=ParseMode.MARKDOWN,
                                reply_markup=InlineKeyboardMarkup(button))
        bot.answer_callback_query(query.id)
    if qdata == "exec":
        button = []
        limit, soft_warn = sql.get_warn_setting(chat_id)
        if soft_warn:
            exc = "Blokir"
            sql.set_warn_strength(chat_id, False)
            soft_warn = False
        else:
            exc = "Tendang"
            sql.set_warn_strength(chat_id, True)
            soft_warn = True
        chat = bot.get_chat(chat_id)
        text = "*{}* memiliki pengaturan berikut untuk modul *Peringatan*:\n\n".format(
            escape_markdown(chat.title))
        text += "Pengguna akan di `{}` jika sudah diluar batas peringatan. Dibutuhkan `{}` peringatan " \
           "sebelum pengguna akan mendapatkan *{}*.".format(exc, limit, "tendangan" if soft_warn else "pemblokiran")
        button.append([
            InlineKeyboardButton(
                text="➖", callback_data="set_wlim=-|{}".format(chat_id)),
            InlineKeyboardButton(
                text="Limit {}".format(limit),
                callback_data="set_wlim=?|{}".format(chat_id)),
            InlineKeyboardButton(text="➕",
                                 callback_data="set_wlim=+|{}".format(chat_id))
        ])
        button.append([
            InlineKeyboardButton(
                text="{}".format("❎ Tendang" if soft_warn else "⛔️ Blokir"),
                callback_data="set_wlim=exec|{}".format(chat_id))
        ])
        button.append([
            InlineKeyboardButton(
                text="Kembali", callback_data="stngs_back({})".format(chat_id))
        ])
        query.message.edit_text(text=text,
                                parse_mode=ParseMode.MARKDOWN,
                                reply_markup=InlineKeyboardMarkup(button))
        bot.answer_callback_query(query.id)
Esempio n. 11
0
def warn(user: User,
         chat: Chat,
         reason: str,
         message: Message,
         warner: User = None,
         conn=False) -> str:
    if is_user_admin(chat, user.id):
        message.reply_text("Sayangnya admin tidak bisa di warn 😔")
        return ""

    if warner:
        warner_tag = mention_html(warner.id, warner.first_name)
    else:
        warner_tag = "Filter peringatan otomatis."

    limit, soft_warn = sql.get_warn_setting(chat.id)
    num_warns, reasons = sql.warn_user(user.id, chat.id, reason)
    if num_warns >= limit:
        sql.reset_warns(user.id, chat.id)
        if soft_warn:  # kick
            chat.unban_member(user.id)
            reply = "{} peringatan, {} telah ditendang!".format(
                limit, mention_html(user.id, user.first_name))

        else:  # ban
            chat.kick_member(user.id)
            reply = "{} peringatan, {} telah diblokir!".format(
                limit, mention_html(user.id, user.first_name))

        for warn_reason in reasons:
            reply += "\n - {}".format(html.escape(warn_reason))

        message.bot.send_sticker(chat.id,
                                 BAN_STICKER)  # banhammer marie sticker
        keyboard = []
        log_reason = "<b>{}:</b>" \
                     "\n#WARN_BAN" \
                     "\n<b>Admin:</b> {}" \
                     "\n<b>Pengguna:</b> {} (<code>{}</code>)" \
                     "\n<b>Alasan:</b> {}"\
                     "\n<b>Jumlah:</b> <code>{}/{}</code>".format(html.escape(chat.title),
                                                                  warner_tag,
                                                                  mention_html(user.id, user.first_name),
                                                                  user.id, reason, num_warns, limit)

    else:
        keyboard = InlineKeyboardMarkup([[
            InlineKeyboardButton("Hapus peringatan",
                                 callback_data="rm_warn({})".format(user.id))
        ]])

        reply = "{} punya {}/{} peringatan... Hati-hati!".format(
            mention_html(user.id, user.first_name), num_warns, limit)
        if reason:
            reply += "\nAlasan pada peringatan terakhir:\n{}".format(
                html.escape(reason))

        log_reason = "<b>{}:</b>" \
                     "\n#WARN" \
                     "\n<b>Admin:</b> {}" \
                     "\n<b>Pengguna:</b> {} (<code>{}</code>)" \
                     "\n<b>Alasan:</b> {}"\
                     "\n<b>Jumlah:</b> <code>{}/{}</code>".format(html.escape(chat.title),
                                                                  warner_tag,
                                                                  mention_html(user.id, user.first_name),
                                                                  user.id, reason, num_warns, limit)

    try:
        if conn:
            message.bot.sendMessage(chat.id,
                                    reply,
                                    reply_markup=keyboard,
                                    parse_mode=ParseMode.HTML)
        else:
            message.bot.sendMessage(chat.id,
                                    reply,
                                    reply_to_message_id=message.message_id,
                                    reply_markup=keyboard,
                                    parse_mode=ParseMode.HTML)
        #message.reply_text(reply, reply_markup=keyboard, parse_mode=ParseMode.HTML)
    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            if conn:
                message.bot.sendMessage(chat.id,
                                        reply,
                                        reply_markup=keyboard,
                                        parse_mode=ParseMode.HTML)
            else:
                message.bot.sendMessage(chat.id,
                                        reply,
                                        reply_to_message_id=message.message_id,
                                        reply_markup=keyboard,
                                        parse_mode=ParseMode.HTML,
                                        quote=False)
            #message.reply_text(reply, reply_markup=keyboard, parse_mode=ParseMode.HTML, quote=False)
        else:
            raise
    return log_reason