1
0
Fork 0
mirror of https://git.sr.ht/~ashkeel/strimertul synced 2024-09-18 01:50:50 +00:00

fix: remove the last remaining ties to Stulbe

This commit is contained in:
Ash Keel 2022-11-23 22:53:48 +01:00
parent eb70306c0a
commit 0a3b6eae4c
No known key found for this signature in database
GPG key ID: BAD8D93E7314ED3E
7 changed files with 9 additions and 94 deletions

View file

@ -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<boolean> {
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<T, B extends BodyInit | URLSearchParams>(
method: string,
path: string,
body?: B,
): Promise<T> {
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;
}
}

View file

@ -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"
}
},

View file

@ -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: {},

View file

@ -43,13 +43,6 @@ export interface TwitchBotCustomCommand {
type TwitchBotCustomCommands = Record<string, TwitchBotCustomCommand>;
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<string, RequestStatus>;

View file

@ -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"

View file

@ -30,7 +30,6 @@ const (
// Feature modules
ModuleLoyalty ModuleID = "loyalty"
ModuleStulbe ModuleID = "stulbe"
// Streaming providers
ModuleTwitch ModuleID = "twitch"

View file

@ -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")