-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
75 lines (62 loc) · 2.5 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const { Client, GatewayIntentBits, Collection } = require("discord.js");
const cron = require("node-cron");
const fetch = require("@replit/node-fetch");
const Database = require("better-sqlite3-multiple-ciphers");
const fs = require("fs");
const path = require("path");
require("dotenv").config();
const db = new Database("./.data/data.db");
db.pragma('journal_mode = WAL');
db.exec(fs.readFileSync("./init.sql").toString());
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.token = process.env.token;
client.commands = new Collection();
const cmd = [];
const cmdpath = path.join(__dirname, "cmd");
const cmdfiles = fs.readdirSync(cmdpath).filter(file => file.endsWith('.js'));
for (const file of cmdfiles) {
const filePath = path.join(cmdpath, file);
require.cache[require.resolve(filePath)] = undefined;
const command = require(filePath);
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
cmd.push(command.data)
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
client.on("ready", async () => {
try {
await client.application.commands.set(cmd);
}
catch (e) {
console.error(e)
}
console.log(`[INFO] Ready to as ${client.user.tag}.`);
});
cron.schedule("0 0,12 * * *", async () => {
const guilds = db.prepare("select * from guilds").all();
for (const guild of guilds) {
let option = { "invites_disabled_until": null, "dms_disabled_until": null }
if (guild.invite == "true") {
option.invites_disabled_until = new Date(Date.now() + 86400 * 1000).toISOString().replace(/\.[0-9]{3}Z/, "+00:00");
}
if (guild.dm == "true") {
option.dms_disabled_until = new Date(Date.now() + 86400 * 1000).toISOString().replace(/\.[0-9]{3}Z/, "+00:00");
}
await fetch(`https://discord.com/api/v9/guilds/${guild.id}/incident-actions`, { method: "put", headers: { "content-type": "application/json", authorization: `Bot ${client.token}` }, body: JSON.stringify(option) });
}
});
client.on("guildDelete", async (guild) => {
db.prepare("delete from guilds where id = ?").run(guild.id);
});
client.on("interactionCreate", async (int) => {
const command = client.commands.get(int.commandName);
if (!command) return;
try {
await command.execute(int, client, db);
} catch (error) {
console.error(error);
}
});
client.login();