コード例 #1
0
def main():
    parser = argparse.ArgumentParser(
        description='Simple Bugzilla triage helper bot for Slack.')
    parser.add_argument('-c',
                        '--config',
                        metavar='FILE',
                        default='~/.triagebot',
                        help='config file')
    parser.add_argument('-d',
                        '--database',
                        metavar='FILE',
                        default='~/.triagebot-db',
                        help='database file')
    args = parser.parse_args()

    # Read config
    with open(os.path.expanduser(args.config)) as fh:
        config = DottedDict(yaml.safe_load(fh))
        config.database = os.path.expanduser(args.database)
    env_map = (('TRIAGEBOT_SLACK_APP_TOKEN',
                'slack-app-token'), ('TRIAGEBOT_SLACK_TOKEN', 'slack-token'),
               ('TRIAGEBOT_BUGZILLA_KEY', 'bugzilla-key'))
    for env, config_key in env_map:
        v = os.environ.get(env)
        if v:
            setattr(config, config_key, v)

    # Connect to services
    client = WebClient(token=config.slack_token)
    # store our user ID
    config.bot_id = client.auth_test()['user_id']
    bzapi = bugzilla.Bugzilla(config.bugzilla,
                              api_key=config.bugzilla_key,
                              force_rest=True)
    if not bzapi.logged_in:
        raise Exception('Did not authenticate')
    db = Database(config)

    # Start socket-mode listener in the background
    socket_client = SocketModeClient(
        app_token=config.slack_app_token,
        web_client=WebClient(token=config.slack_token))
    socket_client.socket_mode_request_listeners.append(
        lambda socket_client, req: process_event(config, socket_client, req))
    socket_client.connect()

    # Run scheduler
    Scheduler(config, client, bzapi, db).run()
コード例 #2
0
ファイル: 11bot.py プロジェクト: bgilbert/11bot
def main():
    parser = argparse.ArgumentParser(
        description='Slack bot to send periodic 1:1 invitations.')
    parser.add_argument('-c',
                        '--config',
                        metavar='FILE',
                        default='~/.11bot',
                        help='config file')
    parser.add_argument('-d',
                        '--database',
                        metavar='FILE',
                        default='~/.11bot-db',
                        help='database file')
    args = parser.parse_args()

    # Self-test
    Grouping.selftest()

    # Read config
    with open(os.path.expanduser(args.config)) as fh:
        config = DottedDict(yaml.safe_load(fh))
        config.database = os.path.expanduser(args.database)
    env_map = (
        ('ELEVENBOT_APP_TOKEN', 'app-token'),
        ('ELEVENBOT_TOKEN', 'token'),
    )
    for env, config_key in env_map:
        v = os.environ.get(env)
        if v:
            setattr(config, config_key, v)

    # Connect to services
    client = WebClient(token=config.token)
    # store our user ID
    config.bot_id = client.auth_test()['user_id']
    db = Database(config)

    # Start socket-mode listener in the background
    socket_client = SocketModeClient(app_token=config.app_token,
                                     web_client=WebClient(token=config.token))
    socket_client.socket_mode_request_listeners.append(
        lambda socket_client, req: process_event(config, socket_client, req))
    socket_client.connect()

    # Run scheduler
    Scheduler(config, client, db).run()