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 httpConfigKey = 'http/config';
|
||||||
const twitchConfigKey = 'twitch/config';
|
const twitchConfigKey = 'twitch/config';
|
||||||
const twitchBotConfigKey = 'twitch/bot-config';
|
const twitchBotConfigKey = 'twitch/bot-config';
|
||||||
|
const twitchBotCommandsKey = 'twitch/bot-custom-commands';
|
||||||
const stulbeConfigKey = 'stulbe/config';
|
const stulbeConfigKey = 'stulbe/config';
|
||||||
const loyaltyConfigKey = 'loyalty/config';
|
const loyaltyConfigKey = 'loyalty/config';
|
||||||
const loyaltyPointsPrefix = 'loyalty/points/';
|
const loyaltyPointsPrefix = 'loyalty/points/';
|
||||||
|
@ -54,6 +55,17 @@ interface TwitchBotConfig {
|
||||||
chat_history: number;
|
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 {
|
interface StulbeConfig {
|
||||||
endpoint: string;
|
endpoint: string;
|
||||||
username: string;
|
username: string;
|
||||||
|
@ -116,6 +128,9 @@ export interface APIState {
|
||||||
goals: LoyaltyGoal[];
|
goals: LoyaltyGoal[];
|
||||||
redeemQueue: LoyaltyRedeem[];
|
redeemQueue: LoyaltyRedeem[];
|
||||||
};
|
};
|
||||||
|
twitchBot: {
|
||||||
|
commands: TwitchBotCustomCommands;
|
||||||
|
};
|
||||||
moduleConfigs: {
|
moduleConfigs: {
|
||||||
moduleConfig: ModuleConfig;
|
moduleConfig: ModuleConfig;
|
||||||
httpConfig: HTTPConfig;
|
httpConfig: HTTPConfig;
|
||||||
|
@ -136,6 +151,9 @@ const initialState: APIState = {
|
||||||
goals: null,
|
goals: null,
|
||||||
redeemQueue: null,
|
redeemQueue: null,
|
||||||
},
|
},
|
||||||
|
twitchBot: {
|
||||||
|
commands: null,
|
||||||
|
},
|
||||||
moduleConfigs: {
|
moduleConfigs: {
|
||||||
moduleConfig: null,
|
moduleConfig: null,
|
||||||
httpConfig: null,
|
httpConfig: null,
|
||||||
|
@ -268,6 +286,13 @@ export const modules = {
|
||||||
state.moduleConfigs.twitchBotConfig = payload;
|
state.moduleConfigs.twitchBotConfig = payload;
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
twitchBotCommands: makeModule<TwitchBotCustomCommands>(
|
||||||
|
twitchBotCommandsKey,
|
||||||
|
(state) => state.twitchBot?.commands,
|
||||||
|
(state, { payload }) => {
|
||||||
|
state.twitchBot.commands = payload;
|
||||||
|
},
|
||||||
|
),
|
||||||
stulbeConfig: makeModule<StulbeConfig>(
|
stulbeConfig: makeModule<StulbeConfig>(
|
||||||
stulbeConfigKey,
|
stulbeConfigKey,
|
||||||
(state) => state.moduleConfigs?.stulbeConfig,
|
(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({
|
const apiReducer = createSlice({
|
||||||
name: 'api',
|
name: 'api',
|
||||||
initialState,
|
initialState,
|
||||||
reducers: {
|
reducers: {
|
||||||
|
...moduleChangeReducers,
|
||||||
initialLoadCompleted(state) {
|
initialLoadCompleted(state) {
|
||||||
state.initialLoadComplete = true;
|
state.initialLoadComplete = true;
|
||||||
},
|
},
|
||||||
connectionStatusChanged(state, { payload }: PayloadAction<boolean>) {
|
connectionStatusChanged(state, { payload }: PayloadAction<boolean>) {
|
||||||
state.connected = payload;
|
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(
|
loyaltyUserPointsChanged(
|
||||||
state,
|
state,
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue