-
Notifications
You must be signed in to change notification settings - Fork 1
/
starterbot.py
31 lines (29 loc) · 1.93 KB
/
starterbot.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
import os
import time
from slackclient import SlackClient
# instantiate Slack & Twilio clients
sc = SlackClient(os.environ.get('SLACK_BOT_TOKEN'))
if __name__ == "__main__":
PURPOSE = "This is *Dynamic Index* "+"```We aim To produce winners in the Ongoing Facebook Bot challenge by working together as a Major team, hence mentoring & providing help to Sub-Teams partaking in the Facebook Bot Challenge```"
if sc.rtm_connect():
while True:
new_evts = sc.rtm_read()
for evt in new_evts:
if "type" in evt:
if evt['type']=="message" and evt['channel']=="D4FUG4926":
if evt['user'] != "U4G8M9WEB" and "<@U4G8M9WEB>" not in evt['text']:
user_info=sc.api_call("users.info", user=evt['user'])
response = "Hi, <@"+user_info['user']['name']+">"+"\n"+" I only welcome new members to the channel."
sc.api_call("chat.postMessage", channel=evt['channel'], text=response, as_user=True)
if 'subtype' in evt:
if evt['subtype'] == 'channel_join' and 'joined' in evt['text']:
user_info=sc.api_call("users.info", user=evt['user'])
response = "Welcome <@"+user_info['user']['name']+">"+"\n"+PURPOSE
sc.api_call("chat.postMessage", channel=evt['channel'], text=response, as_user=True)
if 'text' in evt:
if evt['type'] == 'message' and "<@U4G8M9WEB>" in evt['text']:
user_info=sc.api_call("users.info", user=evt['user'])
response = "Hi, <@"+user_info['user']['name']+">"+"\n"+" I only welcome new members to the channel."
sc.api_call("chat.postMessage", channel=evt['channel'], text=response, as_user=True)
else:
print "Connection Failed, invalid token?"