-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanemoibot
executable file
·98 lines (80 loc) · 3.43 KB
/
anemoibot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python
# package.module
# module description
#
# Author: Allen Leis <[email protected]>
# Created: timestamp
#
# Copyright (C) 2017 Allen Leis
# For license information, see LICENSE
#
# ID: filename.py [] [email protected] $
"""
module description
"""
##########################################################################
# Imports
##########################################################################
from pprint import pprint
import argparse
from anemoi.config import settings
from anemoi.version import get_version
from anemoi.bots.slack import SlackBot
from anemoi.bots.slack.messages import SlackCommsFactory
##########################################################################
# Basic handlers for CLI argument/commands
##########################################################################
def start(slack_access_token, slack_bot_id, darksky_access_token):
bot = SlackBot(
slack_access_token=slack_access_token,
slack_bot_id=slack_bot_id,
darksky_access_token=darksky_access_token
)
bot.start()
def listing():
# TODO: have a autogenerated list of features available to the
# slack bot. Right it just defaults to the darksky mixin as always
# being there. Ideally we could manually turn some off through the
# command line
print 'listing of available integrations goes here (darksky, travis, etc.)'
##########################################################################
# CLI argument parser setup
##########################################################################
def create_parser():
parser = argparse.ArgumentParser(
description='Slack client to respond to user messages',
version=get_version(),
formatter_class=lambda prog: argparse.HelpFormatter(prog,max_help_position=70)
)
# create some samples commands
subparsers = parser.add_subparsers(help='commands')
start_parser = subparsers.add_parser('start', help='List available features of the chatbot')
start_parser.set_defaults(func=start)
list_parser = subparsers.add_parser('list', help='List available features of the chatbot')
list_parser.set_defaults(func=listing)
# add ways to supply custom api keys
# TODO: have this autogenerated based on installed mixins or have each mixin provide
# its own sub parser
slack_group = parser.add_argument_group('slack options')
slack_group.add_argument('--slack_token', action="store", help="for Slack integration", default=settings.slack.access_token)
slack_group.add_argument('--bot_id', action="store", help="Slack ID of the bot", default=settings.slack.bot_id)
darksky_group = parser.add_argument_group('dark sky options')
darksky_group.add_argument('--darksky_token', action="store", help="for DarkSky integration", default=settings.dark_sky.access_token)
return parser
##########################################################################
# Execution
##########################################################################
if __name__ == '__main__':
# setup argument parser
parser = create_parser()
arguments = parser.parse_args()
# handle arguments
# TODO: this could probably be cleaned up by sending all args into all handlers
if arguments.func == start:
arguments.func(
arguments.slack_token,
arguments.bot_id,
arguments.darksky_token
)
if arguments.func == listing:
listing()