From 0a3b6eae4ca55e24b974b44f2dddee68e03c0345 Mon Sep 17 00:00:00 2001 From: Ash Keel Date: Wed, 23 Nov 2022 22:53:48 +0100 Subject: [PATCH] fix: remove the last remaining ties to Stulbe --- frontend/src/lib/stulbe-lib.ts | 65 ------------------------- frontend/src/locale/en/translation.json | 5 +- frontend/src/store/api/reducer.ts | 9 ---- frontend/src/store/api/types.ts | 8 --- modules/loyalty/data.go | 11 ++--- modules/manager.go | 1 - modules/twitch/modules.alerts.go | 4 +- 7 files changed, 9 insertions(+), 94 deletions(-) delete mode 100644 frontend/src/lib/stulbe-lib.ts diff --git a/frontend/src/lib/stulbe-lib.ts b/frontend/src/lib/stulbe-lib.ts deleted file mode 100644 index fd2652d..0000000 --- a/frontend/src/lib/stulbe-lib.ts +++ /dev/null @@ -1,65 +0,0 @@ -export interface StulbeOptions { - controller: AbortController; -} - -type stulbeAuthResult = - | { - ok: true; - token: string; - } - | { - error: string; - }; - -export default class Stulbe { - private token: string; - - // eslint-disable-next-line no-useless-constructor - constructor( - private readonly endpoint: string, - private readonly options?: StulbeOptions, - ) {} - - public async auth(user: string, key: string): Promise { - const res: stulbeAuthResult = (await ( - await fetch(`${this.endpoint}/api/auth`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - user, - key, - }), - signal: this.options?.controller.signal, - }) - ).json()) as stulbeAuthResult; - if ('error' in res) { - throw new Error(res.error); - } - this.token = res.token; - return res.ok; - } - - public async makeRequest( - method: string, - path: string, - body?: B, - ): Promise { - if (!this.token) { - throw new Error('not authenticated'); - } - const res = (await ( - await fetch(`${this.endpoint}/${path}`, { - method, - headers: { - 'Content-Type': 'application/json', - Authorization: `Bearer ${this.token}`, - }, - body, - signal: this.options?.controller.signal, - }) - ).json()) as T; - return res; - } -} diff --git a/frontend/src/locale/en/translation.json b/frontend/src/locale/en/translation.json index c04d387..0952f86 100644 --- a/frontend/src/locale/en/translation.json +++ b/frontend/src/locale/en/translation.json @@ -11,8 +11,7 @@ "dashboard": "Dashboard" }, "strimertul": { - "settings": "Server settings", - "stulbe": "Back-end integration" + "settings": "Server settings" }, "twitch": { "configuration": "Configuration", @@ -83,7 +82,7 @@ }, "sim-events": "Send test event", "auth-button": "Authenticate with Twitch", - "auth-message": "Click the following button to authenticate the back-end with your Twitch account:", + "auth-message": "Click the following button to authenticate strimertul with your Twitch account:", "current-status": "Current status" } }, diff --git a/frontend/src/store/api/reducer.ts b/frontend/src/store/api/reducer.ts index 368fcd6..665855d 100644 --- a/frontend/src/store/api/reducer.ts +++ b/frontend/src/store/api/reducer.ts @@ -198,14 +198,6 @@ export const modules = { state.twitchBot.alerts = payload; }, ), - stulbeConfig: makeModule( - 'stulbe/config', - (state) => state.moduleConfigs?.stulbeConfig, - (state, { payload }) => { - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - state.moduleConfigs.stulbeConfig = payload; - }, - ), loyaltyConfig: makeModule( 'loyalty/config', (state) => state.moduleConfigs?.loyaltyConfig, @@ -286,7 +278,6 @@ const initialState: APIState = { httpConfig: null, twitchConfig: null, twitchBotConfig: null, - stulbeConfig: null, loyaltyConfig: null, }, requestStatus: {}, diff --git a/frontend/src/store/api/types.ts b/frontend/src/store/api/types.ts index 1e0976d..6628a70 100644 --- a/frontend/src/store/api/types.ts +++ b/frontend/src/store/api/types.ts @@ -43,13 +43,6 @@ export interface TwitchBotCustomCommand { type TwitchBotCustomCommands = Record; -interface StulbeConfig { - enabled: boolean; - endpoint: string; - username: string; - auth_key: string; -} - interface LoyaltyConfig { enabled: boolean; currency: string; @@ -181,7 +174,6 @@ export interface APIState { httpConfig: HTTPConfig; twitchConfig: TwitchConfig; twitchBotConfig: TwitchBotConfig; - stulbeConfig: StulbeConfig; loyaltyConfig: LoyaltyConfig; }; requestStatus: Record; diff --git a/modules/loyalty/data.go b/modules/loyalty/data.go index 6a0bf20..47a6c3a 100644 --- a/modules/loyalty/data.go +++ b/modules/loyalty/data.go @@ -63,9 +63,11 @@ type Redeem struct { RequestText string `json:"request_text"` } -const CreateRedeemRPC = "loyalty/@create-redeem" -const RemoveRedeemRPC = "loyalty/@remove-redeem" -const RedeemEvent = "loyalty/ev/new-redeem" +const ( + CreateRedeemRPC = "loyalty/@create-redeem" + RemoveRedeemRPC = "loyalty/@remove-redeem" + RedeemEvent = "loyalty/ev/new-redeem" +) // Stulbe events @@ -84,6 +86,3 @@ type ExLoyaltyContribute struct { GoalID string `json:"goal_id"` Amount int64 `json:"amount"` } - -const KVExLoyaltyRedeem = "stulbe/loyalty/@redeem-rpc" -const KVExLoyaltyContribute = "stulbe/loyalty/@contribute-rpc" diff --git a/modules/manager.go b/modules/manager.go index 983f00e..0ebe28e 100644 --- a/modules/manager.go +++ b/modules/manager.go @@ -30,7 +30,6 @@ const ( // Feature modules ModuleLoyalty ModuleID = "loyalty" - ModuleStulbe ModuleID = "stulbe" // Streaming providers ModuleTwitch ModuleID = "twitch" diff --git a/modules/twitch/modules.alerts.go b/modules/twitch/modules.alerts.go index 7da0190..a75a7f7 100644 --- a/modules/twitch/modules.alerts.go +++ b/modules/twitch/modules.alerts.go @@ -235,7 +235,7 @@ func SetupAlerts(bot *Bot) *BotAlertsModule { } go bot.api.db.Subscribe(func(key, value string) { - if key == "stulbe/ev/webhook" { + if key == EventSubEventKey { var ev eventSubNotification err := json.UnmarshalFromString(value, &ev) if err != nil { @@ -417,7 +417,7 @@ func SetupAlerts(bot *Bot) *BotAlertsModule { writeTemplate(bot, tpl, &giftEv) } } - }, "stulbe/ev/webhook") + }, EventSubEventKey) bot.logger.Debug("loaded bot alerts")