Skip to content

Commit

Permalink
Merge pull request #208 from tosuapp/fix/settings
Browse files Browse the repository at this point in the history
fix: Patrially update settings for type commands
  • Loading branch information
cyperdark authored Oct 18, 2024
2 parents 406301b + 42fefbb commit e704572
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
22 changes: 17 additions & 5 deletions packages/server/assets/homepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,21 +631,33 @@ const showSettings = {
for (let i = 0; i < props.settings.length; i++) {
const setting = props.settings[i];
let value = props.values[setting.uniqueID] ?? setting.value;


if (setting.type == "commands") {
setting.options.forEach(r => {
if (r.values) r.values = r.values.filter(r => r !== '' && r != null);
});


setting.value.forEach((command, cmd_ind) => {
Object.entries(command).forEach(entry => {
const custom_value = value[cmd_ind][entry[0]];
if (custom_value == null) return;
if (entry[1] == custom_value) return;


setting.value[cmd_ind][entry[0]] = custom_value;
});
});


if (!Array.isArray(value)) value = [];
value.push({});
};


if (props.values[setting.uniqueID]) {
value = props.values[setting.uniqueID];
}

setting.value = value;
if (setting.type != "commands")
setting.value = value;
settings.value.push(setting);
};

Expand Down
2 changes: 1 addition & 1 deletion packages/server/utils/parseSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function parseCounterSettings(
if (!fs.existsSync(settingsPath))
fs.writeFileSync(settingsPath, JSON.stringify([]), 'utf8');

if (!fs.existsSync(settingsValuesPath))
if (fs.existsSync(settingsPath) && !fs.existsSync(settingsValuesPath))
fs.writeFileSync(settingsValuesPath, JSON.stringify({}), 'utf8');

const settings: ISettings[] = JsonSafeParse(
Expand Down

0 comments on commit e704572

Please sign in to comment.