Compare commits
No commits in common. "dev" and "master" have entirely different histories.
3 changed files with 2 additions and 41 deletions
|
@ -7,7 +7,7 @@ Firstly, this bot was written using BASH so I'm unsure how well this will run on
|
||||||
Clone this repo, then make sure you have the `slackclient` module installed in your python environment.
|
Clone this repo, then make sure you have the `slackclient` module installed in your python environment.
|
||||||
You will need an API token from Slack, you can learn that and more on how to set up a bot from this documentation: https://github.com/slackapi/python-slackclient/blob/master/tutorial/01-creating-the-slack-app.md
|
You will need an API token from Slack, you can learn that and more on how to set up a bot from this documentation: https://github.com/slackapi/python-slackclient/blob/master/tutorial/01-creating-the-slack-app.md
|
||||||
Once you have set up and installed your app/bot, you can run it by typing:
|
Once you have set up and installed your app/bot, you can run it by typing:
|
||||||
`./runner.sh prod`
|
`./runner.sh`
|
||||||
|
|
||||||
The bot should automatically put itself in the background, currently the only way to kill it is either to execute a `kill` command or use something like `htop` to kill the process.
|
The bot should automatically put itself in the background, currently the only way to kill it is either to execute a `kill` command or use something like `htop` to kill the process.
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
RUNNER_ENV=$1
|
SLACK_API_TOKEN=$(cat .api_token) ~/miniconda3/bin/python slack-bot-testing.py &
|
||||||
|
|
||||||
SLACK_API_TOKEN=$(cat .api_token) ~/miniconda3/bin/python slack-bot-$RUNNER_ENV.py &
|
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
from import_db import import_cf_words
|
|
||||||
from random import randrange as rr
|
|
||||||
from bot_logging import log_output
|
|
||||||
from datetime import datetime
|
|
||||||
import slack
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
|
|
||||||
output = '{}\tI am running\n'.format(datetime.now())
|
|
||||||
|
|
||||||
words = import_cf_words()
|
|
||||||
|
|
||||||
@slack.RTMClient.run_on(event='message')
|
|
||||||
def say_hello(**payload):
|
|
||||||
output = '{0}\t{1}\n'.format(datetime.now(), payload['data'])
|
|
||||||
data = payload['data']
|
|
||||||
web_client = payload['web_client']
|
|
||||||
rtm_client = payload['rtm_client']
|
|
||||||
try:
|
|
||||||
if 'text' in data and 'user' in data:
|
|
||||||
match = re.search('(\\bc[a-zA-Z]+ \\bf[a-zA-Z]+|cf)', data['text'].lower())
|
|
||||||
if match:
|
|
||||||
match_formatted = ' '.join([ m.capitalize() for m in match.groups()[0].split() ])
|
|
||||||
web_client.chat_postMessage(
|
|
||||||
channel = data['channel'],
|
|
||||||
text = '{0}, also known as: {1} {2}'.format(match_formatted, (words['c'][rr(len(words['c']))]).capitalize(), (words['f'][rr(len(words['f']))]).capitalize())
|
|
||||||
)
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
output += '{0}\tAn error occurred: {1}\n'.format(datetime.now(), e)
|
|
||||||
log_output(output)
|
|
||||||
|
|
||||||
slack_token = os.environ["SLACK_API_TOKEN"]
|
|
||||||
rtm_client = slack.RTMClient(token=slack_token)
|
|
||||||
rtm_client.start()
|
|
||||||
|
|
Reference in a new issue