blob: 5386f7f213645f1480bb228bc9c4224796697db4 [file] [log] [blame]
Skyler Greyda16adf2023-03-05 10:22:12 +00001import {
2 ButtonStyle,
3 CommandInteraction,
4 ComponentType,
5 GuildMember,
6 Message,
7 MessageComponentInteraction
8} from "discord.js";
pineafan63fc5e22022-08-04 22:04:10 +01009import type Discord from "discord.js";
10import { Collection, MongoClient } from "mongodb";
pineafana2e39c72023-02-21 18:37:32 +000011import config from "../config/main.js";
TheCodedProf633866f2023-02-03 17:06:00 -050012import client from "../utils/client.js";
TheCodedProf088b1b22023-02-28 17:31:11 -050013import * as crypto from "crypto";
TheCodedProff8ef7942023-03-03 15:32:32 -050014import _ from "lodash";
Skyler Greyda16adf2023-03-05 10:22:12 +000015import defaultData from "../config/default.js";
TheCodedProf75276572023-03-04 13:49:16 -050016
pineafan6de4da52023-03-07 20:43:44 +000017let username, password;
18
Skyler Grey5b78b422023-03-07 22:36:20 +000019if ("username" in config.mongoOptions) username = encodeURIComponent(config.mongoOptions.username as string);
20if ("password" in config.mongoOptions) password = encodeURIComponent(config.mongoOptions.password as string);
Samuel Shuertd66098b2023-03-04 14:05:26 -050021
Skyler Greyda16adf2023-03-05 10:22:12 +000022const mongoClient = new MongoClient(
23 username
pineafan6de4da52023-03-07 20:43:44 +000024 ? `mongodb://${username}:${password}@${config.mongoOptions.host}?authMechanism=DEFAULT&authSource=${config.mongoOptions.authSource}`
25 : `mongodb://${config.mongoOptions.host}`
Skyler Greyda16adf2023-03-05 10:22:12 +000026);
pineafan63fc5e22022-08-04 22:04:10 +010027await mongoClient.connect();
TheCodedProf8d577fa2023-03-01 13:06:40 -050028const database = mongoClient.db();
pineafan6fb3e072022-05-20 19:27:23 +010029
TheCodedProf78b90332023-03-04 14:02:21 -050030const collectionOptions = { authdb: config.mongoOptions.authSource, w: "majority" };
TheCodedProf75c51be2023-03-03 17:18:18 -050031const getIV = () => crypto.randomBytes(16);
TheCodedProffaae5332023-03-01 18:16:05 -050032
pineafan4edb7762022-06-26 19:21:04 +010033export class Guilds {
pineafan6fb3e072022-05-20 19:27:23 +010034 guilds: Collection<GuildConfig>;
TheCodedProf8a2d7cd2023-03-05 14:53:59 -050035 oldGuilds: Collection<GuildConfig>;
TheCodedProff8ef7942023-03-03 15:32:32 -050036 defaultData: GuildConfig;
pineafan63fc5e22022-08-04 22:04:10 +010037
38 constructor() {
pineafan4edb7762022-06-26 19:21:04 +010039 this.guilds = database.collection<GuildConfig>("guilds");
TheCodedProff8ef7942023-03-03 15:32:32 -050040 this.defaultData = defaultData;
TheCodedProf8a2d7cd2023-03-05 14:53:59 -050041 this.oldGuilds = database.collection<GuildConfig>("oldGuilds");
42 }
43
44 async readOld(guild: string): Promise<Partial<GuildConfig>> {
45 // console.log("Guild read")
46 const entry = await this.oldGuilds.findOne({ id: guild });
47 return entry ?? {};
pineafan63fc5e22022-08-04 22:04:10 +010048 }
49
TheCodedProfb7a7b992023-03-05 16:11:59 -050050 async updateAllGuilds() {
51 const guilds = await this.guilds.find().toArray();
52 for (const guild of guilds) {
53 let guildObj;
54 try {
55 guildObj = await client.guilds.fetch(guild.id);
56 } catch (e) {
57 guildObj = null;
58 }
Skyler Grey67691762023-03-06 09:58:19 +000059 if (!guildObj) await this.delete(guild.id);
TheCodedProfb7a7b992023-03-05 16:11:59 -050060 }
61 }
62
Skyler Greyad002172022-08-16 18:48:26 +010063 async read(guild: string): Promise<GuildConfig> {
TheCodedProff8ef7942023-03-03 15:32:32 -050064 // console.log("Guild read")
pineafan63fc5e22022-08-04 22:04:10 +010065 const entry = await this.guilds.findOne({ id: guild });
TheCodedProf9f4cf9f2023-03-04 14:18:19 -050066 const data = _.cloneDeep(this.defaultData);
TheCodedProff8ef7942023-03-03 15:32:32 -050067 return _.merge(data, entry ?? {});
pineafan6fb3e072022-05-20 19:27:23 +010068 }
69
Skyler Grey11236ba2022-08-08 21:13:33 +010070 async write(guild: string, set: object | null, unset: string[] | string = []) {
TheCodedProff8ef7942023-03-03 15:32:32 -050071 // console.log("Guild write")
pineafan63fc5e22022-08-04 22:04:10 +010072 // eslint-disable-next-line @typescript-eslint/no-explicit-any
73 const uo: Record<string, any> = {};
74 if (!Array.isArray(unset)) unset = [unset];
75 for (const key of unset) {
pineafan0bc04162022-07-25 17:22:26 +010076 uo[key] = null;
pineafan6702cef2022-06-13 17:52:37 +010077 }
Skyler Grey75ea9172022-08-06 10:22:23 +010078 const out = { $set: {}, $unset: {} };
79 if (set) out.$set = set;
80 if (unset.length) out.$unset = uo;
pineafan0bc04162022-07-25 17:22:26 +010081 await this.guilds.updateOne({ id: guild }, out, { upsert: true });
pineafan6702cef2022-06-13 17:52:37 +010082 }
83
pineafan63fc5e22022-08-04 22:04:10 +010084 // eslint-disable-next-line @typescript-eslint/no-explicit-any
pineafan6702cef2022-06-13 17:52:37 +010085 async append(guild: string, key: string, value: any) {
TheCodedProff8ef7942023-03-03 15:32:32 -050086 // console.log("Guild append")
pineafan6702cef2022-06-13 17:52:37 +010087 if (Array.isArray(value)) {
Skyler Grey75ea9172022-08-06 10:22:23 +010088 await this.guilds.updateOne(
89 { id: guild },
90 {
91 $addToSet: { [key]: { $each: value } }
92 },
93 { upsert: true }
94 );
pineafan6702cef2022-06-13 17:52:37 +010095 } else {
Skyler Grey75ea9172022-08-06 10:22:23 +010096 await this.guilds.updateOne(
97 { id: guild },
98 {
99 $addToSet: { [key]: value }
100 },
101 { upsert: true }
102 );
pineafan6702cef2022-06-13 17:52:37 +0100103 }
104 }
105
Skyler Grey75ea9172022-08-06 10:22:23 +0100106 async remove(
107 guild: string,
108 key: string,
Skyler Greyc634e2b2022-08-06 17:50:48 +0100109 // eslint-disable-next-line @typescript-eslint/no-explicit-any
Skyler Grey75ea9172022-08-06 10:22:23 +0100110 value: any,
111 innerKey?: string | null
112 ) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500113 // console.log("Guild remove")
pineafan02ba0232022-07-24 22:16:15 +0100114 if (innerKey) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100115 await this.guilds.updateOne(
116 { id: guild },
117 {
118 $pull: { [key]: { [innerKey]: { $eq: value } } }
119 },
120 { upsert: true }
121 );
pineafan0bc04162022-07-25 17:22:26 +0100122 } else if (Array.isArray(value)) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100123 await this.guilds.updateOne(
124 { id: guild },
125 {
126 $pullAll: { [key]: value }
127 },
128 { upsert: true }
129 );
pineafan6702cef2022-06-13 17:52:37 +0100130 } else {
Skyler Grey75ea9172022-08-06 10:22:23 +0100131 await this.guilds.updateOne(
132 { id: guild },
133 {
134 $pullAll: { [key]: [value] }
135 },
136 { upsert: true }
137 );
pineafan6702cef2022-06-13 17:52:37 +0100138 }
pineafan6fb3e072022-05-20 19:27:23 +0100139 }
pineafane23c4ec2022-07-27 21:56:27 +0100140
141 async delete(guild: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500142 // console.log("Guild delete")
pineafane23c4ec2022-07-27 21:56:27 +0100143 await this.guilds.deleteOne({ id: guild });
144 }
TheCodedProfa38cbb32023-03-11 17:22:25 -0500145
146 async staffChannels(): Promise<string[]> {
TheCodedProf528de572023-03-11 17:28:29 -0500147 const entries = await this.guilds
148 .find(
149 { "logging.staff.channel": { $exists: true } },
150 { projection: { "logging.staff.channel": 1, _id: 0 } }
151 )
152 .toArray();
153 return entries.map((e) => e.logging.staff.channel!);
TheCodedProfa38cbb32023-03-11 17:22:25 -0500154 }
pineafan6fb3e072022-05-20 19:27:23 +0100155}
156
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500157interface TranscriptEmbed {
158 title?: string;
159 description?: string;
160 fields?: {
161 name: string;
162 value: string;
163 inline: boolean;
164 }[];
165 footer?: {
166 text: string;
167 iconURL?: string;
168 };
TheCodedProffaae5332023-03-01 18:16:05 -0500169 color?: number;
170 timestamp?: string;
171 author?: {
172 name: string;
173 iconURL?: string;
174 url?: string;
175 };
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500176}
177
178interface TranscriptComponent {
179 type: number;
180 style?: ButtonStyle;
181 label?: string;
182 description?: string;
183 placeholder?: string;
184 emojiURL?: string;
185}
186
187interface TranscriptAuthor {
188 username: string;
189 discriminator: number;
190 nickname?: string;
191 id: string;
192 iconURL?: string;
193 topRole: {
194 color: number;
195 badgeURL?: string;
TheCodedProf088b1b22023-02-28 17:31:11 -0500196 };
197 bot: boolean;
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500198}
199
200interface TranscriptAttachment {
201 url: string;
202 filename: string;
203 size: number;
204 log?: string;
205}
206
207interface TranscriptMessage {
208 id: string;
209 author: TranscriptAuthor;
210 content?: string;
211 embeds?: TranscriptEmbed[];
212 components?: TranscriptComponent[][];
213 editedTimestamp?: number;
214 createdTimestamp: number;
215 flags?: string[];
216 attachments?: TranscriptAttachment[];
217 stickerURLs?: string[];
Skyler Greyda16adf2023-03-05 10:22:12 +0000218 referencedMessage?: string | [string, string, string]; // the message id, the channel id, the guild id
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500219}
220
221interface TranscriptSchema {
222 code: string;
223 for: TranscriptAuthor;
Skyler Greyda16adf2023-03-05 10:22:12 +0000224 type: "ticket" | "purge";
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500225 guild: string;
226 channel: string;
227 messages: TranscriptMessage[];
228 createdTimestamp: number;
229 createdBy: TranscriptAuthor;
230}
231
Skyler Greyda16adf2023-03-05 10:22:12 +0000232interface findDocSchema {
233 channelID: string;
234 messageID: string;
Skyler Grey5b78b422023-03-07 22:36:20 +0000235 code: string;
Skyler Greyda16adf2023-03-05 10:22:12 +0000236}
TheCodedProf003160f2023-03-04 17:09:40 -0500237
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500238export class Transcript {
239 transcripts: Collection<TranscriptSchema>;
TheCodedProf003160f2023-03-04 17:09:40 -0500240 messageToTranscript: Collection<findDocSchema>;
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500241
242 constructor() {
243 this.transcripts = database.collection<TranscriptSchema>("transcripts");
TheCodedProf003160f2023-03-04 17:09:40 -0500244 this.messageToTranscript = database.collection<findDocSchema>("messageToTranscript");
245 }
246
247 async upload(data: findDocSchema) {
248 // console.log("Transcript upload")
249 await this.messageToTranscript.insertOne(data);
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500250 }
251
252 async create(transcript: Omit<TranscriptSchema, "code">) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500253 // console.log("Transcript create")
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500254 let code;
255 do {
TheCodedProf088b1b22023-02-28 17:31:11 -0500256 code = crypto.randomBytes(64).toString("base64").replace(/=/g, "").replace(/\//g, "_").replace(/\+/g, "-");
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500257 } while (await this.transcripts.findOne({ code: code }));
Skyler Greyda16adf2023-03-05 10:22:12 +0000258 const key = crypto
259 .randomBytes(32 ** 2)
260 .toString("base64")
261 .replace(/=/g, "")
262 .replace(/\//g, "_")
263 .replace(/\+/g, "-")
264 .substring(0, 32);
Skyler Grey67691762023-03-06 09:58:19 +0000265 const iv = getIV()
266 .toString("base64")
267 .substring(0, 16)
268 .replace(/=/g, "")
269 .replace(/\//g, "_")
270 .replace(/\+/g, "-");
271 console.log(iv);
Skyler Greyda16adf2023-03-05 10:22:12 +0000272 for (const message of transcript.messages) {
273 if (message.content) {
TheCodedProf75c51be2023-03-03 17:18:18 -0500274 const encCipher = crypto.createCipheriv("AES-256-CBC", key, iv);
275 message.content = encCipher.update(message.content, "utf8", "base64") + encCipher.final("base64");
276 }
277 }
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500278
TheCodedProffaae5332023-03-01 18:16:05 -0500279 const doc = await this.transcripts.insertOne(Object.assign(transcript, { code: code }), collectionOptions);
Skyler Greyda16adf2023-03-05 10:22:12 +0000280 if (doc.acknowledged) {
Skyler Greyf4f21c42023-03-08 14:36:29 +0000281 await client.database.eventScheduler.schedule(
Skyler Greyda16adf2023-03-05 10:22:12 +0000282 "deleteTranscript",
283 (Date.now() + 1000 * 60 * 60 * 24 * 7).toString(),
284 { guild: transcript.guild, code: code, iv: iv, key: key }
285 );
TheCodedProf003160f2023-03-04 17:09:40 -0500286 return [code, key, iv];
Skyler Greyda16adf2023-03-05 10:22:12 +0000287 } else return [null, null, null];
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500288 }
289
TheCodedProf003160f2023-03-04 17:09:40 -0500290 async delete(code: string) {
291 // console.log("Transcript delete")
292 await this.transcripts.deleteOne({ code: code });
TheCodedProf75c51be2023-03-03 17:18:18 -0500293 }
294
295 async deleteAll(guild: string) {
296 // console.log("Transcript delete")
297 const filteredDocs = await this.transcripts.find({ guild: guild }).toArray();
298 for (const doc of filteredDocs) {
299 await this.transcripts.deleteOne({ code: doc.code });
300 }
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500301 }
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500302
TheCodedProf003160f2023-03-04 17:09:40 -0500303 async readEncrypted(code: string) {
304 // console.log("Transcript read")
305 let doc: TranscriptSchema | null = await this.transcripts.findOne({ code: code });
306 let findDoc: findDocSchema | null = null;
pineafan6de4da52023-03-07 20:43:44 +0000307 if (!doc) findDoc = await this.messageToTranscript.findOne({ transcript: code });
Skyler Greyda16adf2023-03-05 10:22:12 +0000308 if (findDoc) {
309 const message = await (
310 client.channels.cache.get(findDoc.channelID) as Discord.TextBasedChannel | null
311 )?.messages.fetch(findDoc.messageID);
312 if (!message) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500313 const attachment = message.attachments.first();
Skyler Greyda16adf2023-03-05 10:22:12 +0000314 if (!attachment) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500315 const transcript = (await fetch(attachment.url)).body;
Skyler Greyda16adf2023-03-05 10:22:12 +0000316 if (!transcript) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500317 const reader = transcript.getReader();
318 let data: Uint8Array | null = null;
319 let allPacketsReceived = false;
320 while (!allPacketsReceived) {
321 const { value, done } = await reader.read();
Skyler Greyda16adf2023-03-05 10:22:12 +0000322 if (done) {
323 allPacketsReceived = true;
324 continue;
325 }
326 if (!data) {
TheCodedProf003160f2023-03-04 17:09:40 -0500327 data = value;
328 } else {
329 data = new Uint8Array(Buffer.concat([data, value]));
330 }
331 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000332 if (!data) return null;
Skyler Greycf771402023-03-05 07:06:37 +0000333 doc = JSON.parse(Buffer.from(data).toString()) as TranscriptSchema;
TheCodedProf003160f2023-03-04 17:09:40 -0500334 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000335 if (!doc) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500336 return doc;
337 }
338
339 async read(code: string, key: string, iv: string) {
Skyler Grey67691762023-03-06 09:58:19 +0000340 console.log("Transcript read");
TheCodedProf003160f2023-03-04 17:09:40 -0500341 let doc: TranscriptSchema | null = await this.transcripts.findOne({ code: code });
342 let findDoc: findDocSchema | null = null;
Skyler Grey67691762023-03-06 09:58:19 +0000343 console.log(doc);
pineafan6de4da52023-03-07 20:43:44 +0000344 if (!doc) findDoc = await this.messageToTranscript.findOne({ transcript: code });
Skyler Greyda16adf2023-03-05 10:22:12 +0000345 if (findDoc) {
346 const message = await (
347 client.channels.cache.get(findDoc.channelID) as Discord.TextBasedChannel | null
348 )?.messages.fetch(findDoc.messageID);
349 if (!message) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500350 const attachment = message.attachments.first();
Skyler Greyda16adf2023-03-05 10:22:12 +0000351 if (!attachment) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500352 const transcript = (await fetch(attachment.url)).body;
Skyler Greyda16adf2023-03-05 10:22:12 +0000353 if (!transcript) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500354 const reader = transcript.getReader();
355 let data: Uint8Array | null = null;
356 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, no-constant-condition
Skyler Greyda16adf2023-03-05 10:22:12 +0000357 while (true) {
TheCodedProf003160f2023-03-04 17:09:40 -0500358 const { value, done } = await reader.read();
359 if (done) break;
Skyler Greyda16adf2023-03-05 10:22:12 +0000360 if (!data) {
TheCodedProf003160f2023-03-04 17:09:40 -0500361 data = value;
362 } else {
363 data = new Uint8Array(Buffer.concat([data, value]));
364 }
365 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000366 if (!data) return null;
Skyler Greycf771402023-03-05 07:06:37 +0000367 doc = JSON.parse(Buffer.from(data).toString()) as TranscriptSchema;
TheCodedProf003160f2023-03-04 17:09:40 -0500368 }
Skyler Grey67691762023-03-06 09:58:19 +0000369 console.log(doc);
Skyler Greyda16adf2023-03-05 10:22:12 +0000370 if (!doc) return null;
371 for (const message of doc.messages) {
372 if (message.content) {
TheCodedProf003160f2023-03-04 17:09:40 -0500373 const decCipher = crypto.createDecipheriv("AES-256-CBC", key, iv);
374 message.content = decCipher.update(message.content, "base64", "utf8") + decCipher.final("utf8");
375 }
376 }
377 return doc;
378 }
379
Skyler Greyda16adf2023-03-05 10:22:12 +0000380 async createTranscript(
Skyler Greye0c511b2023-03-06 10:30:17 +0000381 type: "ticket" | "purge",
Skyler Greyda16adf2023-03-05 10:22:12 +0000382 messages: Message[],
383 interaction: MessageComponentInteraction | CommandInteraction,
384 member: GuildMember
385 ) {
386 const interactionMember = await interaction.guild?.members.fetch(interaction.user.id);
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500387 const newOut: Omit<TranscriptSchema, "code"> = {
Skyler Greye0c511b2023-03-06 10:30:17 +0000388 type: type,
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500389 for: {
390 username: member!.user.username,
391 discriminator: parseInt(member!.user.discriminator),
392 id: member!.user.id,
393 topRole: {
394 color: member!.roles.highest.color
TheCodedProf088b1b22023-02-28 17:31:11 -0500395 },
Skyler Greyda16adf2023-03-05 10:22:12 +0000396 iconURL: member!.user.displayAvatarURL({ forceStatic: true }),
TheCodedProf088b1b22023-02-28 17:31:11 -0500397 bot: member!.user.bot
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500398 },
399 guild: interaction.guild!.id,
400 channel: interaction.channel!.id,
401 messages: [],
402 createdTimestamp: Date.now(),
403 createdBy: {
404 username: interaction.user.username,
405 discriminator: parseInt(interaction.user.discriminator),
406 id: interaction.user.id,
407 topRole: {
408 color: interactionMember?.roles.highest.color ?? 0x000000
TheCodedProf088b1b22023-02-28 17:31:11 -0500409 },
Skyler Greyda16adf2023-03-05 10:22:12 +0000410 iconURL: interaction.user.displayAvatarURL({ forceStatic: true }),
TheCodedProf088b1b22023-02-28 17:31:11 -0500411 bot: interaction.user.bot
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500412 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000413 };
414 if (member.nickname) newOut.for.nickname = member.nickname;
415 if (interactionMember?.roles.icon) newOut.createdBy.topRole.badgeURL = interactionMember.roles.icon.iconURL()!;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500416 messages.reverse().forEach((message) => {
417 const msg: TranscriptMessage = {
418 id: message.id,
419 author: {
420 username: message.author.username,
421 discriminator: parseInt(message.author.discriminator),
422 id: message.author.id,
423 topRole: {
Skyler Greya0c70242023-03-06 09:56:21 +0000424 color: message.member ? message.member.roles.highest.color : 0x000000
TheCodedProf088b1b22023-02-28 17:31:11 -0500425 },
TheCodedProfe92b9b52023-03-06 17:07:34 -0500426 iconURL: (message.member?.user ?? message.author).displayAvatarURL({ forceStatic: true }),
Skyler Grey67691762023-03-06 09:58:19 +0000427 bot: message.author.bot || false
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500428 },
429 createdTimestamp: message.createdTimestamp
430 };
Skyler Greyda16adf2023-03-05 10:22:12 +0000431 if (message.member?.nickname) msg.author.nickname = message.member.nickname;
Skyler Greya0c70242023-03-06 09:56:21 +0000432 if (message.member?.roles.icon) msg.author.topRole.badgeURL = message.member!.roles.icon.iconURL()!;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500433 if (message.content) msg.content = message.content;
Skyler Greyda16adf2023-03-05 10:22:12 +0000434 if (message.embeds.length > 0)
435 msg.embeds = message.embeds.map((embed) => {
436 const obj: TranscriptEmbed = {};
437 if (embed.title) obj.title = embed.title;
438 if (embed.description) obj.description = embed.description;
439 if (embed.fields.length > 0)
440 obj.fields = embed.fields.map((field) => {
441 return {
442 name: field.name,
443 value: field.value,
444 inline: field.inline ?? false
445 };
446 });
447 if (embed.color) obj.color = embed.color;
448 if (embed.timestamp) obj.timestamp = embed.timestamp;
449 if (embed.footer)
450 obj.footer = {
451 text: embed.footer.text
452 };
453 if (embed.footer?.iconURL) obj.footer!.iconURL = embed.footer.iconURL;
454 if (embed.author)
455 obj.author = {
456 name: embed.author.name
457 };
458 if (embed.author?.iconURL) obj.author!.iconURL = embed.author.iconURL;
459 if (embed.author?.url) obj.author!.url = embed.author.url;
460 return obj;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500461 });
Skyler Greyda16adf2023-03-05 10:22:12 +0000462 if (message.components.length > 0)
463 msg.components = message.components.map((component) =>
464 component.components.map((child) => {
465 const obj: TranscriptComponent = {
466 type: child.type
467 };
468 if (child.type === ComponentType.Button) {
469 obj.style = child.style;
470 obj.label = child.label ?? "";
471 } else if (child.type > 2) {
472 obj.placeholder = child.placeholder ?? "";
473 }
474 return obj;
475 })
476 );
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500477 if (message.editedTimestamp) msg.editedTimestamp = message.editedTimestamp;
478 msg.flags = message.flags.toArray();
479
Skyler Greyda16adf2023-03-05 10:22:12 +0000480 if (message.stickers.size > 0) msg.stickerURLs = message.stickers.map((sticker) => sticker.url);
481 if (message.reference)
482 msg.referencedMessage = [
483 message.reference.guildId ?? "",
484 message.reference.channelId,
485 message.reference.messageId ?? ""
486 ];
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500487 newOut.messages.push(msg);
488 });
489 return newOut;
490 }
491
492 toHumanReadable(transcript: Omit<TranscriptSchema, "code">): string {
493 let out = "";
494 for (const message of transcript.messages) {
495 if (message.referencedMessage) {
496 if (Array.isArray(message.referencedMessage)) {
497 out += `> [Crosspost From] ${message.referencedMessage[0]} in ${message.referencedMessage[1]} in ${message.referencedMessage[2]}\n`;
Skyler Greyda16adf2023-03-05 10:22:12 +0000498 } else out += `> [Reply To] ${message.referencedMessage}\n`;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500499 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000500 out += `${message.author.nickname ?? message.author.username}#${message.author.discriminator} (${
501 message.author.id
502 }) (${message.id})`;
TheCodedProff8ef7942023-03-03 15:32:32 -0500503 out += ` [${new Date(message.createdTimestamp).toISOString()}]`;
504 if (message.editedTimestamp) out += ` [Edited: ${new Date(message.editedTimestamp).toISOString()}]`;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500505 out += "\n";
506 if (message.content) out += `[Content]\n${message.content}\n\n`;
507 if (message.embeds) {
508 for (const embed of message.embeds) {
509 out += `[Embed]\n`;
510 if (embed.title) out += `| Title: ${embed.title}\n`;
511 if (embed.description) out += `| Description: ${embed.description}\n`;
512 if (embed.fields) {
513 for (const field of embed.fields) {
514 out += `| Field: ${field.name} - ${field.value}\n`;
515 }
516 }
517 if (embed.footer) {
518 out += `|Footer: ${embed.footer.text}\n`;
519 }
520 out += "\n";
521 }
522 }
523 if (message.components) {
524 for (const component of message.components) {
525 out += `[Component]\n`;
526 for (const button of component) {
527 out += `| Button: ${button.label ?? button.description}\n`;
528 }
529 out += "\n";
530 }
531 }
532 if (message.attachments) {
533 for (const attachment of message.attachments) {
534 out += `[Attachment] ${attachment.filename} (${attachment.size} bytes) ${attachment.url}\n`;
535 }
536 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000537 out += "\n\n";
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500538 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000539 return out;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500540 }
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500541}
542
pineafan4edb7762022-06-26 19:21:04 +0100543export class History {
544 histories: Collection<HistorySchema>;
pineafan4edb7762022-06-26 19:21:04 +0100545
pineafan3a02ea32022-08-11 21:35:04 +0100546 constructor() {
pineafan4edb7762022-06-26 19:21:04 +0100547 this.histories = database.collection<HistorySchema>("history");
pineafan4edb7762022-06-26 19:21:04 +0100548 }
549
Skyler Grey75ea9172022-08-06 10:22:23 +0100550 async create(
551 type: string,
552 guild: string,
553 user: Discord.User,
554 moderator: Discord.User | null,
555 reason: string | null,
pineafan3a02ea32022-08-11 21:35:04 +0100556 before?: string | null,
557 after?: string | null,
558 amount?: string | null
Skyler Grey75ea9172022-08-06 10:22:23 +0100559 ) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500560 // console.log("History create");
Skyler Greyda16adf2023-03-05 10:22:12 +0000561 await this.histories.insertOne(
562 {
563 type: type,
564 guild: guild,
565 user: user.id,
566 moderator: moderator ? moderator.id : null,
567 reason: reason,
568 occurredAt: new Date(),
569 before: before ?? null,
570 after: after ?? null,
571 amount: amount ?? null
572 },
573 collectionOptions
574 );
pineafan4edb7762022-06-26 19:21:04 +0100575 }
576
577 async read(guild: string, user: string, year: number) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500578 // console.log("History read");
Skyler Grey75ea9172022-08-06 10:22:23 +0100579 const entry = (await this.histories
580 .find({
581 guild: guild,
582 user: user,
583 occurredAt: {
584 $gte: new Date(year - 1, 11, 31, 23, 59, 59),
585 $lt: new Date(year + 1, 0, 1, 0, 0, 0)
586 }
587 })
588 .toArray()) as HistorySchema[];
pineafan4edb7762022-06-26 19:21:04 +0100589 return entry;
590 }
pineafane23c4ec2022-07-27 21:56:27 +0100591
592 async delete(guild: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500593 // console.log("History delete");
pineafane23c4ec2022-07-27 21:56:27 +0100594 await this.histories.deleteMany({ guild: guild });
595 }
pineafan4edb7762022-06-26 19:21:04 +0100596}
597
TheCodedProfb5e9d552023-01-29 15:43:26 -0500598interface ScanCacheSchema {
599 addedAt: Date;
600 hash: string;
Skyler Grey14432712023-03-07 23:40:50 +0000601 nsfw?: boolean;
602 malware?: boolean;
603 bad_link?: boolean;
Skyler Greyd1157312023-03-08 10:07:38 +0000604 tags?: string[];
TheCodedProfb5e9d552023-01-29 15:43:26 -0500605}
606
607export class ScanCache {
608 scanCache: Collection<ScanCacheSchema>;
609
610 constructor() {
611 this.scanCache = database.collection<ScanCacheSchema>("scanCache");
612 }
613
614 async read(hash: string) {
615 return await this.scanCache.findOne({ hash: hash });
616 }
617
Skyler Grey14432712023-03-07 23:40:50 +0000618 async write(hash: string, type: "nsfw" | "malware" | "bad_link", data: boolean, tags?: string[]) {
Skyler Greycf89d4c2023-03-08 00:19:33 +0000619 await this.scanCache.updateOne(
620 { hash: hash },
Skyler Greyd1157312023-03-08 10:07:38 +0000621 {
622 $set: (() => {
623 switch (type) {
624 case "nsfw": {
625 return { nsfw: data, addedAt: new Date() };
626 }
627 case "malware": {
628 return { malware: data, addedAt: new Date() };
629 }
630 case "bad_link": {
631 return { bad_link: data, tags: tags ?? [], addedAt: new Date() };
632 }
633 default: {
634 throw new Error("Invalid type");
635 }
636 }
637 })()
638 // No you can't just do { [type]: data }, yes it's a typescript error, no I don't know how to fix it
639 // cleanly, yes it would be marginally more elegant, no it's not essential, yes I'd be happy to review
640 // PRs that did improve this snippet
641 },
Skyler Greycf89d4c2023-03-08 00:19:33 +0000642 Object.assign({ upsert: true }, collectionOptions)
Skyler Greyda16adf2023-03-05 10:22:12 +0000643 );
TheCodedProfb5e9d552023-01-29 15:43:26 -0500644 }
645
646 async cleanup() {
TheCodedProff8ef7942023-03-03 15:32:32 -0500647 // console.log("ScanCache cleanup");
Skyler Greyda16adf2023-03-05 10:22:12 +0000648 await this.scanCache.deleteMany({
649 addedAt: { $lt: new Date(Date.now() - 1000 * 60 * 60 * 24 * 31) },
650 hash: { $not$text: "http" }
651 });
TheCodedProfb5e9d552023-01-29 15:43:26 -0500652 }
653}
654
PineaFan538d3752023-01-12 21:48:23 +0000655export class PerformanceTest {
656 performanceData: Collection<PerformanceDataSchema>;
657
658 constructor() {
659 this.performanceData = database.collection<PerformanceDataSchema>("performance");
660 }
661
662 async record(data: PerformanceDataSchema) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500663 // console.log("PerformanceTest record");
PineaFan538d3752023-01-12 21:48:23 +0000664 data.timestamp = new Date();
TheCodedProffaae5332023-03-01 18:16:05 -0500665 await this.performanceData.insertOne(data, collectionOptions);
PineaFan538d3752023-01-12 21:48:23 +0000666 }
667 async read() {
TheCodedProff8ef7942023-03-03 15:32:32 -0500668 // console.log("PerformanceTest read");
PineaFan538d3752023-01-12 21:48:23 +0000669 return await this.performanceData.find({}).toArray();
670 }
671}
672
673export interface PerformanceDataSchema {
674 timestamp?: Date;
675 discord: number;
676 databaseRead: number;
677 resources: {
678 cpu: number;
679 memory: number;
680 temperature: number;
Skyler Greyda16adf2023-03-05 10:22:12 +0000681 };
PineaFan538d3752023-01-12 21:48:23 +0000682}
683
pineafan4edb7762022-06-26 19:21:04 +0100684export class ModNotes {
685 modNotes: Collection<ModNoteSchema>;
pineafan4edb7762022-06-26 19:21:04 +0100686
pineafan3a02ea32022-08-11 21:35:04 +0100687 constructor() {
pineafan4edb7762022-06-26 19:21:04 +0100688 this.modNotes = database.collection<ModNoteSchema>("modNotes");
pineafan4edb7762022-06-26 19:21:04 +0100689 }
690
691 async create(guild: string, user: string, note: string | null) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500692 // console.log("ModNotes create");
Skyler Grey11236ba2022-08-08 21:13:33 +0100693 await this.modNotes.updateOne({ guild: guild, user: user }, { $set: { note: note } }, { upsert: true });
pineafan4edb7762022-06-26 19:21:04 +0100694 }
695
696 async read(guild: string, user: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500697 // console.log("ModNotes read");
pineafan63fc5e22022-08-04 22:04:10 +0100698 const entry = await this.modNotes.findOne({ guild: guild, user: user });
pineafan4edb7762022-06-26 19:21:04 +0100699 return entry?.note ?? null;
700 }
TheCodedProf267563a2023-01-21 17:00:57 -0500701
702 async delete(guild: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500703 // console.log("ModNotes delete");
TheCodedProf267563a2023-01-21 17:00:57 -0500704 await this.modNotes.deleteMany({ guild: guild });
705 }
pineafan4edb7762022-06-26 19:21:04 +0100706}
707
pineafan73a7c4a2022-07-24 10:38:04 +0100708export class Premium {
709 premium: Collection<PremiumSchema>;
Skyler Greyda16adf2023-03-05 10:22:12 +0000710 cache: Map<string, [boolean, string, number, boolean, Date]>; // Date indicates the time one hour after it was created
711 cacheTimeout = 1000 * 60 * 60; // 1 hour
pineafan4edb7762022-06-26 19:21:04 +0100712
pineafan3a02ea32022-08-11 21:35:04 +0100713 constructor() {
pineafan73a7c4a2022-07-24 10:38:04 +0100714 this.premium = database.collection<PremiumSchema>("premium");
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500715 this.cache = new Map<string, [boolean, string, number, boolean, Date]>();
pineafan4edb7762022-06-26 19:21:04 +0100716 }
717
TheCodedProf633866f2023-02-03 17:06:00 -0500718 async updateUser(user: string, level: number) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500719 // console.log("Premium updateUser");
Skyler Greyda16adf2023-03-05 10:22:12 +0000720 if (!(await this.userExists(user))) await this.createUser(user, level);
TheCodedProf633866f2023-02-03 17:06:00 -0500721 await this.premium.updateOne({ user: user }, { $set: { level: level } }, { upsert: true });
722 }
723
724 async userExists(user: string): Promise<boolean> {
TheCodedProff8ef7942023-03-03 15:32:32 -0500725 // console.log("Premium userExists");
TheCodedProf633866f2023-02-03 17:06:00 -0500726 const entry = await this.premium.findOne({ user: user });
727 return entry ? true : false;
728 }
TheCodedProf633866f2023-02-03 17:06:00 -0500729 async createUser(user: string, level: number) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500730 // console.log("Premium createUser");
TheCodedProffaae5332023-03-01 18:16:05 -0500731 await this.premium.insertOne({ user: user, appliesTo: [], level: level }, collectionOptions);
TheCodedProf633866f2023-02-03 17:06:00 -0500732 }
733
TheCodedProfaa3fe992023-02-25 21:53:09 -0500734 async hasPremium(guild: string): Promise<[boolean, string, number, boolean] | null> {
TheCodedProff8ef7942023-03-03 15:32:32 -0500735 // console.log("Premium hasPremium");
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500736 // [Has premium, user giving premium, level, is mod: if given automatically]
737 const cached = this.cache.get(guild);
738 if (cached && cached[4].getTime() < Date.now()) return [cached[0], cached[1], cached[2], cached[3]];
TheCodedProf94ff6de2023-02-22 17:47:26 -0500739 const entries = await this.premium.find({}).toArray();
Skyler Greyda16adf2023-03-05 10:22:12 +0000740 const members = (await client.guilds.fetch(guild)).members.cache;
741 for (const { user } of entries) {
TheCodedProf94ff6de2023-02-22 17:47:26 -0500742 const member = members.get(user);
Skyler Greyda16adf2023-03-05 10:22:12 +0000743 if (member) {
744 //TODO: Notify user if they've given premium to a server that has since gotten premium via a mod.
TheCodedProf94ff6de2023-02-22 17:47:26 -0500745 const modPerms = //TODO: Create list in config for perms
Skyler Greyda16adf2023-03-05 10:22:12 +0000746 member.permissions.has("Administrator") ||
747 member.permissions.has("ManageChannels") ||
748 member.permissions.has("ManageRoles") ||
749 member.permissions.has("ManageEmojisAndStickers") ||
750 member.permissions.has("ManageWebhooks") ||
751 member.permissions.has("ManageGuild") ||
752 member.permissions.has("KickMembers") ||
753 member.permissions.has("BanMembers") ||
754 member.permissions.has("ManageEvents") ||
755 member.permissions.has("ManageMessages") ||
756 member.permissions.has("ManageThreads");
757 const entry = entries.find((e) => e.user === member.id);
758 if (entry && entry.level === 3 && modPerms) {
759 this.cache.set(guild, [
760 true,
761 member.id,
762 entry.level,
763 true,
764 new Date(Date.now() + this.cacheTimeout)
765 ]);
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500766 return [true, member.id, entry.level, true];
767 }
TheCodedProf94ff6de2023-02-22 17:47:26 -0500768 }
769 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100770 const entry = await this.premium.findOne({
TheCodedProf94ff6de2023-02-22 17:47:26 -0500771 appliesTo: {
772 $elemMatch: {
773 $eq: guild
774 }
775 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100776 });
Skyler Greyda16adf2023-03-05 10:22:12 +0000777 this.cache.set(guild, [
778 entry ? true : false,
779 entry?.user ?? "",
780 entry?.level ?? 0,
781 false,
782 new Date(Date.now() + this.cacheTimeout)
783 ]);
TheCodedProfaa3fe992023-02-25 21:53:09 -0500784 return entry ? [true, entry.user, entry.level, false] : null;
TheCodedProf267563a2023-01-21 17:00:57 -0500785 }
786
TheCodedProf633866f2023-02-03 17:06:00 -0500787 async fetchUser(user: string): Promise<PremiumSchema | null> {
TheCodedProff8ef7942023-03-03 15:32:32 -0500788 // console.log("Premium fetchUser");
TheCodedProf267563a2023-01-21 17:00:57 -0500789 const entry = await this.premium.findOne({ user: user });
TheCodedProf633866f2023-02-03 17:06:00 -0500790 if (!entry) return null;
791 return entry;
792 }
793
TheCodedProf94ff6de2023-02-22 17:47:26 -0500794 async checkAllPremium(member?: GuildMember) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500795 // console.log("Premium checkAllPremium");
TheCodedProf633866f2023-02-03 17:06:00 -0500796 const entries = await this.premium.find({}).toArray();
Skyler Greyda16adf2023-03-05 10:22:12 +0000797 if (member) {
798 const entry = entries.find((e) => e.user === member.id);
799 if (entry) {
TheCodedProf94ff6de2023-02-22 17:47:26 -0500800 const expiresAt = entry.expiresAt;
Skyler Greyda16adf2023-03-05 10:22:12 +0000801 if (expiresAt) expiresAt < Date.now() ? await this.premium.deleteOne({ user: member.id }) : null;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500802 }
803 const roles = member.roles;
804 let level = 0;
805 if (roles.cache.has("1066468879309750313")) {
TheCodedProf633866f2023-02-03 17:06:00 -0500806 level = 99;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500807 } else if (roles.cache.has("1066465491713003520")) {
TheCodedProf633866f2023-02-03 17:06:00 -0500808 level = 1;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500809 } else if (roles.cache.has("1066439526496604194")) {
TheCodedProf633866f2023-02-03 17:06:00 -0500810 level = 2;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500811 } else if (roles.cache.has("1066464134322978912")) {
TheCodedProf633866f2023-02-03 17:06:00 -0500812 level = 3;
813 }
TheCodedProf94ff6de2023-02-22 17:47:26 -0500814 await this.updateUser(member.id, level);
TheCodedProf633866f2023-02-03 17:06:00 -0500815 if (level > 0) {
Skyler Greyda16adf2023-03-05 10:22:12 +0000816 await this.premium.updateOne({ user: member.id }, { $unset: { expiresAt: "" } });
TheCodedProf633866f2023-02-03 17:06:00 -0500817 } else {
Skyler Greyda16adf2023-03-05 10:22:12 +0000818 await this.premium.updateOne(
819 { user: member.id },
820 { $set: { expiresAt: Date.now() + 1000 * 60 * 60 * 24 * 3 } }
821 );
TheCodedProf94ff6de2023-02-22 17:47:26 -0500822 }
823 } else {
Skyler Greyda16adf2023-03-05 10:22:12 +0000824 const members = await (await client.guilds.fetch("684492926528651336")).members.fetch();
825 for (const { roles, id } of members.values()) {
826 const entry = entries.find((e) => e.user === id);
827 if (entry) {
TheCodedProf94ff6de2023-02-22 17:47:26 -0500828 const expiresAt = entry.expiresAt;
Skyler Greyda16adf2023-03-05 10:22:12 +0000829 if (expiresAt) expiresAt < Date.now() ? await this.premium.deleteOne({ user: id }) : null;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500830 }
831 let level: number = 0;
832 if (roles.cache.has("1066468879309750313")) {
833 level = 99;
834 } else if (roles.cache.has("1066465491713003520")) {
835 level = 1;
836 } else if (roles.cache.has("1066439526496604194")) {
837 level = 2;
838 } else if (roles.cache.has("1066464134322978912")) {
839 level = 3;
840 }
841 await this.updateUser(id, level);
842 if (level > 0) {
Skyler Greyda16adf2023-03-05 10:22:12 +0000843 await this.premium.updateOne({ user: id }, { $unset: { expiresAt: "" } });
TheCodedProf94ff6de2023-02-22 17:47:26 -0500844 } else {
Skyler Greyda16adf2023-03-05 10:22:12 +0000845 await this.premium.updateOne(
846 { user: id },
847 { $set: { expiresAt: Date.now() + 1000 * 60 * 60 * 24 * 3 } }
848 );
TheCodedProf94ff6de2023-02-22 17:47:26 -0500849 }
TheCodedProf633866f2023-02-03 17:06:00 -0500850 }
851 }
TheCodedProf267563a2023-01-21 17:00:57 -0500852 }
853
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500854 async addPremium(user: string, guild: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500855 // console.log("Premium addPremium");
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500856 const { level } = (await this.fetchUser(user))!;
857 this.cache.set(guild, [true, user, level, false, new Date(Date.now() + this.cacheTimeout)]);
TheCodedProf267563a2023-01-21 17:00:57 -0500858 return this.premium.updateOne({ user: user }, { $addToSet: { appliesTo: guild } }, { upsert: true });
pineafan4edb7762022-06-26 19:21:04 +0100859 }
TheCodedProffc420b72023-01-24 17:14:38 -0500860
TheCodedProf48865eb2023-03-05 15:25:25 -0500861 async removePremium(user: string, guild: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500862 // console.log("Premium removePremium");
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500863 this.cache.set(guild, [false, "", 0, false, new Date(Date.now() + this.cacheTimeout)]);
TheCodedProf48865eb2023-03-05 15:25:25 -0500864 return await this.premium.updateOne({ user: user }, { $pull: { appliesTo: guild } });
TheCodedProffc420b72023-01-24 17:14:38 -0500865 }
pineafan4edb7762022-06-26 19:21:04 +0100866}
867
pineafan1e462ab2023-03-07 21:34:06 +0000868// export class Plugins {}
pineafan6de4da52023-03-07 20:43:44 +0000869
pineafan6fb3e072022-05-20 19:27:23 +0100870export interface GuildConfig {
Skyler Grey75ea9172022-08-06 10:22:23 +0100871 id: string;
872 version: number;
PineaFan100df682023-01-02 13:26:08 +0000873 singleEventNotifications: Record<string, boolean>;
pineafan6fb3e072022-05-20 19:27:23 +0100874 filters: {
875 images: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100876 NSFW: boolean;
877 size: boolean;
878 };
879 malware: boolean;
pineafan6fb3e072022-05-20 19:27:23 +0100880 wordFilter: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100881 enabled: boolean;
pineafan6fb3e072022-05-20 19:27:23 +0100882 words: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100883 strict: string[];
884 loose: string[];
885 };
pineafan6fb3e072022-05-20 19:27:23 +0100886 allowed: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100887 users: string[];
888 roles: string[];
889 channels: string[];
890 };
891 };
pineafan6fb3e072022-05-20 19:27:23 +0100892 invite: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100893 enabled: boolean;
PineaFan538d3752023-01-12 21:48:23 +0000894 allowed: {
895 channels: string[];
896 roles: string[];
897 users: string[];
898 };
Skyler Grey75ea9172022-08-06 10:22:23 +0100899 };
pineafan6fb3e072022-05-20 19:27:23 +0100900 pings: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100901 mass: number;
902 everyone: boolean;
903 roles: boolean;
pineafan6fb3e072022-05-20 19:27:23 +0100904 allowed: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100905 roles: string[];
906 rolesToMention: string[];
907 users: string[];
908 channels: string[];
909 };
910 };
TheCodedProfad0b8202023-02-14 14:27:09 -0500911 clean: {
912 channels: string[];
913 allowed: {
TheCodedProff8ef7942023-03-03 15:32:32 -0500914 users: string[];
TheCodedProfad0b8202023-02-14 14:27:09 -0500915 roles: string[];
Skyler Greyda16adf2023-03-05 10:22:12 +0000916 };
917 };
Skyler Grey75ea9172022-08-06 10:22:23 +0100918 };
TheCodedProfbaee2c12023-02-18 16:11:06 -0500919 autoPublish: {
920 enabled: boolean;
921 channels: string[];
Skyler Greyda16adf2023-03-05 10:22:12 +0000922 };
pineafan6fb3e072022-05-20 19:27:23 +0100923 welcome: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100924 enabled: boolean;
Skyler Grey75ea9172022-08-06 10:22:23 +0100925 role: string | null;
926 ping: string | null;
927 channel: string | null;
928 message: string | null;
929 };
930 stats: Record<string, { name: string; enabled: boolean }>;
pineafan6fb3e072022-05-20 19:27:23 +0100931 logging: {
932 logs: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100933 enabled: boolean;
934 channel: string | null;
Skyler Greyad002172022-08-16 18:48:26 +0100935 toLog: string;
Skyler Grey75ea9172022-08-06 10:22:23 +0100936 };
pineafan6fb3e072022-05-20 19:27:23 +0100937 staff: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100938 channel: string | null;
939 };
pineafan73a7c4a2022-07-24 10:38:04 +0100940 attachments: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100941 channel: string | null;
942 saved: Record<string, string>;
943 };
944 };
pineafan6fb3e072022-05-20 19:27:23 +0100945 verify: {
PineaFandf4996f2023-01-01 14:20:06 +0000946 enabled: boolean;
Skyler Grey75ea9172022-08-06 10:22:23 +0100947 role: string | null;
948 };
pineafan6fb3e072022-05-20 19:27:23 +0100949 tickets: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100950 enabled: boolean;
951 category: string | null;
Skyler Greyad002172022-08-16 18:48:26 +0100952 types: string;
953 customTypes: string[] | null;
Skyler Grey75ea9172022-08-06 10:22:23 +0100954 useCustom: boolean;
955 supportRole: string | null;
956 maxTickets: number;
957 };
pineafan6fb3e072022-05-20 19:27:23 +0100958 moderation: {
959 mute: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100960 timeout: boolean;
961 role: string | null;
962 text: string | null;
963 link: string | null;
964 };
pineafan6fb3e072022-05-20 19:27:23 +0100965 kick: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100966 text: string | null;
967 link: string | null;
968 };
pineafan6fb3e072022-05-20 19:27:23 +0100969 ban: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100970 text: string | null;
971 link: string | null;
972 };
pineafan6fb3e072022-05-20 19:27:23 +0100973 softban: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100974 text: string | null;
975 link: string | null;
976 };
pineafan6fb3e072022-05-20 19:27:23 +0100977 warn: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100978 text: string | null;
979 link: string | null;
980 };
pineafan6fb3e072022-05-20 19:27:23 +0100981 role: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100982 role: string | null;
TheCodedProfd9636e82023-01-17 22:13:06 -0500983 text: null;
984 link: null;
Skyler Grey75ea9172022-08-06 10:22:23 +0100985 };
PineaFane6ba7882023-01-18 20:41:16 +0000986 nick: {
987 text: string | null;
988 link: string | null;
Skyler Greyda16adf2023-03-05 10:22:12 +0000989 };
Skyler Grey75ea9172022-08-06 10:22:23 +0100990 };
pineafan6fb3e072022-05-20 19:27:23 +0100991 tracks: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100992 name: string;
993 retainPrevious: boolean;
994 nullable: boolean;
995 track: string[];
996 manageableBy: string[];
997 }[];
pineafan6fb3e072022-05-20 19:27:23 +0100998 roleMenu: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100999 enabled: boolean;
1000 allowWebUI: boolean;
pineafan6fb3e072022-05-20 19:27:23 +01001001 options: {
Skyler Grey75ea9172022-08-06 10:22:23 +01001002 name: string;
1003 description: string;
1004 min: number;
1005 max: number;
pineafan6fb3e072022-05-20 19:27:23 +01001006 options: {
Skyler Grey75ea9172022-08-06 10:22:23 +01001007 name: string;
1008 description: string | null;
1009 role: string;
1010 }[];
1011 }[];
1012 };
1013 tags: Record<string, string>;
pineafan63fc5e22022-08-04 22:04:10 +01001014}
pineafan4edb7762022-06-26 19:21:04 +01001015
1016export interface HistorySchema {
Skyler Grey75ea9172022-08-06 10:22:23 +01001017 type: string;
1018 guild: string;
1019 user: string;
1020 moderator: string | null;
pineafan3a02ea32022-08-11 21:35:04 +01001021 reason: string | null;
Skyler Grey75ea9172022-08-06 10:22:23 +01001022 occurredAt: Date;
1023 before: string | null;
1024 after: string | null;
1025 amount: string | null;
pineafan4edb7762022-06-26 19:21:04 +01001026}
1027
1028export interface ModNoteSchema {
Skyler Grey75ea9172022-08-06 10:22:23 +01001029 guild: string;
1030 user: string;
pineafan3a02ea32022-08-11 21:35:04 +01001031 note: string | null;
pineafan4edb7762022-06-26 19:21:04 +01001032}
1033
pineafan73a7c4a2022-07-24 10:38:04 +01001034export interface PremiumSchema {
Skyler Grey75ea9172022-08-06 10:22:23 +01001035 user: string;
1036 level: number;
Skyler Grey75ea9172022-08-06 10:22:23 +01001037 appliesTo: string[];
TheCodedProf633866f2023-02-03 17:06:00 -05001038 expiresAt?: number;
Skyler Grey75ea9172022-08-06 10:22:23 +01001039}