Ejemplo n.º 1
0
def set_rules(bot: Bot, update: Update):
    spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    chat = update.effective_chat
    chat_id = update.effective_chat.id
    user = update.effective_user
    msg = update.effective_message  # type: Optional[Message]
    raw_text = msg.text
    args = raw_text.split(None, 1)  # use python's maxsplit to separate cmd and args

    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 len(args) == 2:
        txt = args[1]
        offset = len(txt) - len(raw_text)  # set correct offset relative to command
        markdown_rules = markdown_parser(txt, entities=msg.parse_entities(), offset=offset)

        sql.set_rules(chat_id, markdown_rules)
        if conn:
            update.effective_message.reply_text("Berhasil mengatur aturan untuk *{}*.".format(chat_name), parse_mode="markdown")
        else:
            update.effective_message.reply_text("Berhasil mengatur aturan untuk grup ini.")
Ejemplo n.º 2
0
def send(update, message, keyboard, backup_message):
	chat = update.effective_chat
	cleanserv = sql.clean_service(chat.id)
	reply = update.message.message_id
	# Clean service welcome
	if cleanserv:
		reply = False
	try:
		msg = dispatcher.bot.send_message(chat.id, message, parse_mode=ParseMode.MARKDOWN, reply_markup=keyboard, reply_to_message_id=reply, disable_web_page_preview=True)
	except IndexError:
		msg = dispatcher.bot.send_message(chat.id, markdown_parser(backup_message +
																  tl(update.effective_message, "\nCatatan: pesan saat ini tidak valid "
																  "karena masalah markdown. Bisa jadi "
																  "karena nama pengguna.")),
												  reply_to_message_id=reply, 
												  parse_mode=ParseMode.MARKDOWN)
	except KeyError:
		msg = dispatcher.bot.send_message(chat.id, markdown_parser(backup_message +
																  tl(update.effective_message, "\nCatatan: pesan saat ini tidak valid "
																  "karena ada masalah dengan beberapa salah tempat. "
																  "Harap perbarui")),
												  reply_to_message_id=reply, 
												  parse_mode=ParseMode.MARKDOWN)
	except BadRequest as excp:
		if excp.message == "Button_url_invalid":
			msg = dispatcher.bot.send_message(chat.id, markdown_parser(backup_message +
																	  tl(update.effective_message, "\nCatatan: pesan saat ini memiliki url yang tidak "
																	  "valid di salah satu tombolnya. Harap perbarui.")),
													  reply_to_message_id=reply, 
													  parse_mode=ParseMode.MARKDOWN)
		elif excp.message == "Unsupported url protocol":
			msg = dispatcher.bot.send_message(chat.id, markdown_parser(backup_message +
																	  tl(update.effective_message, "\nCatatan: pesan saat ini memiliki tombol yang "
																	  "menggunakan protokol url yang tidak didukung "
																	  "oleh telegram. Harap perbarui.")),
													  reply_to_message_id=reply, 
													  parse_mode=ParseMode.MARKDOWN)
		elif excp.message == "Wrong url host":
			msg = dispatcher.bot.send_message(chat.id, markdown_parser(backup_message +
																	  tl(update.effective_message, "\nCatatan: pesan saat ini memiliki beberapa url "
																	  "yang buruk. Harap perbarui.")),
													  reply_to_message_id=reply, 
													  parse_mode=ParseMode.MARKDOWN)
			LOGGER.warning(message)
			LOGGER.warning(keyboard)
			LOGGER.exception("Could not parse! got invalid url host errors")
		else:
			try:
				msg = dispatcher.bot.send_message(chat.id, markdown_parser(backup_message +
																	  tl(update.effective_message, "\nCatatan: Terjadi kesalahan saat mengirim pesan "
																	  "kustom. Harap perbarui.")),
													  reply_to_message_id=reply, 
													  parse_mode=ParseMode.MARKDOWN)
				LOGGER.exception("ERROR!")
			except BadRequest:
				print("Cannot send welcome msg, bot is muted!")
				return ""
	return msg