diff --git a/README.md b/README.md index 8e4657d..1142ac3 100644 --- a/README.md +++ b/README.md @@ -191,7 +191,7 @@ As of now, nothing needs to be done except setting the `yt_backend_enabled` fiel The following procedure needs to be only done once: -1. Go to the admin panel of your Owncast server. Open the "Integrations" - "Access tokens" menu item. +1. Go to the admin panel of your Owncast server. Open the "Integrations" - "Access Tokens" menu item. 2. Create a new access token with the "Can perform administrative actions such as moderation, get server statuses, etc" permission. 3. Copy the token string generated in the admin panel and paste it into the `oc-token.txt` file in the `auth` subdirectory in the application directory. 4. Save the file. The Owncast connection should now work and fetch messages whenever you start a livestream. @@ -265,8 +265,7 @@ Additionally, YouTube does not have its own chat emote API as of now, so the emo ### Owncast (internal) -Work in progress. - +Work in progress. Need additional testing. Basic messages work as expected. ## FAQ diff --git a/config.json b/config.json index ac041fc..a9d9d65 100644 --- a/config.json +++ b/config.json @@ -9,7 +9,7 @@ "yt_api_root_url": "https://yt.lemnoslife.com/noKey", "yt_api_poll_timeout": 3, "yt_channel": "@foxyshadow", - "oc_backend_enabled": false, + "oc_backend_enabled": true, "oc_server": "https://streams.luxferre.top", "oc_api_poll_timeout": 2 } diff --git a/src/owncast.go b/src/owncast.go index c6f8d27..05f2aa9 100644 --- a/src/owncast.go +++ b/src/owncast.go @@ -60,15 +60,22 @@ func oc_api_get(endpoint string) []interface{} { return respbody } +/* + +[{"timestamp":"2024-09-15T06:37:36.022049086Z","type":"CHAT","id":"PrBY39eSg","user":{"createdAt":"2024-09-14T11:51:52.135597747Z","id":"SmcN3l6Ig","displayName":"inspiring-joliot","previousNames":["inspiring-joliot"],"scopes":[""],"displayColor":0,"isBot":false,"authenticated":false},"body":"\u003cp\u003etest\u003c/p\u003e"}, +{"timestamp":"2024-09-15T06:38:20.410448447Z","type":"CHAT","id":"lIgyqr6Sg","user":{"createdAt":"2024-09-14T11:51:52.135597747Z","id":"SmcN3l6Ig","displayName":"inspiring-joliot","previousNames":["inspiring-joliot"],"scopes":[""],"displayColor":0,"isBot":false,"authenticated":false},"body":"\u003cp\u003exlol\u003c/p\u003e"}] + +*/ + /* main message procesing function */ func oc_process_message(rawmsg map[string]interface{}) { /* if the message came from a real user, this is the one we should process */ - if rawmsg["type"] == "UserMessage" { + if rawmsg["type"] == "CHAT" { if !slices.Contains(oc_msg_id_cache, rawmsg["id"].(string)) { /* we have a fresh message here */ author := rawmsg["user"].(map[string]interface{}) - /* convert the timestamp - TODO determine the correct format */ - sent_dt, _ := time.Parse("2006-01-02T15:04:05.000000-07:00", rawmsg["timestamp"].(string)) + /* convert the timestamp */ + sent_dt, _ := time.Parse("2006-01-02T15:04:05.000000000Z", rawmsg["timestamp"].(string)) /* prepare output message */ out_message := ChatMessage { @@ -79,6 +86,10 @@ func oc_process_message(rawmsg map[string]interface{}) { Icon: "", } + /* remove starting and ending

tag from the message */ + out_message.Text = strings.ReplaceAll(out_message.Text, "\u003cp\u003e", "") + out_message.Text = strings.ReplaceAll(out_message.Text, "\u003c/p\u003e", "") + /* check for authenticated role */ if _, ok := author["authenticated"]; ok && author["authenticated"].(bool) == true { out_message.Type += "-authenticated" @@ -90,7 +101,10 @@ func oc_process_message(rawmsg map[string]interface{}) { } /* add display color hint */ - out_message.Type += fmt.Sprintf("-occolor%d", int(author["displayColor"].(float64))) + dcolor := int(author["displayColor"].(float64)) + if dcolor > 0 { + out_message.Type += fmt.Sprintf("-occolor%d", dcolor) + } /* finally, send it to the message broker via the message_transport channel */ message_transport <- out_message diff --git a/webroot/style.css b/webroot/style.css index 15b2973..bbb8874 100644 --- a/webroot/style.css +++ b/webroot/style.css @@ -89,6 +89,8 @@ html, body { width: 16px; background-size: 16px; background-repeat no-repeat; + position: relative; + top: 2px; } .timestamp {