Skip to content

Instantly share code, notes, and snippets.

@ckinsey
Created September 6, 2016 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ckinsey/ee8cb927ac8bfa96510704285d2560d6 to your computer and use it in GitHub Desktop.
Save ckinsey/ee8cb927ac8bfa96510704285d2560d6 to your computer and use it in GitHub Desktop.
Bot.py Basic
import markovify
import time
from slackclient import SlackClient
BOT_TOKEN = "insert bot token here"
GROUP_TOKEN = "insert slack group token here"
def main():
"""
Startup logic and the main application loop to monitor Slack events.
"""
# Create the slackclient instance
sc = SlackClient(BOT_TOKEN)
# Connect to slack
if not sc.rtm_connect():
raise Exception("Couldn't connect to slack.")
# Where the magic happens
while True:
# Examine latest events
for slack_event in sc.rtm_read():
# Disregard events that are not messages
if not slack_event.get('type') == "message":
continue
message = slack_event.get("text")
user = slack_event.get("user")
channel = slack_event.get("channel")
if not message or not user:
continue
######
# Commands we're listening for.
######
if "ping" in message.lower():
sc.rtm_send_message(channel, "ping")
# Sleep for half a second
time.sleep(0.5)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment