3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-18 23:09:59 +00:00
zeppelin/presetup-configurator/src/LogChannels.tsx

192 lines
6.2 KiB
TypeScript
Raw Normal View History

Update djs & knub (#395) * update pkgs Signed-off-by: GitHub <noreply@github.com> * new knub typings Signed-off-by: GitHub <noreply@github.com> * more pkg updates Signed-off-by: GitHub <noreply@github.com> * more fixes Signed-off-by: GitHub <noreply@github.com> * channel typings Signed-off-by: GitHub <noreply@github.com> * more message utils typings fixes Signed-off-by: GitHub <noreply@github.com> * migrate permissions Signed-off-by: GitHub <noreply@github.com> * fix: InternalPoster webhookables Signed-off-by: GitHub <noreply@github.com> * djs typings: Attachment & Util Signed-off-by: GitHub <noreply@github.com> * more typings Signed-off-by: GitHub <noreply@github.com> * fix: rename permissionNames Signed-off-by: GitHub <noreply@github.com> * more fixes Signed-off-by: GitHub <noreply@github.com> * half the number of errors * knub commands => messageCommands Signed-off-by: GitHub <noreply@github.com> * configPreprocessor => configParser Signed-off-by: GitHub <noreply@github.com> * fix channel.messages Signed-off-by: GitHub <noreply@github.com> * revert automod any typing Signed-off-by: GitHub <noreply@github.com> * more configParser typings Signed-off-by: GitHub <noreply@github.com> * revert Signed-off-by: GitHub <noreply@github.com> * remove knub type params Signed-off-by: GitHub <noreply@github.com> * fix more MessageEmbed / MessageOptions Signed-off-by: GitHub <noreply@github.com> * dumb commit for @almeidx to see why this is stupid Signed-off-by: GitHub <noreply@github.com> * temp disable custom_events Signed-off-by: GitHub <noreply@github.com> * more minor typings fixes - 23 err left Signed-off-by: GitHub <noreply@github.com> * update djs dep * +debug build method (revert this) Signed-off-by: GitHub <noreply@github.com> * Revert "+debug build method (revert this)" This reverts commit a80af1e729b742d1aad1097df538d224fbd32ce7. * Redo +debug build (Revert this) Signed-off-by: GitHub <noreply@github.com> * uniform before/after Load shorthands Signed-off-by: GitHub <noreply@github.com> * remove unused imports & add prettier plugin Signed-off-by: GitHub <noreply@github.com> * env fixes for web platform hosting Signed-off-by: GitHub <noreply@github.com> * feat: knub v32-next; related fixes * fix: allow legacy keys in change_perms action * fix: request Message Content intent * fix: use Knub's config validation logic in API * fix(dashboard): fix error when there are no message and/or slash commands in a plugin * fix(automod): start_thread action thread options * fix(CustomEvents): message command types * chore: remove unneeded type annotation * feat: add forum channel icon; use thread icon for news threads * chore: make tslint happy * chore: fix formatting --------- Signed-off-by: GitHub <noreply@github.com> Co-authored-by: almeidx <almeidx@pm.me> Co-authored-by: Dragory <2606411+Dragory@users.noreply.github.com>
2023-04-01 12:58:17 +01:00
import React, { SetStateAction } from "react";
2021-01-18 22:44:54 +02:00
import "./LogChannels.css";
const LOG_TYPES = {
2021-09-11 19:06:51 +03:00
MEMBER_WARN: "Member warned",
MEMBER_MUTE: "Member muted",
MEMBER_UNMUTE: "Member unmuted",
MEMBER_MUTE_EXPIRED: "Mute expired",
MEMBER_KICK: "Member kicked",
MEMBER_BAN: "Member banned",
MEMBER_UNBAN: "Member unbanned",
MEMBER_FORCEBAN: "Member forcebanned",
MEMBER_SOFTBAN: "Member softbanned",
MEMBER_JOIN: "Member joined",
MEMBER_LEAVE: "Member left",
MEMBER_ROLE_ADD: "Member, role added",
MEMBER_ROLE_REMOVE: "Member, role removed",
MEMBER_NICK_CHANGE: "Member nickname changed",
MEMBER_USERNAME_CHANGE: "Member username changed",
MEMBER_RESTORE: "Member roles restored",
CHANNEL_CREATE: "Channel created",
CHANNEL_DELETE: "Channel deleted",
CHANNEL_UPDATE: "Channel updated",
THREAD_CREATE: "Thread created",
THREAD_DELETE: "Thread deleted",
THREAD_UPDATE: "Thread updated",
ROLE_CREATE: "Role created",
ROLE_DELETE: "Role deleted",
ROLE_UPDATE: "Role updated",
MESSAGE_EDIT: "Message edited",
MESSAGE_DELETE: "Message deleted",
MESSAGE_DELETE_BULK: "Messages deleted in bulk",
MESSAGE_DELETE_BARE: "Message deleted (bare)",
VOICE_CHANNEL_JOIN: "Voice channel join",
VOICE_CHANNEL_LEAVE: "Voice channel leave",
VOICE_CHANNEL_MOVE: "Voice channel move",
STAGE_INSTANCE_CREATE: "Stage created",
STAGE_INSTANCE_DELETE: "Stage deleted",
STAGE_INSTANCE_UPDATE: "Stage updated",
EMOJI_CREATE: "Emoji created",
EMOJI_DELETE: "Emoji deleted",
EMOJI_UPDATE: "Emoji updated",
STICKER_CREATE: "Sticker created",
STICKER_DELETE: "Sticker deleted",
STICKER_UPDATE: "Sticker updated",
COMMAND: "Command used",
MESSAGE_SPAM_DETECTED: "Message spam detected",
CENSOR: "Message censored",
CLEAN: "Messages cleaned",
CASE_CREATE: "Case created",
MASSBAN: "Massbanned",
MASSMUTE: "Massmuted",
MEMBER_TIMED_MUTE: "Member temporarily muted",
MEMBER_TIMED_UNMUTE: "Member, scheduled unmute",
MEMBER_JOIN_WITH_PRIOR_RECORDS: "Member joined with prior records",
OTHER_SPAM_DETECTED: "Non-message spam detected",
MEMBER_ROLE_CHANGES: "Member roles changed",
VOICE_CHANNEL_FORCE_MOVE: "Force-moved to a voice channel",
CASE_UPDATE: "Case updated",
MEMBER_MUTE_REJOIN: "Muted member rejoined",
SCHEDULED_MESSAGE: "Scheduled message to be posted",
POSTED_SCHEDULED_MESSAGE: "Posted scheduled message",
BOT_ALERT: "Bot alert",
AUTOMOD_ACTION: "Automod action",
SCHEDULED_REPEATED_MESSAGE: "Scheduled message to be posted repeatedly",
REPEATED_MESSAGE: "Set a message to be posted repeatedly",
MESSAGE_DELETE_AUTO: "Message deleted (auto)",
SET_ANTIRAID_USER: "Set antiraid (user)",
SET_ANTIRAID_AUTO: "Set antiraid (auto)",
MEMBER_NOTE: "Member noted",
CASE_DELETE: "Case deleted",
DM_FAILED: "Failed to DM member",
2021-01-18 22:44:54 +02:00
};
2021-01-20 22:19:10 +02:00
const sortedLogTypes = Object.fromEntries(
2021-09-11 19:06:51 +03:00
Object.entries(LOG_TYPES).sort((a, b) => {
if (a[1].toLowerCase() > b[1].toLowerCase()) return 1;
if (a[1].toLowerCase() < b[1].toLowerCase()) return -1;
if (a[0].toLowerCase() > b[0].toLowerCase()) return 1;
if (a[0].toLowerCase() < b[0].toLowerCase()) return -1;
return 0;
}),
2021-01-20 22:19:10 +02:00
) as typeof LOG_TYPES;
2021-01-18 22:44:54 +02:00
type LOG_TYPE = keyof typeof LOG_TYPES;
export interface LogChannel {
id: string;
includeExclude: "include" | "exclude";
logTypes: Set<LOG_TYPE>;
}
interface Props {
logChannels: LogChannel[];
setLogChannels: React.Dispatch<SetStateAction<LogChannel[]>>;
}
export function LogChannels({ logChannels, setLogChannels }: Props) {
function addLogChannel(props: Partial<LogChannel> = {}) {
2021-09-11 19:06:51 +03:00
setLogChannels((_logChannels) => {
return [
..._logChannels,
{
id: "",
includeExclude: "include",
logTypes: new Set(),
...props,
},
];
2021-01-18 22:44:54 +02:00
});
}
function deleteLogChannel(index) {
2021-09-11 19:06:51 +03:00
setLogChannels((_logChannels) => {
2021-01-18 22:44:54 +02:00
const newArr = [..._logChannels];
newArr.splice(index, 1);
return newArr;
});
}
function addReverseLogChannel() {
2021-09-11 19:06:51 +03:00
const includedLogTypesInOtherLogChannels = new Set(logChannels.map((l) => Array.from(l.logTypes)).flat());
addLogChannel({
includeExclude: "exclude",
logTypes: includedLogTypesInOtherLogChannels,
});
}
2021-01-18 22:44:54 +02:00
function setId(index: number, id: string) {
2021-09-11 19:06:51 +03:00
setLogChannels((_logChannels) => {
2021-01-18 22:44:54 +02:00
_logChannels[index].id = id;
return [..._logChannels];
});
}
function setIncludeExclude(index: number, includeExclude: LogChannel["includeExclude"]) {
2021-09-11 19:06:51 +03:00
setLogChannels((_logChannels) => {
2021-01-18 22:44:54 +02:00
_logChannels[index].includeExclude = includeExclude;
return [..._logChannels];
});
}
function toggleLogType(index: number, logType: LOG_TYPE, enabled: boolean) {
2021-09-11 19:06:51 +03:00
setLogChannels((_logChannels) => {
2021-01-18 22:44:54 +02:00
if (enabled) {
_logChannels[index].logTypes.add(logType);
} else {
_logChannels[index].logTypes.delete(logType);
}
return [..._logChannels];
});
}
return (
<div className="LogChannels">
{logChannels.map((logChannel, index) => (
<div className="log-channel">
<label>
2021-09-11 19:06:51 +03:00
ID: <input value={logChannel.id} onChange={(e) => setId(index, e.target.value)} />
2021-01-18 22:44:54 +02:00
</label>
<label>
Mode:
2021-09-11 19:06:51 +03:00
<select
value={logChannel.includeExclude}
onChange={(e) => setIncludeExclude(index, e.target.value as LogChannel["includeExclude"])}
>
2021-01-18 22:44:54 +02:00
<option value={"include"}>Include</option>
<option value={"exclude"}>Exclude</option>
</select>
</label>
<div className="log-types">
2021-01-20 22:19:10 +02:00
{Object.entries(sortedLogTypes).map(([logType, description]) => (
2021-01-18 22:44:54 +02:00
<label>
<input
type="checkbox"
checked={logChannel.logTypes.has(logType as LOG_TYPE)}
2021-09-11 19:06:51 +03:00
onChange={(e) => toggleLogType(index, logType as LOG_TYPE, e.target.checked)}
2021-01-18 22:44:54 +02:00
/>
{description}
</label>
))}
</div>
<button onClick={() => deleteLogChannel(index)}>Delete</button>
2021-01-18 22:44:54 +02:00
</div>
))}
<button onClick={() => addLogChannel()}>Add</button>
<button onClick={() => addReverseLogChannel()}>Add "everything else"</button>
2021-01-18 22:44:54 +02:00
</div>
);
}