-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
38 lines (28 loc) · 1.09 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
from datetime import datetime
from dateutil import parser
from flask import Flask, request, abort
app = Flask(__name__)
FILE_TO_WRITE_TO = '/home/j/obs_stuffs/chatlog.txt'
@app.route('/webhook', methods=['POST'])
def webhook():
if request.method == 'POST':
message = request.json['eventData'].get('body')
user = request.json['eventData'].get('user').get('displayName')
timestamp = request.json['eventData'].get('timestamp')
formatted = datetime.strftime(parser.isoparse(timestamp), '%H:%M:%S')
if user and message and timestamp:
write_out_chatlog(formatted, user, message)
return 'success', 200
else:
abort(400)
def check_for_tts(message):
if message.startswith("!tts "):
speak = message.split('!tts ')[1]
os.system(f'echo "{speak}" | festival --tts')
def write_out_chatlog(timestamp, user, message):
with open(FILE_TO_WRITE_TO, mode='a') as chatlog:
chatlog.write(f"{timestamp} {user}: {message}\n")
check_for_tts(message)
if __name__ == "__main__":
app.run(host='0.0.0.0')