Пример #1
0
    def main_menu(self, bot, update):
        from_user = update.message.from_user if update.message else update.callback_query.from_user
        if not self.session.query(
                User.id).filter(User.id == from_user.id).first():
            new_user = User(id=from_user.id,
                            username=from_user.username,
                            first_name=from_user.first_name,
                            last_name=from_user.last_name,
                            language=from_user.language_code)
            self.session.add(new_user)
            self.session.commit()

        note_exist = False if len(Manager.get_notes(
            self.session, from_user.id)) == 0 else True
        if update.message:
            update.message.reply_text(
                text=_('welcome_message'),
                reply_markup=keyboards.main_menu(note_exist=note_exist))
        else:
            query = update.callback_query
            bot.edit_message_text(
                text=_('welcome_message'),
                chat_id=query.message.chat_id,
                message_id=query.message.message_id,
                reply_markup=keyboards.main_menu(note_exist=note_exist))
Пример #2
0
def main_menu(note_exist=True):
    keyboard = [[
        InlineKeyboardButton(_('newـnote'), callback_data=u'/new_note')
    ]]
    if note_exist:
        keyboard.append(
            [InlineKeyboardButton(_('myـnotes'), callback_data=u'/myـnotes')])
    return InlineKeyboardMarkup(keyboard)
Пример #3
0
 def show_notes(self, bot, update):
     query = update.callback_query
     print('show notes for user:'******'your_notes'),
                           chat_id=query.message.chat_id,
                           message_id=query.message.message_id,
                           reply_markup=keyboards.note_list(notes))
Пример #4
0
def note_list(notes):
    def per_type(per):
        return {
            Permission.PT.owner: _('owner'),
            Permission.PT.can_edit: _('can_edit'),
            Permission.PT.can_read: _('read_only')
        }[per]

    keyboard = [[
        InlineKeyboardButton(per_type(note[1]) + note[0],
                             callback_data=u'/note/' + note[0])
    ] for note in notes]
    keyboard.append(
        [InlineKeyboardButton(_('back'), callback_data=u'/main_menu')])
    return InlineKeyboardMarkup(keyboard)
Пример #5
0
 def per_type(per):
     return {
         Permission.PT.owner: _('owner'),
         Permission.PT.can_edit: _('can_edit'),
         Permission.PT.can_read: _('read_only')
     }[per]
Пример #6
0
 def s_new_note_1(self, bot, update):
     update.message.reply_text(text=_('get_title_with_error_title'))
Пример #7
0
 def s_new_note_0(self, bot, update):
     query = update.callback_query
     bot.edit_message_text(text=_('get_title'),
                           chat_id=query.message.chat_id,
                           message_id=query.message.message_id)