Exemple #1
0
    def handler(self, bot, update, *args, **kwargs):
        auth_data = kwargs.get('auth_data')
        username = kwargs.get('username')
        button_list = list()
        text = 'Pick up one of the statuses:'
        reply_markup = None

        # getting statuses from user's unresolved issues
        raw_items = self.app.jira.get_issues(username=username,
                                             auth_data=auth_data)
        statuses = {issue.fields.status.name for issue in raw_items}

        # creating an inline keyboard for showing buttons
        if statuses:
            for status in sorted(statuses):
                button_list.append(
                    InlineKeyboardButton(
                        status,
                        callback_data='user_status:{}:{}'.format(
                            username, status)))
            reply_markup = InlineKeyboardMarkup(
                build_menu(button_list, n_cols=2))
        else:
            text = 'You do not have assigned issues'

        self.app.send(bot, update, text=text, buttons=reply_markup)
Exemple #2
0
    def handler(self, bot, update, *args, **kwargs):
        auth_data = kwargs.get('auth_data')
        project = kwargs.get('project')
        button_list = list()
        text = 'Pick up one of the statuses:'
        reply_markup = None

        # getting statuses from projects unresolved issues
        raw_items = self.app.jira.get_project_issues(project=project,
                                                     auth_data=auth_data)
        statuses = {issue.fields.status.name for issue in raw_items}

        # creating an inline keyboard for showing buttons
        if statuses:
            for status in sorted(statuses):
                button_list.append(
                    InlineKeyboardButton(
                        status,
                        callback_data='project_status:{}:{}'.format(
                            project, status)))
            reply_markup = InlineKeyboardMarkup(
                build_menu(button_list, n_cols=2))
        else:
            text = 'The project "{}" has no issues'.format(project)

        self.app.send(bot, update, text=text, buttons=reply_markup)
Exemple #3
0
    def handler(self, bot, update, *args, **kwargs):
        auth_data = kwargs.get('auth_data')
        arguments = kwargs.get('args')
        options = self.resolve_arguments(arguments, auth_data)

        host_webhook = self.app.db.get_webhook(host_url=auth_data.jira_host)

        if not host_webhook:
            confirmation_buttons = [
                InlineKeyboardButton(text='No',
                                     callback_data='create_webhook:{}'.format(
                                         self.negative_answer)),
                InlineKeyboardButton(text='Yes',
                                     callback_data='create_webhook:{}'.format(
                                         self.positive_answer)),
            ]
            buttons = InlineKeyboardMarkup(
                build_menu(confirmation_buttons, n_cols=2))
            text = (
                f'Have no existing webhook for {auth_data.jira_host}. Do you want to create one?\n'
                '<b>NOTE:</b> You must have an Administrator permissions for your Jira'
            )
            return self.app.send(bot, update, text=text, buttons=buttons)

        CreateSubscribeCommand(self.app).handler(bot,
                                                 update,
                                                 topic=options.target,
                                                 name=options.key,
                                                 webhook=host_webhook)
    def handler(self, bot, update, *args, **kwargs):
        user_id = update.effective_user.id
        entries = self.app.db.get_schedule_commands(user_id)
        buttons = list()
        if entries.count():
            text = 'Click to remove schedule commands:'
            for entry in entries:
                data = f'unschedule:{entry["_id"]}'
                button = InlineKeyboardButton(entry.get("name"),
                                              callback_data=data)
                buttons.append(button)
            reply_markup = InlineKeyboardMarkup(build_menu(buttons))
        else:
            text = "You don't have schedule commands"
            reply_markup = None

        self.app.send(bot, update, text=text, buttons=reply_markup)
Exemple #5
0
    def handler(self, bot, update, *args, **kwargs):
        button_list = [
            InlineKeyboardButton('Yes',
                                 callback_data='disconnect:{}'.format(
                                     self.positive_answer)),
            InlineKeyboardButton('No',
                                 callback_data='disconnect:{}'.format(
                                     self.negative_answer)),
        ]

        reply_markup = InlineKeyboardMarkup(build_menu(button_list, n_cols=2))
        self.app.send(
            bot,
            update,
            text=
            'Are you sure you want to log out? All credentials associated with this user will be lost.',
            buttons=reply_markup)
Exemple #6
0
    def handler(self, bot, update, *args, **kwargs):
        auth_data = kwargs.get('auth_data')
        options = kwargs.get('args')
        callback_data = 'filter_p:{}:{}'
        filter_buttons = list()

        filters = self.app.jira.get_favourite_filters(auth_data=auth_data)
        if options and filters:
            filter_name = ' '.join(options)

            if filter_name in filters.keys():
                kwargs.update({
                    'filter_name': filter_name,
                    'filter_id': filters.get(filter_name)
                })
                return FilterIssuesCommand(self.app).handler(
                    bot, update, *args, **kwargs)
            else:
                text = "Filter {} is not in your favorites".format(filter_name)
                return self.app.send(bot, update, text=text)
        elif filters:
            for name in filters.keys():
                filter_buttons.append(
                    InlineKeyboardButton(text=name,
                                         callback_data=callback_data.format(
                                             name, filters[name])))

            buttons = InlineKeyboardMarkup(build_menu(filter_buttons,
                                                      n_cols=2))
            if buttons:
                text = "Pick up one of the filters:"
                return self.app.send(bot, update, text=text, buttons=buttons)

        self.app.send(
            bot,
            update,
            text=
            "You don't have any favourite filters. Add some filters in your Jira first"
        )
Exemple #7
0
    def handler(self, bot, update, *args, **kwargs):
        auth_data = kwargs.get('auth_data')
        options = kwargs.get('args')
        parameters_names = ('target', 'name')
        params = dict(zip_longest(parameters_names, options))

        if not params['target']:
            confirmation_buttons = [
                InlineKeyboardButton(
                    text='No',
                    callback_data=
                    f'unsubscribe_all:{WatchDispatcherCommand.negative_answer}'
                ),
                InlineKeyboardButton(
                    text='Yes',
                    callback_data=
                    f'unsubscribe_all:{WatchDispatcherCommand.positive_answer}'
                ),
            ]
            buttons = InlineKeyboardMarkup(
                build_menu(confirmation_buttons, n_cols=2))
            text = 'Do you want to unsubscribe from all updates?'
            return self.app.send(bot, update, text=text, buttons=buttons)

        if params['target'] not in self.targets or not params['name']:
            return self.app.send(bot, update, text=self.description)

        if params['target'] == 'project':
            self.app.jira.is_project_exists(project=params['name'],
                                            auth_data=auth_data)
        elif params['target'] == 'issue':
            self.app.jira.is_issue_exists(issue=params['name'],
                                          auth_data=auth_data)

        kwargs.update({'topic': params['target'], 'name': params['name']})
        UnsubscribeOneItemCommand(self.app).handler(bot, update, **kwargs)