From a8dfbb413e040e504401492df6ac8ce9cb7017bf Mon Sep 17 00:00:00 2001 From: rxdn <29165304+rxdn@users.noreply.github.com> Date: Wed, 28 Jul 2021 14:51:37 +0100 Subject: [PATCH] Feedback rating --- app/http/endpoints/api/settings/settings.go | 7 +++++++ .../endpoints/api/settings/updatesettings.go | 8 ++++++- cmd/panel/main.go | 17 +++++++++------ config/config.go | 2 ++ .../src/components/manage/SettingsCard.svelte | 21 ++++++++++--------- frontend/src/js/constants.js | 2 +- go.mod | 2 +- rpc/premiumclient.go | 2 +- 8 files changed, 41 insertions(+), 20 deletions(-) diff --git a/app/http/endpoints/api/settings/settings.go b/app/http/endpoints/api/settings/settings.go index 9f2de6a..299a9b9 100644 --- a/app/http/endpoints/api/settings/settings.go +++ b/app/http/endpoints/api/settings/settings.go @@ -18,6 +18,7 @@ type Settings struct { PingEveryone bool `json:"ping_everyone"` UsersCanClose bool `json:"users_can_close"` CloseConfirmation bool `json:"close_confirmation"` + FeedbackEnabled bool `json:"feedback_enabled"` } func GetSettingsHandler(ctx *gin.Context) { @@ -93,6 +94,12 @@ func GetSettingsHandler(ctx *gin.Context) { return }) + // close confirmation + group.Go(func() (err error) { + settings.FeedbackEnabled, err = dbclient.Client.FeedbackEnabled.Get(guildId) + return + }) + if err := group.Wait(); err != nil { ctx.AbortWithStatusJSON(500, gin.H{ "success": false, diff --git a/app/http/endpoints/api/settings/updatesettings.go b/app/http/endpoints/api/settings/updatesettings.go index c5d0f12..5a76df9 100644 --- a/app/http/endpoints/api/settings/updatesettings.go +++ b/app/http/endpoints/api/settings/updatesettings.go @@ -23,7 +23,7 @@ func UpdateSettingsHandler(ctx *gin.Context) { // Get a list of all channel IDs channels := cache.Instance.GetGuildChannels(guildId) - // Get prefix + // TODO: Errors validPrefix := settings.updatePrefix(guildId) validWelcomeMessage := settings.updateWelcomeMessage(guildId) validTicketLimit := settings.updateTicketLimit(guildId) @@ -33,6 +33,7 @@ func UpdateSettingsHandler(ctx *gin.Context) { settings.updatePingEveryone(guildId) settings.updateUsersCanClose(guildId) settings.updateCloseConfirmation(guildId) + settings.updateFeedbackEnabled(guildId) ctx.JSON(200, gin.H{ "prefix": validPrefix, @@ -135,3 +136,8 @@ func (s *Settings) updateUsersCanClose(guildId uint64) { func (s *Settings) updateCloseConfirmation(guildId uint64) { go dbclient.Client.CloseConfirmation.Set(guildId, s.CloseConfirmation) } + + +func (s *Settings) updateFeedbackEnabled(guildId uint64) { + go dbclient.Client.FeedbackEnabled.Set(guildId, s.FeedbackEnabled) +} diff --git a/cmd/panel/main.go b/cmd/panel/main.go index 1cbe81d..aab5f06 100644 --- a/cmd/panel/main.go +++ b/cmd/panel/main.go @@ -51,12 +51,17 @@ func main() { messagequeue.Client = messagequeue.NewRedisClient() go ListenChat(messagequeue.Client) - rpc.PremiumClient = premium.NewPremiumLookupClient( - premium.NewPatreonClient(config.Conf.Bot.PremiumLookupProxyUrl, config.Conf.Bot.PremiumLookupProxyKey), - messagequeue.Client.Client, - cache.Instance.PgCache, - database.Client, - ) + if !config.Conf.Debug { + rpc.PremiumClient = premium.NewPremiumLookupClient( + premium.NewPatreonClient(config.Conf.Bot.PremiumLookupProxyUrl, config.Conf.Bot.PremiumLookupProxyKey), + messagequeue.Client.Client, + cache.Instance.PgCache, + database.Client, + ) + } else { + c := premium.NewMockLookupClient(premium.Whitelabel, premium.SourcePatreon) + rpc.PremiumClient = &c + } http.StartServer() } diff --git a/config/config.go b/config/config.go index f6f99f5..f70cb70 100644 --- a/config/config.go +++ b/config/config.go @@ -12,6 +12,7 @@ type ( Config struct { Admins []uint64 ForceWhitelabel []uint64 + Debug bool Server Server Oauth Oauth Database Database @@ -122,6 +123,7 @@ func fromEnvvar() { Conf = Config{ Admins: admins, ForceWhitelabel: forcedWhitelabel, + Debug: os.Getenv("DEBUG") != "", Server: Server{ Host: os.Getenv("SERVER_ADDR"), BaseUrl: os.Getenv("BASE_URL"), diff --git a/frontend/src/components/manage/SettingsCard.svelte b/frontend/src/components/manage/SettingsCard.svelte index abc432b..477e8bc 100644 --- a/frontend/src/components/manage/SettingsCard.svelte +++ b/frontend/src/components/manage/SettingsCard.svelte @@ -6,22 +6,24 @@