Created
July 4, 2015 22:23
-
-
Save julianeon/2541c9c8eb1079b10631 to your computer and use it in GitHub Desktop.
Slack bot example, adapted from my working version.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time, json, yaml, re, os, myfunc | |
from slackclient import SlackClient | |
with open('slack.yaml', 'r') as f: | |
doc = yaml.load(f) | |
user_id=doc["user_id"] | |
user_name=doc["user_name"] | |
user_address=doc["user_address"] | |
print user_id | |
id_to_name=dict(zip(user_id,user_name)) | |
id_to_address=dict(zip(user_id,user_address)) | |
token = doc["token"] | |
sc = SlackClient(token) | |
sc = SlackClient(token) | |
if not sc.rtm_connect(): | |
exit("Failed to connect.") | |
while True: | |
new_evts = sc.rtm_read() | |
for evt in new_evts: | |
print(evt) | |
if "type" in evt: | |
if evt["type"] == "message" and "text" in evt: | |
message=evt["text"] | |
muser=evt["user"] | |
uid=str(muser) | |
sender=id_to_name[uid] | |
pline="" | |
pay_xrp=myfunc.send_xrp_amount | |
if "tipbot" in message: | |
tline=message.split() | |
for word in tline: | |
cleanword=re.sub('[@<>]', '', word) | |
if cleanword in user_id: | |
print "USER_ID" | |
receiver=id_to_name[cleanword] | |
pline="Not found. Message the admin for more information." | |
if cleanword in id_to_address: | |
destination=id_to_address[cleanword] | |
sender="*"+sender+"*" | |
receiver="*"+receiver+"*" | |
pline= sender + " sent 1 coin to " + receiver + "!" | |
text=pay_coin(destination,"1") | |
print text | |
chan = sc.server.channels.find(evt["channel"]) | |
if chan: | |
chan.send_message(pline) | |
time.sleep(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your tutorials were super helpful! Thanks for all of the work you put into it :D