trying to combine scripts into bot.py
This commit is contained in:
parent
93551c8460
commit
dfeebe53d9
@ -3,12 +3,15 @@ import time
|
|||||||
import re
|
import re
|
||||||
import logging
|
import logging
|
||||||
from slackclient import SlackClient
|
from slackclient import SlackClient
|
||||||
|
import pdb
|
||||||
|
|
||||||
|
|
||||||
# instantiate Slack client
|
# instantiate Slack client
|
||||||
slack_client = SlackClient(os.environ.get('SLACK_BOT_TOKEN'))
|
slack_client = SlackClient(os.environ.get('SLACK_BOT_TOKEN'))
|
||||||
# starterbot's user ID in Slack: value is assigned after the bot starts up
|
# starterbot's user ID in Slack: value is assigned after the bot starts up
|
||||||
starterbot_id = None
|
starterbot_id = None
|
||||||
|
# channel i want to get ID from
|
||||||
|
bot_channel = "bots-like-gaston"
|
||||||
|
|
||||||
# constants
|
# constants
|
||||||
RTM_READ_DELAY = 1 # 1 second delay between reading from RTM
|
RTM_READ_DELAY = 1 # 1 second delay between reading from RTM
|
||||||
@ -59,6 +62,19 @@ def handle_command(command, channel):
|
|||||||
text=response or default_response
|
text=response or default_response
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def reactable_message(event):
|
||||||
|
"""Test whether a (Slack) event is a reaction-able message
|
||||||
|
|
||||||
|
Check whether it's not a DM, it's not empty, and it's actually a message
|
||||||
|
"""
|
||||||
|
return 'channel' in event and 'text' in event and event.get('type') == 'message'
|
||||||
|
|
||||||
|
def get_channel_ID(channelName):
|
||||||
|
for channel in slack_client.api_call('channels.list')["channels"]:
|
||||||
|
if channel["name"] == channelName:
|
||||||
|
return channel["id"]
|
||||||
|
raise Exception("couldn't find channel requested.")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
logging.basicConfig(filename='mojojojo.log', level=logging.INFO)
|
logging.basicConfig(filename='mojojojo.log', level=logging.INFO)
|
||||||
logging.info('Started')
|
logging.info('Started')
|
||||||
@ -71,6 +87,21 @@ if __name__ == "__main__":
|
|||||||
if command:
|
if command:
|
||||||
handle_command(command, channel)
|
handle_command(command, channel)
|
||||||
time.sleep(RTM_READ_DELAY)
|
time.sleep(RTM_READ_DELAY)
|
||||||
|
events = slack_client.rtm_read()
|
||||||
|
for event in events:
|
||||||
|
if reactable_message(event):
|
||||||
|
channel = event['channel']
|
||||||
|
text = event['text']
|
||||||
|
if 'blah' in text.lower():
|
||||||
|
print(event.get('ts')) # does this populate
|
||||||
|
#pdb.set_trace()
|
||||||
|
slack_client.api_call(
|
||||||
|
'reactions.add',
|
||||||
|
channel = get_channel_ID("BOTS"),
|
||||||
|
name = "thumbsup",
|
||||||
|
timestamp = event.get('ts')
|
||||||
|
)
|
||||||
|
time.sleep(1)
|
||||||
logging.info("Client worked. No errors (we think lol)")
|
logging.info("Client worked. No errors (we think lol)")
|
||||||
else:
|
else:
|
||||||
print("Connection failed. Exception traceback printed above.")
|
print("Connection failed. Exception traceback printed above.")
|
||||||
|
@ -42,7 +42,7 @@ if slack_client.rtm_connect():
|
|||||||
#pdb.set_trace()
|
#pdb.set_trace()
|
||||||
slack_client.api_call(
|
slack_client.api_call(
|
||||||
'reactions.add',
|
'reactions.add',
|
||||||
channel = get_channel_ID(bot_channel),
|
channel = get_channel_ID("BOTS"),
|
||||||
name = "thumbsup",
|
name = "thumbsup",
|
||||||
timestamp = event.get('ts')
|
timestamp = event.get('ts')
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user