예제 #1
0
 def projects(self, user: User):
     projects = ' '.join(
         ['#' + project['name'] for project in user.api.projects.all()])
     if projects:
         user.send_message('Your projects: ' + projects)
     else:
         user.send_message('You don\'t have any projects!')
예제 #2
0
 def labels(self, user: User):
     labels = ' '.join(
         ['@' + label['name'] for label in user.api.labels.all()])
     if labels:
         user.send_message('Your labels: ' + labels)
     else:
         user.send_message('You don\'t have any labels!')
예제 #3
0
 def wrap(self, _, update, *args, **kwargs):
     assert isinstance(User.query, Query)
     assert isinstance(update.message, Message)
     tguser = update.message.from_user
     assert isinstance(tguser, TgUser)
     user = User.query.filter(User.tg_id == tguser.id).one_or_none()
     now = datetime.now()
     if not user:
         user = User(
             tg_id=tguser.id,
             first_name=tguser.first_name,
             last_name=tguser.last_name or '',
             username=tguser.username,
             created_at=now,
             last_active_at=now,
         )
         db.session.add(user)
         db.session.commit()
     else:
         user.first_name = tguser.first_name
         user.last_name = tguser.last_name or ''
         user.username = tguser.username
         user.last_active_at = now
         user.is_active = True
     user.update = update
     user.message = update.message
     try:
         func(self, user, *args, **kwargs)
     except Flow:
         pass
     db.session.commit()
예제 #4
0
 def base_welcome(self, user: User):
     projects = ' '.join(
         ['#' + project['name'] for project in user.api.projects.all()])
     labels = ' '.join(
         ['@' + label['name'] for label in user.api.labels.all()])
     text = 'You were succesfully authorized!'
     if projects or labels:
         text += '\n'
     if projects:
         text += '\nProjects: ' + projects
     if labels:
         text += '\nLabels: ' + labels
     text += '\n\nNow you can send me a task that you want to save for later...'
     user.send_message(text)
예제 #5
0
 def any_text(self, user: User):
     item = user.api.quick.add(user.message.text)
     if not item:
         user.send_message('Could not create task')
         return
     labels = item['labels']
     if labels:
         labels = [
             '@' + label.data['name'] for label in user.api.labels.all()
             if label.data['id'] in labels
         ]
     answer = 'Task added:\n{} {} {}'.format(item['content'],
                                             ' '.join(labels),
                                             item['date_string'] or '')
     user.send_message(answer)
예제 #6
0
 def wrap(self, user: User):
     user.init_api()
     if not user.auth:
         assert isinstance(self, MyBot), self
         user.state = str(uuid4())
         db.session.commit()
         with app.app_context():
             url = url_for('todoist.need_auth',
                           state=user.state,
                           _external=True)
             user.send_message(
                 'You need to authorize: {}\n'.format(url) +
                 'We promise, that we will not share you private information with anyone, or look at it by ourselves.\n'
                 'You can check it open source code of this bot: {}'.format(
                     app.config['PROJECT_REPOSITORY_LINK']))
             raise Stop
     func(self, user)
예제 #7
0
 def wrap(self, user: User):
     while True:
         if not user.message or not user.message.text or not str(
                 user.message.text).startswith('/start '):
             break
         param = str(user.message.text).split(' ', 1)[1]
         if not param.startswith('error_'):
             break
         with app.app_context():
             if not user.state:
                 user.state = str(uuid4())
             url = url_for('todoist.need_auth',
                           state=user.state,
                           _external=True)
             if param == 'error_access_denied':
                 user.send_message(
                     'If you want to use bot you have to grant us access to your Todoist account: {}\n'
                     .format(url) + 'We care about your privacy!')
             elif param == 'error_invalid_scope':
                 user.send_message('Shit happens...\n'
                                   'Please, try again: {}\n'.format(url))
             raise Stop
         break
     func(self, user)
예제 #8
0
 def notification(self, user: User, item: Item):
     text = '{} {}'.format(emoji.DOUBLE_RED_EXCLAMATION,
                           item.data['content'])
     return user.send_message(text)
예제 #9
0
 def error(self, user: User, error):
     user.send_message('Error occurred')
     logging.warning('Error occurred: {}'.format(error))
예제 #10
0
 def any_other(self, user: User):
     user.send_message('This type of content is not supported.')
예제 #11
0
 def stop(self, user: User):
     user.send_message(
         'We will not send you anything again until you send a message me.')
     user.is_active = False
예제 #12
0
 def start(self, user: User):
     user.send_message(
         'You are authorized! Everything is okey!\n'
         'Now you can create new task just by writing it to me...')