Bot now posts to correct chat url
This commit is contained in:
parent
ac113944cd
commit
6503f66114
|
@ -3,17 +3,23 @@ import json
|
|||
import random
|
||||
import requests
|
||||
from requests.structures import CaseInsensitiveDict
|
||||
from ameliabot.init_logging import init_logging
|
||||
from ameliabot.logger import logging
|
||||
from ameliabot.quote import Quote
|
||||
from flask import request
|
||||
|
||||
|
||||
init_logging()
|
||||
bot_version = "0.0.1"
|
||||
|
||||
# Get basic owncast bot config
|
||||
try:
|
||||
with open("config/owncast.json", "r") as f:
|
||||
config = json.load(f)
|
||||
logging.info("Configuration loaded")
|
||||
except FileNotFoundError:
|
||||
logging.error("Configuration file not found.")
|
||||
logging.error("Please see README.md for more information.")
|
||||
raise SystemExit
|
||||
|
||||
with open("commands.json", "r") as f:
|
||||
commands = json.load(f)
|
||||
|
@ -43,7 +49,9 @@ def parse_webhook():
|
|||
data = process_chat(data)
|
||||
|
||||
if data:
|
||||
logging.debug("Processed: {}".format(data))
|
||||
send_message(data)
|
||||
|
||||
def send_message(data):
|
||||
data = '{"body": "%s"}' % data
|
||||
resp = requests.post(
|
||||
config["owncast_server"],
|
||||
|
@ -51,7 +59,7 @@ def parse_webhook():
|
|||
data=data.encode('utf-8'))
|
||||
|
||||
if resp.status_code == 200:
|
||||
logging.debug("RESP: {}".format(data))
|
||||
logging.debug("RESP: {}".format(resp.__dict__))
|
||||
else:
|
||||
logging.error("Status code {} returned".format(
|
||||
str(resp.status_code)))
|
||||
|
@ -78,13 +86,11 @@ def get_quote(num):
|
|||
|
||||
|
||||
def process_chat(data):
|
||||
timestamp = "{} {}".format(
|
||||
data["timestamp"][0:10], data["timestamp"][11:19])
|
||||
sender = data["user"]["displayName"]
|
||||
text = data["body"]
|
||||
command_reply = get_command(text)
|
||||
|
||||
logging.info("{} <{}> {}".format(timestamp, sender, text))
|
||||
logging.info("<{}> {}".format(sender, text))
|
||||
|
||||
if command_reply:
|
||||
try:
|
||||
|
|
|
@ -1,11 +1,19 @@
|
|||
from datetime import datetime
|
||||
import random
|
||||
from ameliabot.logger import logging
|
||||
|
||||
|
||||
try:
|
||||
import psycopg2
|
||||
except ModuleNotFoundError:
|
||||
logging.error("Please install psycopg2.")
|
||||
logging.error("Please see README.md for more information.")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
class Quote:
|
||||
def __init__(self, database, user, password):
|
||||
self.conn = psycopg2.connect(database, user, password)
|
||||
self.conn = psycopg2.connect(database=database, user=user, password=password)
|
||||
self.num_quotes = self._get_num_quotes()
|
||||
|
||||
def insert(self, owner, submitter, text):
|
||||
|
|
2
bot.py
2
bot.py
|
@ -1,11 +1,9 @@
|
|||
#!/usr/bin/env python
|
||||
from flask import Flask, Response
|
||||
from ameliabot import owncast
|
||||
from ameliabot.init_logging import init_logging
|
||||
from ameliabot.logger import logging
|
||||
|
||||
|
||||
init_logging()
|
||||
logging.info("Loaded ameliabot v%s" % owncast.bot_version)
|
||||
|
||||
# the url of the Owncast API for bot posts
|
||||
|
|
Loading…
Reference in New Issue