Improved CF functionality, added logging and bash runner script.
This commit is contained in:
parent
c455543a96
commit
b41c142043
5 changed files with 15062 additions and 27 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,4 +2,5 @@
|
|||
**/*.pyc
|
||||
**/__pycache__/**
|
||||
**/.vscode/**
|
||||
logs/**
|
||||
.api_token**
|
||||
|
|
11
bot_logging.py
Normal file
11
bot_logging.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
from datetime import datetime as dt
|
||||
import datetime
|
||||
|
||||
def log_output(logs):
|
||||
log_filename = '_'.join('Bot Logs {0}'.format(datetime.date(dt.today().year, dt.today().month,dt.today().day).isoformat()).split())
|
||||
|
||||
log_file = open('logs/' + log_filename, 'a+')
|
||||
|
||||
log_file.write(logs)
|
||||
|
||||
log_file.close()
|
3
runner.sh
Executable file
3
runner.sh
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
SLACK_API_TOKEN=$(cat .api_token) ~/miniconda3/bin/python slack-bot-testing.py &
|
|
@ -1,40 +1,36 @@
|
|||
import os
|
||||
import slack
|
||||
import import_db
|
||||
from import_db import import_cf_words
|
||||
from random import randrange as rr
|
||||
'''
|
||||
client = slack.WebClient(token=os.environ['SLACK_API_TOKEN'])
|
||||
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())
|
||||
|
||||
response = client.chat_postMessage(
|
||||
channel='#general',
|
||||
text='Hello, world!'
|
||||
)
|
||||
assert response['ok']
|
||||
assert response['message']['text'] == 'Hello, world!'
|
||||
'''
|
||||
print('I am running.')
|
||||
|
||||
words = import_db.import_cf_words()
|
||||
words = import_cf_words()
|
||||
|
||||
@slack.RTMClient.run_on(event='message')
|
||||
def say_hello(**payload):
|
||||
print(payload['data'])
|
||||
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 'cf' in data['text'].lower():
|
||||
channel_id = data['channel']
|
||||
thread_ts = data['ts']
|
||||
user = data['user']
|
||||
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())
|
||||
)
|
||||
|
||||
web_client.chat_postMessage(
|
||||
channel=channel_id,
|
||||
text='CF, also known as: {0} {1}'.format((words['c'][rr(len(words['c']))]).capitalize(), (words['f'][rr(len(words['f']))]).capitalize()),
|
||||
)
|
||||
except:
|
||||
print('lmao wtf')
|
||||
except Exception as e:
|
||||
print(e)
|
||||
output += '{}\tThat weird error happened again let\'s fix that.\n'.format(datetime.now())
|
||||
log_output(output)
|
||||
|
||||
slack_token = os.environ["SLACK_API_TOKEN"]
|
||||
rtm_client = slack.RTMClient(token=slack_token)
|
||||
|
|
15024
word_db.txt
15024
word_db.txt
File diff suppressed because it is too large
Load diff
Reference in a new issue