Esempio n. 1
0
def save(bot: Bot, update: Update):
	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]
	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":
			chat_name = "catatan lokal"
		else:
			chat_name = chat.title

	msg = update.effective_message  # type: Optional[Message]

	note_name, text, data_type, content, buttons = get_note_type(msg)

	if data_type is None:
		msg.reply_text("Tidak ada catatan!")
		return
	
	if len(text.strip()) == 0:
		text = note_name
		
	sql.add_note_to_db(chat_id, note_name, text, data_type, buttons=buttons, file=content)
	msg.reply_text("Ok, `{note_name}` ditambahkan di *{chat_name}*.\ndapatkan dengan `/get {note_name}`, atau `#{note_name}`".format(note_name=note_name, chat_name=chat_name), parse_mode=ParseMode.MARKDOWN)
Esempio n. 2
0
def save(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  # type: Optional[Chat]
	user = update.effective_user  # type: Optional[User]
	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":
			chat_name = "catatan lokal"
		else:
			chat_name = chat.title

	msg = update.effective_message  # type: Optional[Message]

	checktext = msg.text.split()
	if msg.reply_to_message:
		if len(checktext) <= 1:
			send_message(update.effective_message, tl(update.effective_message, "Anda harus memberi nama untuk catatan ini!"))
			return
	else:
		if len(checktext) <= 2:
			send_message(update.effective_message, tl(update.effective_message, "Anda harus memberi nama untuk catatan ini!"))
			return

	note_name, text, data_type, content, buttons = get_note_type(msg)

	if data_type is None:
		send_message(update.effective_message, tl(update.effective_message, "Tidak ada catatan!"))
		return

	if len(text.strip()) == 0:
		text = "`" + note_name + "`"
		
	sql.add_note_to_db(chat_id, note_name, text, data_type, buttons=buttons, file=content)
	if conn:
		savedtext = tl(update.effective_message, "Ok, catatan `{note_name}` disimpan di *{chat_name}*.").format(note_name=note_name, chat_name=chat_name)
	else:
		savedtext = tl(update.effective_message, "Ok, catatan `{note_name}` disimpan.").format(note_name=note_name)
	try:
		send_message(update.effective_message, savedtext, parse_mode=ParseMode.MARKDOWN)
	except BadRequest:
		if conn:
			savedtext = tl(update.effective_message, "Ok, catatan <code>{note_name}</code> disimpan di <b>{chat_name}</b>.").format(note_name=note_name, chat_name=chat_name)
		else:
			savedtext = tl(update.effective_message, "Ok, catatan <code>{note_name}</code> disimpan.").format(note_name=note_name)
		send_message(update.effective_message, savedtext, parse_mode=ParseMode.HTML)
Esempio n. 3
0
def save(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  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    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":
            chat_name = "catatan lokal"
        else:
            chat_name = chat.title

    msg = update.effective_message  # type: Optional[Message]

    checktext = msg.text.split()
    if msg.reply_to_message:
        if len(checktext) <= 1:
            msg.reply_text("Anda harus memberi nama untuk catatan ini!")
            return
    else:
        if len(checktext) <= 2:
            msg.reply_text("Anda harus memberi nama untuk catatan ini!")
            return

    note_name, text, data_type, content, buttons = get_note_type(msg)

    if data_type is None:
        msg.reply_text("Tidak ada catatan!")
        return

    if len(text.strip()) == 0:
        text = note_name

    sql.add_note_to_db(chat_id,
                       note_name,
                       text,
                       data_type,
                       buttons=buttons,
                       file=content)
    msg.reply_text(
        "Ok, `{note_name}` ditambahkan di *{chat_name}*.\ndapatkan dengan `/get {note_name}`, atau `#{note_name}`"
        .format(note_name=note_name, chat_name=chat_name),
        parse_mode=ParseMode.MARKDOWN)