generated from nhcarrigan/template
feat: add security actions
This commit is contained in:
36
src/modules/maintainSecurity.ts
Normal file
36
src/modules/maintainSecurity.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { ExtendedClient } from "../interfaces/ExtendedClient";
|
||||
import { errorHandler } from "../utils/errorHandler";
|
||||
|
||||
/**
|
||||
* Loops through the list of configured servers to lock security for, and processes the
|
||||
* API calls.
|
||||
*
|
||||
* @param {ExtendedClient} bot The bot's Discord instance.
|
||||
*/
|
||||
export const maintainSecurity = async (bot: ExtendedClient) => {
|
||||
try {
|
||||
const records = await bot.db.security.findMany();
|
||||
const date = new Date(new Date().getTime() + 24 * 60 * 60 * 1000);
|
||||
for (const record of records) {
|
||||
await fetch(
|
||||
`https://discord.com/api/v10/guilds/${record.serverId}/incident-actions`,
|
||||
{
|
||||
method: "PUT",
|
||||
headers: {
|
||||
Authorization: `Bot ${bot.env.token}`,
|
||||
"content-type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
dms_disabled_until: record.lockDms ? date : null,
|
||||
invites_disabled_until: record.lockInvites ? date : null
|
||||
})
|
||||
}
|
||||
).catch(
|
||||
async (e) =>
|
||||
await errorHandler(bot, `incident-actions for ${record.serverId}`, e)
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
await errorHandler(bot, "maintain security", err);
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user