File tree 4 files changed +102
-2
lines changed
4 files changed +102
-2
lines changed Original file line number Diff line number Diff line change
1
+ config.yml
2
+ * .pyc
Original file line number Diff line number Diff line change 1
- import requests
2
- import slackweb
1
+ """
2
+ Author: BIT Community
3
+
4
+ Description:
5
+
6
+ bitbot is a simple slack greetings bot developed by the BIT community
7
+ to help promote opensource and BIT code collaboration.
8
+
9
+ """
10
+ from slackclient import SlackClient
11
+ from helpers import load_config
12
+
13
+ try :
14
+ slack_config = load_config (get_settings = "slack" )
15
+ except :
16
+ print ("Problem loading config settings" )
17
+
18
+ if slack_config :
19
+ slack_token = slack_config ['slack_token' ]
20
+ introduction_channel_id = slack_config ['introduction_channel_id' ]
21
+ bot_user = slack_config ['bot_user' ]
22
+ greeting_message = slack_config ['greeting_message' ]
23
+
24
+
25
+ def slack_client_connect ():
26
+ slack_client = SlackClient (slack_token )
27
+ return slack_client
28
+
29
+
30
+ def slack_client_test ():
31
+ slack_client = slack_client_connect ()
32
+ print (slack_client .api_call ('api.test' ))
33
+ print (slack_client .api_call ('auth.test' ))
34
+
35
+
36
+ def slack_post_message (message = None ):
37
+ slack_client = slack_client_connect ()
38
+ if message :
39
+ post = slack_client .api_call ("chat.postMessage" , as_user = "true:" ,
40
+ channel = introduction_channel_id ,
41
+ text = message )
42
+ else :
43
+ post = "There was no message to send."
44
+ return post
45
+
46
+
47
+ #slack_client_test()
48
+ #slack_post_message(message=greeting_message)
49
+
50
+
Original file line number Diff line number Diff line change
1
+ ---
2
+
3
+ slack :
4
+ token : <token>
5
+ bot_user : <bot user>
6
+ introduction_channel_id : <channel id>
7
+ greeting_message : |
8
+ Hi, I'm bitbot :bitlogo: . This is our first community coding project!
9
+ Join in on the fun!
10
+ Hack all the things :neckbeard:!
11
+ Drink all the :beer:!
Original file line number Diff line number Diff line change
1
+ """
2
+ Definition:
3
+ Helper function
4
+ """
5
+
6
+ import yaml
7
+
8
+
9
+ def load_config (get_settings = None ):
10
+ """
11
+ Load config.yml
12
+ """
13
+ config = dict ()
14
+
15
+ if not get_settings :
16
+ return "Please specify what settings you would like to parse"
17
+
18
+ try :
19
+ load_config = yaml .load (open ('config.yml' ))
20
+ except :
21
+ return "Could not load Config file."
22
+ try :
23
+ config ['slack_token' ] = load_config [get_settings ]['token' ]
24
+ except :
25
+ return "Issue loading token in config.yml"
26
+ try :
27
+ config ['bot_user' ] = load_config [get_settings ]['bot_user' ]
28
+ except :
29
+ return "Issue loading bot_user name in config.yml"
30
+ try :
31
+ config ['introduction_channel_id' ] = load_config [get_settings ]['introduction_channel_id' ]
32
+ except :
33
+ return "Issue loading introduction_channel_id in config.yml"
34
+ try :
35
+ config ['greeting_message' ] = load_config [get_settings ]['greeting_message' ]
36
+ except :
37
+ return "Issue loading slack message"
38
+
39
+ return config
You can’t perform that action at this time.
0 commit comments