Exemplo n.º 1
0
def start_command(bot, message: Message):
    user_id = message.from_user.id
    user_data = bot.users.get(user_id)
    if not user_data:
        current_time = time()
        telegram_user = message.from_user
        user_data = {
            'id': user_id,
            'created': current_time,
            'last_request_ts': current_time,
            'bot_mode': bot.config.get('default_mode', 'multiple_notes'),
            'telegram': {
                'first_name': telegram_user.first_name,
                'last_name': telegram_user.last_name,
                'username': telegram_user.username,
                'chat_id': message.chat.id,
            },
            'evernote': {
                'access': {
                    'permission': 'basic'
                },
            },
        }
        bot.users.create(user_data)

    user = BotUser(**user_data)
    message_text = '''Welcome! It's bot for saving your notes to Evernote on fly.
Please tap on button below to link your Evernote account with bot.'''
    user.evernote.oauth = get_evernote_oauth_data(bot, user, message_text)
    bot.users.save(user.asdict())
Exemplo n.º 2
0
 def switch_mode_one_note(self, bot_user: BotUser):
     chat_id = bot_user.telegram.chat_id
     evernote_data = bot_user.evernote
     if evernote_data.access.permission == 'full':
         note = self.evernote(bot_user).create_note(
             evernote_data.notebook.guid,
             title='Telegram bot notes'
         )
         bot_user.bot_mode = 'one_note' # TODO: move up
         evernote_data.shared_note_id = note.guid
         note_url = self.evernote(bot_user).get_note_link(note.guid)
         text = f'Your notes will be saved to <a href="{note_url}">this note</a>'
         self.api.sendMessage(chat_id, text, json.dumps({'hide_keyboard': True}), parse_mode='Html')
     else:
         text = 'To enable "One note" mode you have to allow to the bot both reading and updating your notes'
         self.api.sendMessage(chat_id, text, json.dumps({'hide_keyboard': True}))
         message_text = 'Please, sign in and give the permissions to the bot.'
         bot_user.evernote.oauth = get_evernote_oauth_data(self, bot_user,
             message_text, access='full')