예제 #1
0
def remove_all_notes(update, context):
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message

    if chat.type == "private":
        chat.title = tl(chat.id, "local notes")
    else:
        owner = chat.get_member(user.id)
        chat.title = chat.title
        if owner.status != 'creator':
            message.reply_text(tl(chat.id, "You must be this chat creator."))
            return

    note_list = sql.get_all_chat_notes(chat.id)
    if not note_list:
        message.reply_text(tl(chat.id, "No notes in *{}*!").format(chat.title),
                           parse_mode=ParseMode.MARKDOWN)
        return

    x = 0
    a_note = []
    for notename in note_list:
        x += 1
        note = notename.name.lower()
        a_note.append(note)

    for note in a_note:
        sql.rm_note(chat.id, note)

    message.reply_text(
        tl(chat.id, "{} notes from this chat have been removed.").format(x))
예제 #2
0
def remove_all_notes(bot: Bot, update: Update):
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message

    if chat.type == "private":
        chat.title = tld(chat.id, "note_is_local")
    else:
        owner = chat.get_member(user.id)
        chat.title = chat.title
        if owner.status != 'creator':
            message.reply_text(tld(chat.id, "notes_must_be_creator"))
            return

    note_list = sql.get_all_chat_notes(chat.id)
    if not note_list:
        message.reply_text(tld(chat.id,
                               "note_none_in_chat").format(chat.title),
                           parse_mode=ParseMode.MARKDOWN)
        return

    x = 0
    a_note = []
    for notename in note_list:
        x += 1
        note = notename.name.lower()
        a_note.append(note)

    for note in a_note:
        sql.rm_note(chat.id, note)

    message.reply_text(tld(chat.id, "notes_cleanup_success").format(x))
예제 #3
0
파일: notes.py 프로젝트: MhdRezza/hitsuki
def list_notes(update, context):
    chat = update.effective_chat
    user = update.effective_user
    conn = connected(context.bot, update, chat, user.id, need_admin=False)
    if conn:
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
        msg = tl(update.effective_message, "*Notes on {}:*\n").format(chat_name)
    else:
        chat_id = update.effective_chat.id
        if chat.type == "private":
            chat_name = ""
            msg = tl(update.effective_message, "*Local notes:*\n")
        else:
            chat_name = chat.title
            msg = tl(update.effective_message, "*Notes on {}:*\n").format(chat_name)

    note_list = sql.get_all_chat_notes(chat_id)

    for note in note_list:
        note_name = " • `#{}`\n".format(note.name)
        if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH:
            send_message(update.effective_message, msg, parse_mode=ParseMode.MARKDOWN)
            msg = ""
        msg += note_name

    if msg == tl(update.effective_message, "*Notes on {}:*\n").format(chat_name) or msg == tl(update.effective_message,
                                                                                              "*Local notes:*\n"):
        if conn:
            send_message(update.effective_message, tl(update.effective_message, "No notes in *{}*!").format(chat_name),
                         parse_mode="markdown")
        else:
            send_message(update.effective_message, tl(update.effective_message, "No notes in this chat!"))

    elif len(msg) != 0:
        msg += tl(update.effective_message, "\nYou can retrieve these notes by using `/get notename`, or `#notename`")
        try:
            send_message(update.effective_message, msg, parse_mode=ParseMode.MARKDOWN)
        except BadRequest:
            if chat.type == "private":
                chat_name = ""
                msg = tl(update.effective_message, "<b>Local notes:</b>\n")
            else:
                chat_name = chat.title
                msg = tl(update.effective_message, "<b>Notes on {}:</b>\n").format(chat_name)
            for note in note_list:
                note_name = " - <code>{}</code>\n".format(note.name)
                if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH:
                    send_message(update.effective_message, msg, parse_mode=ParseMode.MARKDOWN)
                    msg = ""
                msg += note_name
            msg += tl(update.effective_message,
                      "\nYou can retrieve these notes by using <code>/get notename</code>, or <code>#notename</code>")
            send_message(update.effective_message, msg, parse_mode=ParseMode.HTML)
예제 #4
0
def list_notes(bot: Bot, update: Update):
    chat = update.effective_chat
    user = update.effective_user
    conn = connected(bot, update, chat, user.id, need_admin=False)
    if conn:
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
        msg = tld(chat.id, "note_in_chat")
    else:
        chat_id = update.effective_chat.id
        if chat.type == "private":
            chat_name = tld(chat.id, "note_is_local")
            msg = tld(chat.id, "note_in_local")
        else:
            chat_name = chat.title
            msg = tld(chat.id, "note_in_chat")

    note_list = sql.get_all_chat_notes(chat_id)

    for note in note_list:
        note_name = " • `#{}`\n".format(note.name.lower())
        if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH:
            update.effective_message.reply_text(msg,
                                                parse_mode=ParseMode.MARKDOWN)
            msg = ""
        msg += note_name

    if not note_list:
        update.effective_message.reply_text(tld(
            chat.id, "note_none_in_chat").format(chat_name),
                                            parse_mode=ParseMode.MARKDOWN)

    elif len(msg) != 0:
        msg += tld(chat.id, "note_get")
        update.effective_message.reply_text(msg.format(chat_name),
                                            parse_mode=ParseMode.MARKDOWN)
예제 #5
0
def __chat_settings__(bot, update, chat, chatP, user):
    chat_id = chat.id
    user_id = user.id
    notes = sql.get_all_chat_notes(chat_id)
    return (tld(user_id,
                "There are `{}` notes in this chat.").format(len(notes)))
예제 #6
0
def __chat_settings__(chat_id, user_id):
    notes = sql.get_all_chat_notes(chat_id)
    return tl(user_id, "There are `{}` notes in this chat.").format(len(notes))
예제 #7
0
    chat = update.effective_chat
    user = update.effective_user
    if conn := connected(bot, update, chat, user.id, need_admin=False):
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
        msg = tld(chat.id, "note_in_chat")
    else:
        chat_id = update.effective_chat.id
        if chat.type == "private":
            chat_name = tld(chat.id, "note_is_local")
            msg = tld(chat.id, "note_in_local")
        else:
            chat_name = chat.title
            msg = tld(chat.id, "note_in_chat")

    note_list = sql.get_all_chat_notes(chat_id)

    for note in note_list:
        note_name = " • `#{}`\n".format(note.name.lower())
        if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH:
            update.effective_message.reply_text(msg,
                                                parse_mode=ParseMode.MARKDOWN)
            msg = ""
        msg += note_name

    if not note_list:
        update.effective_message.reply_text(tld(
            chat.id, "note_none_in_chat").format(chat_name),
                                            parse_mode=ParseMode.MARKDOWN)

    elif len(msg) != 0: