Owncast support added
This commit is contained in:
+18
-4
@@ -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 <p> 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
|
||||
|
||||
Reference in New Issue
Block a user