import React, { useEffect, useState } from "react"; import { LevelEntry, Levels } from "./Levels"; import { LogChannel, LogChannels } from "./LogChannels"; import yaml from "js-yaml"; import "./Configurator.css"; export function Configurator() { const [prefix, setPrefix] = useState('!'); const [levels, setLevels] = useState([]); const [withModCommands, setWithModCommands] = useState(false); const [muteRoleId, setMuteRoleId] = useState(""); const [caseChannelId, setCaseChannelId] = useState(""); const [dmModActionReasons, setDmModActionReasons] = useState(false); const [withLogs, setWithLogs] = useState(false); const [logChannels, setLogChannels] = useState([]); const [result, setResult] = useState({}); useEffect(() => { const resultObj: any = { prefix, levels: levels.reduce((obj, entry) => { obj[entry[0]] = entry[1]; return obj; }, {}), plugins: { utility: {}, }, }; if (withModCommands) { resultObj.plugins.cases = { config: { case_log_channel: caseChannelId, }, }; resultObj.plugins.mod_actions = {}; if (muteRoleId) { resultObj.plugins.mutes = { config: { mute_role: muteRoleId, } }; if (dmModActionReasons) { resultObj.plugins.mutes.config.dm_on_mute = true; } } if (dmModActionReasons) { resultObj.plugins.mod_actions = { config: { dm_on_warn: true, dm_on_kick: true, dm_on_ban: true, }, }; } } if (withLogs) { resultObj.plugins.logs = { config: { channels: logChannels.reduce((obj, logChannel) => { if (logChannel.includeExclude === "include") { obj[logChannel.id] = { include: Array.from(logChannel.logTypes.values()), }; } else { obj[logChannel.id] = { exclude: Array.from(logChannel.logTypes.values()), }; } return obj; }, {}), }, }; } setResult(resultObj); }, [prefix, levels, withModCommands, muteRoleId, caseChannelId, dmModActionReasons, withLogs, logChannels]); const [formattedResult, setFormattedResult] = useState(""); useEffect(() => { setFormattedResult(yaml.dump(result)); }, [result]); return (
{/* Options */}

Prefix

Levels

Mod commands

{withModCommands && (
)}

Logs

{withLogs && ( )}
{/* Result */}
{formattedResult}
); }