kopia lustrzana https://codeberg.org/nmkj/audon
remove avatar restore
rodzic
6f7b58f2e2
commit
85979a7ebf
4
go.mod
4
go.mod
|
@ -3,10 +3,12 @@ module audon
|
||||||
go 1.19
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/gabriel-vasile/mimetype v1.4.1
|
||||||
github.com/go-playground/validator/v10 v10.11.1
|
github.com/go-playground/validator/v10 v10.11.1
|
||||||
github.com/go-redis/redis/v9 v9.0.0-rc.2
|
github.com/go-redis/redis/v9 v9.0.0-rc.2
|
||||||
github.com/gorilla/sessions v1.2.1
|
github.com/gorilla/sessions v1.2.1
|
||||||
github.com/jaevor/go-nanoid v1.3.0
|
github.com/jaevor/go-nanoid v1.3.0
|
||||||
|
github.com/jellydator/ttlcache/v3 v3.0.1
|
||||||
github.com/joho/godotenv v1.4.0
|
github.com/joho/godotenv v1.4.0
|
||||||
github.com/labstack/echo-contrib v0.13.0
|
github.com/labstack/echo-contrib v0.13.0
|
||||||
github.com/labstack/echo/v4 v4.9.1
|
github.com/labstack/echo/v4 v4.9.1
|
||||||
|
@ -33,7 +35,6 @@ require (
|
||||||
github.com/eapache/channels v1.1.0 // indirect
|
github.com/eapache/channels v1.1.0 // indirect
|
||||||
github.com/eapache/queue v1.1.0 // indirect
|
github.com/eapache/queue v1.1.0 // indirect
|
||||||
github.com/frostbyte73/go-throttle v0.0.0-20210621200530-8018c891361d // indirect
|
github.com/frostbyte73/go-throttle v0.0.0-20210621200530-8018c891361d // indirect
|
||||||
github.com/gabriel-vasile/mimetype v1.4.1 // indirect
|
|
||||||
github.com/go-logr/logr v1.2.3 // indirect
|
github.com/go-logr/logr v1.2.3 // indirect
|
||||||
github.com/go-logr/stdr v1.2.2 // indirect
|
github.com/go-logr/stdr v1.2.2 // indirect
|
||||||
github.com/go-logr/zapr v1.2.3 // indirect
|
github.com/go-logr/zapr v1.2.3 // indirect
|
||||||
|
@ -47,7 +48,6 @@ require (
|
||||||
github.com/gorilla/context v1.1.1 // indirect
|
github.com/gorilla/context v1.1.1 // indirect
|
||||||
github.com/gorilla/securecookie v1.1.1 // indirect
|
github.com/gorilla/securecookie v1.1.1 // indirect
|
||||||
github.com/gorilla/websocket v1.5.0 // indirect
|
github.com/gorilla/websocket v1.5.0 // indirect
|
||||||
github.com/jellydator/ttlcache/v3 v3.0.1 // indirect
|
|
||||||
github.com/jxskiss/base62 v1.1.0 // indirect
|
github.com/jxskiss/base62 v1.1.0 // indirect
|
||||||
github.com/klauspost/compress v1.13.6 // indirect
|
github.com/klauspost/compress v1.13.6 // indirect
|
||||||
github.com/labstack/gommon v0.4.0 // indirect
|
github.com/labstack/gommon v0.4.0 // indirect
|
||||||
|
|
54
webhooks.go
54
webhooks.go
|
@ -1,19 +1,18 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/jellydator/ttlcache/v3"
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/livekit/protocol/auth"
|
"github.com/livekit/protocol/auth"
|
||||||
"github.com/livekit/protocol/webhook"
|
"github.com/livekit/protocol/webhook"
|
||||||
mastodon "github.com/mattn/go-mastodon"
|
mastodon "github.com/mattn/go-mastodon"
|
||||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func livekitWebhookHandler(c echo.Context) error {
|
func livekitWebhookHandler(c echo.Context) error {
|
||||||
|
@ -38,7 +37,6 @@ func livekitWebhookHandler(c echo.Context) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if event.GetEvent() == webhook.EventParticipantLeft {
|
} else if event.GetEvent() == webhook.EventParticipantLeft {
|
||||||
// Revert user's avatar
|
|
||||||
audonID := event.GetParticipant().GetIdentity()
|
audonID := event.GetParticipant().GetIdentity()
|
||||||
user, err := findUserByID(c.Request().Context(), audonID)
|
user, err := findUserByID(c.Request().Context(), audonID)
|
||||||
if user == nil || err != nil {
|
if user == nil || err != nil {
|
||||||
|
@ -51,51 +49,13 @@ func livekitWebhookHandler(c echo.Context) error {
|
||||||
if data == nil {
|
if data == nil {
|
||||||
return echo.NewHTTPError(http.StatusGone)
|
return echo.NewHTTPError(http.StatusGone)
|
||||||
}
|
}
|
||||||
mastoClient := getMastodonClient(data.Value())
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
if mastoClient == nil {
|
defer cancel()
|
||||||
c.Logger().Errorf("unable to get mastodon client: %v", data.Value().MastodonConfig)
|
nextUser, err := findUserByID(ctx, audonID)
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError)
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
}
|
}
|
||||||
cached := webhookTimerCache.Get(audonID)
|
nextUser.ClearUserAvatar(ctx)
|
||||||
if cached != nil {
|
|
||||||
oldTimer := cached.Value()
|
|
||||||
if !oldTimer.Stop() {
|
|
||||||
<-oldTimer.C
|
|
||||||
}
|
|
||||||
}
|
|
||||||
countdown := time.NewTimer(60 * time.Second)
|
|
||||||
webhookTimerCache.Set(audonID, countdown, ttlcache.DefaultTTL)
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
<-countdown.C
|
|
||||||
webhookTimerCache.Delete(audonID)
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
stillAgain, err := user.InLivekit(ctx)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
}
|
|
||||||
if stillAgain {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
nextUser, err := findUserByID(ctx, audonID)
|
|
||||||
if err == nil && nextUser.AvatarFile != "" {
|
|
||||||
log.Printf("Recovering avatar: %s --> (%s) %s\n", nextUser.AvatarFile, audonID, nextUser.Webfinger)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
avatar := nextUser.getAvatarImagePath(nextUser.AvatarFile)
|
|
||||||
_, err = updateAvatar(ctx, mastoClient, avatar)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
}
|
|
||||||
nextUser.ClearUserAvatar(ctx)
|
|
||||||
} else if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
} else if event.GetEvent() == webhook.EventRoomStarted {
|
} else if event.GetEvent() == webhook.EventRoomStarted {
|
||||||
// Have the bot advertise the room
|
// Have the bot advertise the room
|
||||||
|
|
Ładowanie…
Reference in New Issue