forked from slackapi/python-slack-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
58 lines (52 loc) · 1.89 KB
/
main.py
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
from slackclient import SlackClient
from random import randint
from pprint import pprint
import time
import os
token = os.environ.get('SLACKBOT_LUMBERGH_TOKEN')
slack_client = SlackClient(token)
hits = [
"you guys",
"these guys",
"my guys",
"those guys",
"hey guys",
"hi guys",
"the guys",
"these guys",
"thanks guys",
"guyz"
]
responses = [
'Some people in the community find "guys" alienating, next time would you consider folks? :slightly_smiling_face: (<http://bit.ly/2uJCn3y|Learn more>)',
'Some people in the community find "guys" alienating, next time would you consider all? :slightly_smiling_face: (<http://bit.ly/2uJCn3y|Learn more>)',
'Some people in the community find "guys" alienating, next time would you consider y\'all? :slightly_smiling_face: (<http://bit.ly/2uJCn3y|Learn more>)',
'Some people in the community find "guys" alienating, next time would you consider everyone? :slightly_smiling_face: (<http://bit.ly/2uJCn3y|Learn more>)'
]
if slack_client.rtm_connect():
while True:
events = slack_client.rtm_read()
for event in events:
if (
'channel' in event and
'text' in event and
'user' in event and
'ts' in event and
event.get('type') == 'message'
):
channel = event['channel']
text = event['text']
user = event['user']
for hit in hits:
if hit in text.lower():
slack_client.api_call(
'chat.postEphemeral',
channel=channel,
text=responses[randint(0, len(responses)-1)],
user = user,
as_user = 'true',
)
break
time.sleep(1)
else:
print('Connection failed, invalid token?')