mirror of
https://git.sr.ht/~ashkeel/strimertul
synced 2024-09-20 02:00:49 +00:00
Add custom command module and huge refactor of reducers
This commit is contained in:
parent
7c5d3f449d
commit
81a2cd816e
1 changed files with 42 additions and 24 deletions
|
@ -15,6 +15,7 @@ const moduleConfigKey = 'stul-meta/modules';
|
|||
const httpConfigKey = 'http/config';
|
||||
const twitchConfigKey = 'twitch/config';
|
||||
const twitchBotConfigKey = 'twitch/bot-config';
|
||||
const twitchBotCommandsKey = 'twitch/bot-custom-commands';
|
||||
const stulbeConfigKey = 'stulbe/config';
|
||||
const loyaltyConfigKey = 'loyalty/config';
|
||||
const loyaltyPointsPrefix = 'loyalty/points/';
|
||||
|
@ -54,6 +55,17 @@ interface TwitchBotConfig {
|
|||
chat_history: number;
|
||||
}
|
||||
|
||||
type AccessLevelType = 'everyone' | 'vip' | 'moderators' | 'streamer';
|
||||
|
||||
interface TwitchBotCustomCommand {
|
||||
description: string;
|
||||
access_level: AccessLevelType;
|
||||
response: string;
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
type TwitchBotCustomCommands = Record<string, TwitchBotCustomCommand>;
|
||||
|
||||
interface StulbeConfig {
|
||||
endpoint: string;
|
||||
username: string;
|
||||
|
@ -116,6 +128,9 @@ export interface APIState {
|
|||
goals: LoyaltyGoal[];
|
||||
redeemQueue: LoyaltyRedeem[];
|
||||
};
|
||||
twitchBot: {
|
||||
commands: TwitchBotCustomCommands;
|
||||
};
|
||||
moduleConfigs: {
|
||||
moduleConfig: ModuleConfig;
|
||||
httpConfig: HTTPConfig;
|
||||
|
@ -136,6 +151,9 @@ const initialState: APIState = {
|
|||
goals: null,
|
||||
redeemQueue: null,
|
||||
},
|
||||
twitchBot: {
|
||||
commands: null,
|
||||
},
|
||||
moduleConfigs: {
|
||||
moduleConfig: null,
|
||||
httpConfig: null,
|
||||
|
@ -268,6 +286,13 @@ export const modules = {
|
|||
state.moduleConfigs.twitchBotConfig = payload;
|
||||
},
|
||||
),
|
||||
twitchBotCommands: makeModule<TwitchBotCustomCommands>(
|
||||
twitchBotCommandsKey,
|
||||
(state) => state.twitchBot?.commands,
|
||||
(state, { payload }) => {
|
||||
state.twitchBot.commands = payload;
|
||||
},
|
||||
),
|
||||
stulbeConfig: makeModule<StulbeConfig>(
|
||||
stulbeConfigKey,
|
||||
(state) => state.moduleConfigs?.stulbeConfig,
|
||||
|
@ -321,40 +346,33 @@ export const removeRedeem = createAsyncThunk(
|
|||
},
|
||||
);
|
||||
|
||||
const moduleChangeReducers = Object.fromEntries(
|
||||
Object.entries(modules).map(([key, mod]) => [
|
||||
`${key}Changed`,
|
||||
mod.stateSetter,
|
||||
]),
|
||||
) as Record<
|
||||
`${keyof typeof modules}Changed`,
|
||||
(
|
||||
state: unknown,
|
||||
action: {
|
||||
payload: unknown;
|
||||
type: string;
|
||||
},
|
||||
) => never
|
||||
>;
|
||||
|
||||
const apiReducer = createSlice({
|
||||
name: 'api',
|
||||
initialState,
|
||||
reducers: {
|
||||
...moduleChangeReducers,
|
||||
initialLoadCompleted(state) {
|
||||
state.initialLoadComplete = true;
|
||||
},
|
||||
connectionStatusChanged(state, { payload }: PayloadAction<boolean>) {
|
||||
state.connected = payload;
|
||||
},
|
||||
moduleConfigChanged(state, { payload }: PayloadAction<ModuleConfig>) {
|
||||
state.moduleConfigs.moduleConfig = payload;
|
||||
},
|
||||
httpConfigChanged(state, { payload }: PayloadAction<HTTPConfig>) {
|
||||
state.moduleConfigs.httpConfig = payload;
|
||||
},
|
||||
twitchConfigChanged(state, { payload }: PayloadAction<TwitchConfig>) {
|
||||
state.moduleConfigs.twitchConfig = payload;
|
||||
},
|
||||
twitchBotConfigChanged(state, { payload }: PayloadAction<TwitchBotConfig>) {
|
||||
state.moduleConfigs.twitchBotConfig = payload;
|
||||
},
|
||||
stulbeConfigChanged(state, { payload }: PayloadAction<StulbeConfig>) {
|
||||
state.moduleConfigs.stulbeConfig = payload;
|
||||
},
|
||||
loyaltyConfigChanged(state, { payload }: PayloadAction<LoyaltyConfig>) {
|
||||
state.moduleConfigs.loyaltyConfig = payload;
|
||||
},
|
||||
loyaltyRewardsChanged(state, { payload }: PayloadAction<LoyaltyReward[]>) {
|
||||
state.loyalty.rewards = payload;
|
||||
},
|
||||
loyaltyGoalsChanged(state, { payload }: PayloadAction<LoyaltyGoal[]>) {
|
||||
state.loyalty.goals = payload;
|
||||
},
|
||||
loyaltyUserPointsChanged(
|
||||
state,
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue