Add settings command
This commit is contained in:
parent
798f9f25e0
commit
936393feb0
|
@ -18,7 +18,7 @@ const enterEvent = new KeyboardEvent("keydown", {
|
|||
export default {
|
||||
id: "customcss",
|
||||
name: "customcss",
|
||||
description: `Toggle or view your CustomCSS`,
|
||||
description: `Toggle, open, or share your CustomCSS`,
|
||||
options: [
|
||||
{
|
||||
type: OptionTypes.STRING,
|
||||
|
@ -36,24 +36,24 @@ export default {
|
|||
],
|
||||
execute: async (data, {channel}) => {
|
||||
const action = data.find(o => o.name === "action").value;
|
||||
const isEnabled = Settings.get("settings", "customcss", "customcss");
|
||||
const isEnabled = Settings.get("customcss", "customcss");
|
||||
|
||||
if (action === "toggle") {
|
||||
Settings.set("settings", "customcss", "customcss", !isEnabled);
|
||||
Settings.set("customcss", "customcss", !isEnabled);
|
||||
return {content: `CustomCSS has been toggled!`};
|
||||
}
|
||||
|
||||
if (action === "enable") {
|
||||
if (isEnabled) return {content: `CustomCSS is already enabled!`};
|
||||
|
||||
Settings.set("settings", "customcss", "customcss", true);
|
||||
Settings.set("customcss", "customcss", true);
|
||||
return {content: `CustomCSS has been enabled!`};
|
||||
}
|
||||
|
||||
if (action === "disable") {
|
||||
if (!isEnabled) return {content: `CustomCSS is already disabled!`};
|
||||
|
||||
Settings.set("settings", "customcss", "customcss", false);
|
||||
Settings.set("customcss", "customcss", false);
|
||||
return {content: `CustomCSS has been disabled!`};
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import DebugCommand from "./debug";
|
|||
import RestartCommand from "./restart";
|
||||
import SupportCommand from "./support";
|
||||
import CustomCSSCommand from "./customcss";
|
||||
import SettingsCommand from "./settings";
|
||||
|
||||
|
||||
export default new class DefaultCommands extends Builtin {
|
||||
|
@ -18,7 +19,8 @@ export default new class DefaultCommands extends Builtin {
|
|||
DebugCommand,
|
||||
RestartCommand,
|
||||
SupportCommand,
|
||||
CustomCSSCommand
|
||||
CustomCSSCommand,
|
||||
SettingsCommand
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
import {OptionTypes} from "@modules/commandmanager";
|
||||
import Settings from "@modules/settingsmanager";
|
||||
|
||||
|
||||
export default {
|
||||
id: "settings",
|
||||
name: "settings",
|
||||
description: `Toggle or open your settings`,
|
||||
options: [
|
||||
{
|
||||
type: OptionTypes.STRING,
|
||||
name: "action",
|
||||
description: "Action to take",
|
||||
required: true,
|
||||
choices: [
|
||||
{name: "Toggle", value: "toggle"},
|
||||
{name: "Enable", value: "enable"},
|
||||
{name: "Disable", value: "disable"}
|
||||
]
|
||||
},
|
||||
{
|
||||
type: OptionTypes.STRING,
|
||||
name: "setting",
|
||||
description: `Which setting to modify?`,
|
||||
required: true,
|
||||
get choices() {
|
||||
return Settings.collections[0].settings.map(c => {
|
||||
const switches = c.settings.filter(s => s.type === "switch");
|
||||
return switches.map(s => ({name: s.name, value: `${c.id}-${s.id}-${s.name}`}));
|
||||
}).flat();
|
||||
}
|
||||
}
|
||||
],
|
||||
execute: async (data) => {
|
||||
const action = data.find(o => o.name === "action").value;
|
||||
const settingData = data.find(o => o.name === "setting").value.split("-");
|
||||
const catId = settingData[0];
|
||||
const id = settingData[1];
|
||||
const name = settingData[2];
|
||||
const isEnabled = Settings.get(catId, id);
|
||||
|
||||
if (action === "toggle") {
|
||||
Settings.set(catId, id, !isEnabled);
|
||||
return {content: `${name} has been toggled!`};
|
||||
}
|
||||
|
||||
if (action === "enable") {
|
||||
if (isEnabled) return {content: `${name} is already enabled!`};
|
||||
|
||||
Settings.set(catId, id, true);
|
||||
return {content: `${name} has been enabled!`};
|
||||
}
|
||||
|
||||
if (action === "disable") {
|
||||
if (!isEnabled) return {content: `${name} is already disabled!`};
|
||||
|
||||
Settings.set(catId, id, false);
|
||||
return {content: `${name} has been disabled!`};
|
||||
}
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue