mirror of
https://github.com/janderedev/automod.git
synced 2024-12-22 10:45:27 +00:00
allow configuring warn/kick/ban DMs + contact info
(someone needs to refactor the hot mess that is ServerDashboard.tsx aaa)
This commit is contained in:
parent
5546ec3c59
commit
ad353463a6
|
@ -16,6 +16,9 @@ type ServerDetails = {
|
||||||
serverConfig: any,
|
serverConfig: any,
|
||||||
users: User[],
|
users: User[],
|
||||||
channels: Channel[],
|
channels: Channel[],
|
||||||
|
dmOnKick?: boolean,
|
||||||
|
dmOnWarn?: boolean,
|
||||||
|
contact?: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
app.get('/dash/server/:server', requireAuth({ permission: 0 }), async (req: Request, res: Response) => {
|
app.get('/dash/server/:server', requireAuth({ permission: 0 }), async (req: Request, res: Response) => {
|
||||||
|
@ -118,10 +121,16 @@ app.put('/dash/server/:server/:option', async (req: Request, res: Response) => {
|
||||||
type RequestBody = {
|
type RequestBody = {
|
||||||
prefix?: string,
|
prefix?: string,
|
||||||
spaceAfterPrefix?: boolean,
|
spaceAfterPrefix?: boolean,
|
||||||
|
dmOnKick?: boolean,
|
||||||
|
dmOnWarn?: boolean,
|
||||||
|
contact?: boolean,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!validateField('prefix', ['string'], 2) ||
|
if (!validateField('prefix', ['string'], 2) ||
|
||||||
!validateField('spaceAfterPrefix', ['boolean'], 2)
|
!validateField('spaceAfterPrefix', ['boolean'], 2) ||
|
||||||
|
!validateField('dmOnKick', ['boolean'], 2) ||
|
||||||
|
!validateField('dmOnWarn', ['boolean'], 2) ||
|
||||||
|
!validateField('contact', ['string'], 2)
|
||||||
) return;
|
) return;
|
||||||
|
|
||||||
const body: RequestBody = req.body;
|
const body: RequestBody = req.body;
|
||||||
|
@ -130,6 +139,9 @@ app.put('/dash/server/:server/:option', async (req: Request, res: Response) => {
|
||||||
$set: JSON.parse(JSON.stringify({ // Get rid of undefined fields
|
$set: JSON.parse(JSON.stringify({ // Get rid of undefined fields
|
||||||
prefix: body.prefix == '' ? null : body.prefix,
|
prefix: body.prefix == '' ? null : body.prefix,
|
||||||
spaceAfterPrefix: body.spaceAfterPrefix,
|
spaceAfterPrefix: body.spaceAfterPrefix,
|
||||||
|
dmOnKick: body.dmOnKick,
|
||||||
|
dmOnWarn: body.dmOnWarn,
|
||||||
|
contact: body.contact,
|
||||||
})),
|
})),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,9 @@ type ServerDetails = {
|
||||||
serverConfig?: ServerConfig,
|
serverConfig?: ServerConfig,
|
||||||
users: APIUser[],
|
users: APIUser[],
|
||||||
channels: APIChannel[],
|
channels: APIChannel[],
|
||||||
|
dmOnKick?: boolean,
|
||||||
|
dmOnWarn?: boolean,
|
||||||
|
contact?: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
wsEvents.on('req:getUserServerDetails', async (data: ReqData, cb: (data: WSResponse) => void) => {
|
wsEvents.on('req:getUserServerDetails', async (data: ReqData, cb: (data: WSResponse) => void) => {
|
||||||
|
@ -80,6 +83,9 @@ wsEvents.on('req:getUserServerDetails', async (data: ReqData, cb: (data: WSRespo
|
||||||
type: c!.channel_type == 'VoiceChannel' ? 'VOICE' : 'TEXT',
|
type: c!.channel_type == 'VoiceChannel' ? 'VOICE' : 'TEXT',
|
||||||
icon: c!.generateIconURL(),
|
icon: c!.generateIconURL(),
|
||||||
})),
|
})),
|
||||||
|
dmOnKick: serverConfig?.dmOnKick,
|
||||||
|
dmOnWarn: serverConfig?.dmOnWarn,
|
||||||
|
contact: serverConfig?.contact,
|
||||||
}
|
}
|
||||||
|
|
||||||
cb({ success: true, server: response });
|
cb({ success: true, server: response });
|
||||||
|
|
|
@ -29,6 +29,9 @@ type Server = {
|
||||||
serverConfig?: { [key: string]: any },
|
serverConfig?: { [key: string]: any },
|
||||||
users: User[],
|
users: User[],
|
||||||
channels: Channel[],
|
channels: Channel[],
|
||||||
|
dmOnKick?: boolean,
|
||||||
|
dmOnWarn?: boolean,
|
||||||
|
contact?: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
type AntispamRule = {
|
type AntispamRule = {
|
||||||
|
@ -51,10 +54,19 @@ const ServerDashboard: FunctionComponent = () => {
|
||||||
const [serverInfo, setServerInfo] = useState({} as Server);
|
const [serverInfo, setServerInfo] = useState({} as Server);
|
||||||
const [status, setStatus] = useState('');
|
const [status, setStatus] = useState('');
|
||||||
|
|
||||||
const [changed, setChanged] = useState({} as { prefix?: boolean, prefixAllowSpace?: boolean });
|
const [changed, setChanged] = useState({} as {
|
||||||
|
prefix?: boolean,
|
||||||
|
prefixAllowSpace?: boolean,
|
||||||
|
dmOnKick?: boolean,
|
||||||
|
dmOnWarn?: boolean,
|
||||||
|
contact?: boolean,
|
||||||
|
});
|
||||||
const [prefix, setPrefix] = useState('' as string|undefined);
|
const [prefix, setPrefix] = useState('' as string|undefined);
|
||||||
const [prefixAllowSpace, setPrefixAllowSpace] = useState(false);
|
const [prefixAllowSpace, setPrefixAllowSpace] = useState(false);
|
||||||
|
const [dmOnKick, setDmOnKick] = useState(false);
|
||||||
|
const [dmOnWarn, setDmOnWarn] = useState(false);
|
||||||
|
const [contact, setContact] = useState('');
|
||||||
|
|
||||||
const [botManagers, setBotManagers] = useState([] as string[]);
|
const [botManagers, setBotManagers] = useState([] as string[]);
|
||||||
const [moderators, setModerators] = useState([] as string[]);
|
const [moderators, setModerators] = useState([] as string[]);
|
||||||
|
|
||||||
|
@ -68,6 +80,9 @@ const ServerDashboard: FunctionComponent = () => {
|
||||||
const payload = {
|
const payload = {
|
||||||
...(changed.prefix ? { prefix } : undefined),
|
...(changed.prefix ? { prefix } : undefined),
|
||||||
...(changed.prefixAllowSpace ? { spaceAfterPrefix: prefixAllowSpace } : undefined),
|
...(changed.prefixAllowSpace ? { spaceAfterPrefix: prefixAllowSpace } : undefined),
|
||||||
|
...(changed.dmOnKick ? { dmOnKick } : undefined),
|
||||||
|
...(changed.dmOnWarn ? { dmOnWarn } : undefined),
|
||||||
|
...(changed.contact ? { contact: contact || null } : undefined),
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await axios.put(
|
const res = await axios.put(
|
||||||
|
@ -91,6 +106,9 @@ const ServerDashboard: FunctionComponent = () => {
|
||||||
|
|
||||||
setPrefix(server.serverConfig?.prefix || '');
|
setPrefix(server.serverConfig?.prefix || '');
|
||||||
setPrefixAllowSpace(!!server.serverConfig?.spaceAfterPrefix);
|
setPrefixAllowSpace(!!server.serverConfig?.spaceAfterPrefix);
|
||||||
|
setDmOnKick(!!server.serverConfig?.dmOnKick);
|
||||||
|
setDmOnWarn(!!server.serverConfig?.dmOnWarn);
|
||||||
|
setContact(server.serverConfig?.contact || '');
|
||||||
|
|
||||||
setBotManagers(server.serverConfig?.botManagers ?? []);
|
setBotManagers(server.serverConfig?.botManagers ?? []);
|
||||||
setModerators(server.serverConfig?.moderators ?? []);
|
setModerators(server.serverConfig?.moderators ?? []);
|
||||||
|
@ -190,10 +208,6 @@ const ServerDashboard: FunctionComponent = () => {
|
||||||
title="Allow space after prefix"
|
title="Allow space after prefix"
|
||||||
description={'Whether the bot recognizes a command if the prefix is followed by a space. Enable if your prefix is a word.'}
|
description={'Whether the bot recognizes a command if the prefix is followed by a space. Enable if your prefix is a word.'}
|
||||||
/>
|
/>
|
||||||
<Button
|
|
||||||
style={{ marginTop: "16px" }}
|
|
||||||
onClick={saveConfig}
|
|
||||||
>Save</Button>
|
|
||||||
</>
|
</>
|
||||||
|
|
||||||
<LineDivider />
|
<LineDivider />
|
||||||
|
@ -231,6 +245,47 @@ const ServerDashboard: FunctionComponent = () => {
|
||||||
</UserListContainer>
|
</UserListContainer>
|
||||||
</UserListTypeContainer>
|
</UserListTypeContainer>
|
||||||
</>
|
</>
|
||||||
|
|
||||||
|
<LineDivider />
|
||||||
|
|
||||||
|
<>
|
||||||
|
<H3>Infraction DMs</H3>
|
||||||
|
<Checkbox
|
||||||
|
title="DM on kick/ban"
|
||||||
|
description="If enabled, users will receive a DM when getting kicked or banned"
|
||||||
|
value={dmOnKick}
|
||||||
|
onChange={() => { setDmOnKick(!dmOnKick); setChanged({ ...changed, dmOnKick: true }) }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Checkbox
|
||||||
|
title="DM on warn"
|
||||||
|
description="If enabled, users will receive a DM when getting warned"
|
||||||
|
value={dmOnWarn}
|
||||||
|
onChange={() => { setDmOnWarn(!dmOnWarn); setChanged({ ...changed, dmOnWarn: true }) }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<H3>Contact info</H3>
|
||||||
|
<H4>
|
||||||
|
Provide a link, email address or instructions for users on how to contact you.
|
||||||
|
If provided, this data will be sent along with warn/kick/ban DM messages.
|
||||||
|
</H4>
|
||||||
|
<InputBox
|
||||||
|
style={{ margin: '8px', width: 'calc(100% - 16px)' }}
|
||||||
|
title='Contact info'
|
||||||
|
placeholder='http/https URL, mailto link or custom text...'
|
||||||
|
value={contact}
|
||||||
|
onChange={e => { setContact(e.currentTarget.value); setChanged({ ...changed, contact: true }) }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
style={{
|
||||||
|
position: "fixed",
|
||||||
|
right: '8px',
|
||||||
|
bottom: Object.values(changed).filter(i => i).length ? '8px' : '-40px',
|
||||||
|
}}
|
||||||
|
onClick={saveConfig}
|
||||||
|
>Save</Button>
|
||||||
|
</>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue