mirror of
https://git.sr.ht/~ashkeel/strimertul
synced 2024-09-20 02:00:49 +00:00
fix: remove the last remaining ties to Stulbe
This commit is contained in:
parent
eb70306c0a
commit
0a3b6eae4c
7 changed files with 9 additions and 94 deletions
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -11,8 +11,7 @@
|
||||||
"dashboard": "Dashboard"
|
"dashboard": "Dashboard"
|
||||||
},
|
},
|
||||||
"strimertul": {
|
"strimertul": {
|
||||||
"settings": "Server settings",
|
"settings": "Server settings"
|
||||||
"stulbe": "Back-end integration"
|
|
||||||
},
|
},
|
||||||
"twitch": {
|
"twitch": {
|
||||||
"configuration": "Configuration",
|
"configuration": "Configuration",
|
||||||
|
@ -83,7 +82,7 @@
|
||||||
},
|
},
|
||||||
"sim-events": "Send test event",
|
"sim-events": "Send test event",
|
||||||
"auth-button": "Authenticate with Twitch",
|
"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"
|
"current-status": "Current status"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -198,14 +198,6 @@ export const modules = {
|
||||||
state.twitchBot.alerts = payload;
|
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(
|
loyaltyConfig: makeModule(
|
||||||
'loyalty/config',
|
'loyalty/config',
|
||||||
(state) => state.moduleConfigs?.loyaltyConfig,
|
(state) => state.moduleConfigs?.loyaltyConfig,
|
||||||
|
@ -286,7 +278,6 @@ const initialState: APIState = {
|
||||||
httpConfig: null,
|
httpConfig: null,
|
||||||
twitchConfig: null,
|
twitchConfig: null,
|
||||||
twitchBotConfig: null,
|
twitchBotConfig: null,
|
||||||
stulbeConfig: null,
|
|
||||||
loyaltyConfig: null,
|
loyaltyConfig: null,
|
||||||
},
|
},
|
||||||
requestStatus: {},
|
requestStatus: {},
|
||||||
|
|
|
@ -43,13 +43,6 @@ export interface TwitchBotCustomCommand {
|
||||||
|
|
||||||
type TwitchBotCustomCommands = Record<string, TwitchBotCustomCommand>;
|
type TwitchBotCustomCommands = Record<string, TwitchBotCustomCommand>;
|
||||||
|
|
||||||
interface StulbeConfig {
|
|
||||||
enabled: boolean;
|
|
||||||
endpoint: string;
|
|
||||||
username: string;
|
|
||||||
auth_key: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface LoyaltyConfig {
|
interface LoyaltyConfig {
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
currency: string;
|
currency: string;
|
||||||
|
@ -181,7 +174,6 @@ export interface APIState {
|
||||||
httpConfig: HTTPConfig;
|
httpConfig: HTTPConfig;
|
||||||
twitchConfig: TwitchConfig;
|
twitchConfig: TwitchConfig;
|
||||||
twitchBotConfig: TwitchBotConfig;
|
twitchBotConfig: TwitchBotConfig;
|
||||||
stulbeConfig: StulbeConfig;
|
|
||||||
loyaltyConfig: LoyaltyConfig;
|
loyaltyConfig: LoyaltyConfig;
|
||||||
};
|
};
|
||||||
requestStatus: Record<string, RequestStatus>;
|
requestStatus: Record<string, RequestStatus>;
|
||||||
|
|
|
@ -63,9 +63,11 @@ type Redeem struct {
|
||||||
RequestText string `json:"request_text"`
|
RequestText string `json:"request_text"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreateRedeemRPC = "loyalty/@create-redeem"
|
const (
|
||||||
const RemoveRedeemRPC = "loyalty/@remove-redeem"
|
CreateRedeemRPC = "loyalty/@create-redeem"
|
||||||
const RedeemEvent = "loyalty/ev/new-redeem"
|
RemoveRedeemRPC = "loyalty/@remove-redeem"
|
||||||
|
RedeemEvent = "loyalty/ev/new-redeem"
|
||||||
|
)
|
||||||
|
|
||||||
// Stulbe events
|
// Stulbe events
|
||||||
|
|
||||||
|
@ -84,6 +86,3 @@ type ExLoyaltyContribute struct {
|
||||||
GoalID string `json:"goal_id"`
|
GoalID string `json:"goal_id"`
|
||||||
Amount int64 `json:"amount"`
|
Amount int64 `json:"amount"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const KVExLoyaltyRedeem = "stulbe/loyalty/@redeem-rpc"
|
|
||||||
const KVExLoyaltyContribute = "stulbe/loyalty/@contribute-rpc"
|
|
||||||
|
|
|
@ -30,7 +30,6 @@ const (
|
||||||
|
|
||||||
// Feature modules
|
// Feature modules
|
||||||
ModuleLoyalty ModuleID = "loyalty"
|
ModuleLoyalty ModuleID = "loyalty"
|
||||||
ModuleStulbe ModuleID = "stulbe"
|
|
||||||
|
|
||||||
// Streaming providers
|
// Streaming providers
|
||||||
ModuleTwitch ModuleID = "twitch"
|
ModuleTwitch ModuleID = "twitch"
|
||||||
|
|
|
@ -235,7 +235,7 @@ func SetupAlerts(bot *Bot) *BotAlertsModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
go bot.api.db.Subscribe(func(key, value string) {
|
go bot.api.db.Subscribe(func(key, value string) {
|
||||||
if key == "stulbe/ev/webhook" {
|
if key == EventSubEventKey {
|
||||||
var ev eventSubNotification
|
var ev eventSubNotification
|
||||||
err := json.UnmarshalFromString(value, &ev)
|
err := json.UnmarshalFromString(value, &ev)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -417,7 +417,7 @@ func SetupAlerts(bot *Bot) *BotAlertsModule {
|
||||||
writeTemplate(bot, tpl, &giftEv)
|
writeTemplate(bot, tpl, &giftEv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, "stulbe/ev/webhook")
|
}, EventSubEventKey)
|
||||||
|
|
||||||
bot.logger.Debug("loaded bot alerts")
|
bot.logger.Debug("loaded bot alerts")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue