blob: c46a39d9ac7e3c2f0c5deb155dab7ebb09b68dc4 [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
TheCodedProffaae5332023-03-01 18:16:05 -050017const username = encodeURIComponent(config.mongoOptions.username);
18const password = encodeURIComponent(config.mongoOptions.password);
Samuel Shuertd66098b2023-03-04 14:05:26 -050019
Skyler Greyda16adf2023-03-05 10:22:12 +000020const mongoClient = new MongoClient(
21 username
22 ? `mongodb://${username}:${password}@${config.mongoOptions.host}?authMechanism=DEFAULT`
23 : `mongodb://${config.mongoOptions.host}`,
24 { authSource: config.mongoOptions.authSource }
25);
pineafan63fc5e22022-08-04 22:04:10 +010026await mongoClient.connect();
TheCodedProf8d577fa2023-03-01 13:06:40 -050027const database = mongoClient.db();
pineafan6fb3e072022-05-20 19:27:23 +010028
TheCodedProf78b90332023-03-04 14:02:21 -050029const collectionOptions = { authdb: config.mongoOptions.authSource, w: "majority" };
TheCodedProf75c51be2023-03-03 17:18:18 -050030const getIV = () => crypto.randomBytes(16);
TheCodedProffaae5332023-03-01 18:16:05 -050031
pineafan4edb7762022-06-26 19:21:04 +010032export class Guilds {
pineafan6fb3e072022-05-20 19:27:23 +010033 guilds: Collection<GuildConfig>;
TheCodedProf8a2d7cd2023-03-05 14:53:59 -050034 oldGuilds: Collection<GuildConfig>;
TheCodedProff8ef7942023-03-03 15:32:32 -050035 defaultData: GuildConfig;
pineafan63fc5e22022-08-04 22:04:10 +010036
37 constructor() {
pineafan4edb7762022-06-26 19:21:04 +010038 this.guilds = database.collection<GuildConfig>("guilds");
TheCodedProff8ef7942023-03-03 15:32:32 -050039 this.defaultData = defaultData;
TheCodedProf8a2d7cd2023-03-05 14:53:59 -050040 this.oldGuilds = database.collection<GuildConfig>("oldGuilds");
41 }
42
43 async readOld(guild: string): Promise<Partial<GuildConfig>> {
44 // console.log("Guild read")
45 const entry = await this.oldGuilds.findOne({ id: guild });
46 return entry ?? {};
pineafan63fc5e22022-08-04 22:04:10 +010047 }
48
TheCodedProfb7a7b992023-03-05 16:11:59 -050049 async updateAllGuilds() {
50 const guilds = await this.guilds.find().toArray();
51 for (const guild of guilds) {
52 let guildObj;
53 try {
54 guildObj = await client.guilds.fetch(guild.id);
55 } catch (e) {
56 guildObj = null;
57 }
58 if(!guildObj) await this.delete(guild.id);
59 }
60 }
61
Skyler Greyad002172022-08-16 18:48:26 +010062 async read(guild: string): Promise<GuildConfig> {
TheCodedProff8ef7942023-03-03 15:32:32 -050063 // console.log("Guild read")
pineafan63fc5e22022-08-04 22:04:10 +010064 const entry = await this.guilds.findOne({ id: guild });
TheCodedProf9f4cf9f2023-03-04 14:18:19 -050065 const data = _.cloneDeep(this.defaultData);
TheCodedProff8ef7942023-03-03 15:32:32 -050066 return _.merge(data, entry ?? {});
pineafan6fb3e072022-05-20 19:27:23 +010067 }
68
Skyler Grey11236ba2022-08-08 21:13:33 +010069 async write(guild: string, set: object | null, unset: string[] | string = []) {
TheCodedProff8ef7942023-03-03 15:32:32 -050070 // console.log("Guild write")
pineafan63fc5e22022-08-04 22:04:10 +010071 // eslint-disable-next-line @typescript-eslint/no-explicit-any
72 const uo: Record<string, any> = {};
73 if (!Array.isArray(unset)) unset = [unset];
74 for (const key of unset) {
pineafan0bc04162022-07-25 17:22:26 +010075 uo[key] = null;
pineafan6702cef2022-06-13 17:52:37 +010076 }
Skyler Grey75ea9172022-08-06 10:22:23 +010077 const out = { $set: {}, $unset: {} };
78 if (set) out.$set = set;
79 if (unset.length) out.$unset = uo;
pineafan0bc04162022-07-25 17:22:26 +010080 await this.guilds.updateOne({ id: guild }, out, { upsert: true });
pineafan6702cef2022-06-13 17:52:37 +010081 }
82
pineafan63fc5e22022-08-04 22:04:10 +010083 // eslint-disable-next-line @typescript-eslint/no-explicit-any
pineafan6702cef2022-06-13 17:52:37 +010084 async append(guild: string, key: string, value: any) {
TheCodedProff8ef7942023-03-03 15:32:32 -050085 // console.log("Guild append")
pineafan6702cef2022-06-13 17:52:37 +010086 if (Array.isArray(value)) {
Skyler Grey75ea9172022-08-06 10:22:23 +010087 await this.guilds.updateOne(
88 { id: guild },
89 {
90 $addToSet: { [key]: { $each: value } }
91 },
92 { upsert: true }
93 );
pineafan6702cef2022-06-13 17:52:37 +010094 } else {
Skyler Grey75ea9172022-08-06 10:22:23 +010095 await this.guilds.updateOne(
96 { id: guild },
97 {
98 $addToSet: { [key]: value }
99 },
100 { upsert: true }
101 );
pineafan6702cef2022-06-13 17:52:37 +0100102 }
103 }
104
Skyler Grey75ea9172022-08-06 10:22:23 +0100105 async remove(
106 guild: string,
107 key: string,
Skyler Greyc634e2b2022-08-06 17:50:48 +0100108 // eslint-disable-next-line @typescript-eslint/no-explicit-any
Skyler Grey75ea9172022-08-06 10:22:23 +0100109 value: any,
110 innerKey?: string | null
111 ) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500112 // console.log("Guild remove")
pineafan02ba0232022-07-24 22:16:15 +0100113 if (innerKey) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100114 await this.guilds.updateOne(
115 { id: guild },
116 {
117 $pull: { [key]: { [innerKey]: { $eq: value } } }
118 },
119 { upsert: true }
120 );
pineafan0bc04162022-07-25 17:22:26 +0100121 } else if (Array.isArray(value)) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100122 await this.guilds.updateOne(
123 { id: guild },
124 {
125 $pullAll: { [key]: value }
126 },
127 { upsert: true }
128 );
pineafan6702cef2022-06-13 17:52:37 +0100129 } else {
Skyler Grey75ea9172022-08-06 10:22:23 +0100130 await this.guilds.updateOne(
131 { id: guild },
132 {
133 $pullAll: { [key]: [value] }
134 },
135 { upsert: true }
136 );
pineafan6702cef2022-06-13 17:52:37 +0100137 }
pineafan6fb3e072022-05-20 19:27:23 +0100138 }
pineafane23c4ec2022-07-27 21:56:27 +0100139
140 async delete(guild: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500141 // console.log("Guild delete")
pineafane23c4ec2022-07-27 21:56:27 +0100142 await this.guilds.deleteOne({ id: guild });
143 }
pineafan6fb3e072022-05-20 19:27:23 +0100144}
145
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500146interface TranscriptEmbed {
147 title?: string;
148 description?: string;
149 fields?: {
150 name: string;
151 value: string;
152 inline: boolean;
153 }[];
154 footer?: {
155 text: string;
156 iconURL?: string;
157 };
TheCodedProffaae5332023-03-01 18:16:05 -0500158 color?: number;
159 timestamp?: string;
160 author?: {
161 name: string;
162 iconURL?: string;
163 url?: string;
164 };
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500165}
166
167interface TranscriptComponent {
168 type: number;
169 style?: ButtonStyle;
170 label?: string;
171 description?: string;
172 placeholder?: string;
173 emojiURL?: string;
174}
175
176interface TranscriptAuthor {
177 username: string;
178 discriminator: number;
179 nickname?: string;
180 id: string;
181 iconURL?: string;
182 topRole: {
183 color: number;
184 badgeURL?: string;
TheCodedProf088b1b22023-02-28 17:31:11 -0500185 };
186 bot: boolean;
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500187}
188
189interface TranscriptAttachment {
190 url: string;
191 filename: string;
192 size: number;
193 log?: string;
194}
195
196interface TranscriptMessage {
197 id: string;
198 author: TranscriptAuthor;
199 content?: string;
200 embeds?: TranscriptEmbed[];
201 components?: TranscriptComponent[][];
202 editedTimestamp?: number;
203 createdTimestamp: number;
204 flags?: string[];
205 attachments?: TranscriptAttachment[];
206 stickerURLs?: string[];
Skyler Greyda16adf2023-03-05 10:22:12 +0000207 referencedMessage?: string | [string, string, string]; // the message id, the channel id, the guild id
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500208}
209
210interface TranscriptSchema {
211 code: string;
212 for: TranscriptAuthor;
Skyler Greyda16adf2023-03-05 10:22:12 +0000213 type: "ticket" | "purge";
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500214 guild: string;
215 channel: string;
216 messages: TranscriptMessage[];
217 createdTimestamp: number;
218 createdBy: TranscriptAuthor;
219}
220
Skyler Greyda16adf2023-03-05 10:22:12 +0000221interface findDocSchema {
222 channelID: string;
223 messageID: string;
224 transcript: string;
225}
TheCodedProf003160f2023-03-04 17:09:40 -0500226
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500227export class Transcript {
228 transcripts: Collection<TranscriptSchema>;
TheCodedProf003160f2023-03-04 17:09:40 -0500229 messageToTranscript: Collection<findDocSchema>;
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500230
231 constructor() {
232 this.transcripts = database.collection<TranscriptSchema>("transcripts");
TheCodedProf003160f2023-03-04 17:09:40 -0500233 this.messageToTranscript = database.collection<findDocSchema>("messageToTranscript");
234 }
235
236 async upload(data: findDocSchema) {
237 // console.log("Transcript upload")
238 await this.messageToTranscript.insertOne(data);
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500239 }
240
241 async create(transcript: Omit<TranscriptSchema, "code">) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500242 // console.log("Transcript create")
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500243 let code;
244 do {
TheCodedProf088b1b22023-02-28 17:31:11 -0500245 code = crypto.randomBytes(64).toString("base64").replace(/=/g, "").replace(/\//g, "_").replace(/\+/g, "-");
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500246 } while (await this.transcripts.findOne({ code: code }));
Skyler Greyda16adf2023-03-05 10:22:12 +0000247 const key = crypto
248 .randomBytes(32 ** 2)
249 .toString("base64")
250 .replace(/=/g, "")
251 .replace(/\//g, "_")
252 .replace(/\+/g, "-")
253 .substring(0, 32);
Skyler Greya0c70242023-03-06 09:56:21 +0000254 const iv = getIV().toString("base64").substring(0, 16).replace(/=/g, "").replace(/\//g, "_").replace(/\+/g, "-");
255 console.log(iv);
Skyler Greyda16adf2023-03-05 10:22:12 +0000256 for (const message of transcript.messages) {
257 if (message.content) {
TheCodedProf75c51be2023-03-03 17:18:18 -0500258 const encCipher = crypto.createCipheriv("AES-256-CBC", key, iv);
259 message.content = encCipher.update(message.content, "utf8", "base64") + encCipher.final("base64");
260 }
261 }
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500262
TheCodedProffaae5332023-03-01 18:16:05 -0500263 const doc = await this.transcripts.insertOne(Object.assign(transcript, { code: code }), collectionOptions);
Skyler Greyda16adf2023-03-05 10:22:12 +0000264 if (doc.acknowledged) {
265 client.database.eventScheduler.schedule(
266 "deleteTranscript",
267 (Date.now() + 1000 * 60 * 60 * 24 * 7).toString(),
268 { guild: transcript.guild, code: code, iv: iv, key: key }
269 );
TheCodedProf003160f2023-03-04 17:09:40 -0500270 return [code, key, iv];
Skyler Greyda16adf2023-03-05 10:22:12 +0000271 } else return [null, null, null];
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500272 }
273
TheCodedProf003160f2023-03-04 17:09:40 -0500274 async delete(code: string) {
275 // console.log("Transcript delete")
276 await this.transcripts.deleteOne({ code: code });
TheCodedProf75c51be2023-03-03 17:18:18 -0500277 }
278
279 async deleteAll(guild: string) {
280 // console.log("Transcript delete")
281 const filteredDocs = await this.transcripts.find({ guild: guild }).toArray();
282 for (const doc of filteredDocs) {
283 await this.transcripts.deleteOne({ code: doc.code });
284 }
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500285 }
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500286
TheCodedProf003160f2023-03-04 17:09:40 -0500287 async readEncrypted(code: string) {
288 // console.log("Transcript read")
289 let doc: TranscriptSchema | null = await this.transcripts.findOne({ code: code });
290 let findDoc: findDocSchema | null = null;
Skyler Greyda16adf2023-03-05 10:22:12 +0000291 if (!doc) findDoc = await this.messageToTranscript.findOne({ transcript: code });
292 if (findDoc) {
293 const message = await (
294 client.channels.cache.get(findDoc.channelID) as Discord.TextBasedChannel | null
295 )?.messages.fetch(findDoc.messageID);
296 if (!message) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500297 const attachment = message.attachments.first();
Skyler Greyda16adf2023-03-05 10:22:12 +0000298 if (!attachment) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500299 const transcript = (await fetch(attachment.url)).body;
Skyler Greyda16adf2023-03-05 10:22:12 +0000300 if (!transcript) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500301 const reader = transcript.getReader();
302 let data: Uint8Array | null = null;
303 let allPacketsReceived = false;
304 while (!allPacketsReceived) {
305 const { value, done } = await reader.read();
Skyler Greyda16adf2023-03-05 10:22:12 +0000306 if (done) {
307 allPacketsReceived = true;
308 continue;
309 }
310 if (!data) {
TheCodedProf003160f2023-03-04 17:09:40 -0500311 data = value;
312 } else {
313 data = new Uint8Array(Buffer.concat([data, value]));
314 }
315 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000316 if (!data) return null;
Skyler Greycf771402023-03-05 07:06:37 +0000317 doc = JSON.parse(Buffer.from(data).toString()) as TranscriptSchema;
TheCodedProf003160f2023-03-04 17:09:40 -0500318 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000319 if (!doc) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500320 return doc;
321 }
322
323 async read(code: string, key: string, iv: string) {
Skyler Greya0c70242023-03-06 09:56:21 +0000324 console.log("Transcript read")
TheCodedProf003160f2023-03-04 17:09:40 -0500325 let doc: TranscriptSchema | null = await this.transcripts.findOne({ code: code });
326 let findDoc: findDocSchema | null = null;
Skyler Greya0c70242023-03-06 09:56:21 +0000327 console.log(doc)
Skyler Greyda16adf2023-03-05 10:22:12 +0000328 if (!doc) findDoc = await this.messageToTranscript.findOne({ transcript: code });
329 if (findDoc) {
330 const message = await (
331 client.channels.cache.get(findDoc.channelID) as Discord.TextBasedChannel | null
332 )?.messages.fetch(findDoc.messageID);
333 if (!message) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500334 const attachment = message.attachments.first();
Skyler Greyda16adf2023-03-05 10:22:12 +0000335 if (!attachment) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500336 const transcript = (await fetch(attachment.url)).body;
Skyler Greyda16adf2023-03-05 10:22:12 +0000337 if (!transcript) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500338 const reader = transcript.getReader();
339 let data: Uint8Array | null = null;
340 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, no-constant-condition
Skyler Greyda16adf2023-03-05 10:22:12 +0000341 while (true) {
TheCodedProf003160f2023-03-04 17:09:40 -0500342 const { value, done } = await reader.read();
343 if (done) break;
Skyler Greyda16adf2023-03-05 10:22:12 +0000344 if (!data) {
TheCodedProf003160f2023-03-04 17:09:40 -0500345 data = value;
346 } else {
347 data = new Uint8Array(Buffer.concat([data, value]));
348 }
349 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000350 if (!data) return null;
Skyler Greycf771402023-03-05 07:06:37 +0000351 doc = JSON.parse(Buffer.from(data).toString()) as TranscriptSchema;
TheCodedProf003160f2023-03-04 17:09:40 -0500352 }
Skyler Greya0c70242023-03-06 09:56:21 +0000353 console.log(doc)
Skyler Greyda16adf2023-03-05 10:22:12 +0000354 if (!doc) return null;
355 for (const message of doc.messages) {
356 if (message.content) {
TheCodedProf003160f2023-03-04 17:09:40 -0500357 const decCipher = crypto.createDecipheriv("AES-256-CBC", key, iv);
358 message.content = decCipher.update(message.content, "base64", "utf8") + decCipher.final("utf8");
359 }
360 }
361 return doc;
362 }
363
Skyler Greyda16adf2023-03-05 10:22:12 +0000364 async createTranscript(
365 messages: Message[],
366 interaction: MessageComponentInteraction | CommandInteraction,
367 member: GuildMember
368 ) {
369 const interactionMember = await interaction.guild?.members.fetch(interaction.user.id);
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500370 const newOut: Omit<TranscriptSchema, "code"> = {
371 type: "ticket",
372 for: {
373 username: member!.user.username,
374 discriminator: parseInt(member!.user.discriminator),
375 id: member!.user.id,
376 topRole: {
377 color: member!.roles.highest.color
TheCodedProf088b1b22023-02-28 17:31:11 -0500378 },
Skyler Greyda16adf2023-03-05 10:22:12 +0000379 iconURL: member!.user.displayAvatarURL({ forceStatic: true }),
TheCodedProf088b1b22023-02-28 17:31:11 -0500380 bot: member!.user.bot
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500381 },
382 guild: interaction.guild!.id,
383 channel: interaction.channel!.id,
384 messages: [],
385 createdTimestamp: Date.now(),
386 createdBy: {
387 username: interaction.user.username,
388 discriminator: parseInt(interaction.user.discriminator),
389 id: interaction.user.id,
390 topRole: {
391 color: interactionMember?.roles.highest.color ?? 0x000000
TheCodedProf088b1b22023-02-28 17:31:11 -0500392 },
Skyler Greyda16adf2023-03-05 10:22:12 +0000393 iconURL: interaction.user.displayAvatarURL({ forceStatic: true }),
TheCodedProf088b1b22023-02-28 17:31:11 -0500394 bot: interaction.user.bot
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500395 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000396 };
397 if (member.nickname) newOut.for.nickname = member.nickname;
398 if (interactionMember?.roles.icon) newOut.createdBy.topRole.badgeURL = interactionMember.roles.icon.iconURL()!;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500399 messages.reverse().forEach((message) => {
400 const msg: TranscriptMessage = {
401 id: message.id,
402 author: {
403 username: message.author.username,
404 discriminator: parseInt(message.author.discriminator),
405 id: message.author.id,
406 topRole: {
Skyler Greya0c70242023-03-06 09:56:21 +0000407 color: message.member ? message.member.roles.highest.color : 0x000000
TheCodedProf088b1b22023-02-28 17:31:11 -0500408 },
Skyler Greya0c70242023-03-06 09:56:21 +0000409 iconURL: (message.member?.user || message.author)?.displayAvatarURL({ forceStatic: true }),
410 bot: message.author?.bot || false
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500411 },
412 createdTimestamp: message.createdTimestamp
413 };
Skyler Greyda16adf2023-03-05 10:22:12 +0000414 if (message.member?.nickname) msg.author.nickname = message.member.nickname;
Skyler Greya0c70242023-03-06 09:56:21 +0000415 if (message.member?.roles.icon) msg.author.topRole.badgeURL = message.member!.roles.icon.iconURL()!;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500416 if (message.content) msg.content = message.content;
Skyler Greyda16adf2023-03-05 10:22:12 +0000417 if (message.embeds.length > 0)
418 msg.embeds = message.embeds.map((embed) => {
419 const obj: TranscriptEmbed = {};
420 if (embed.title) obj.title = embed.title;
421 if (embed.description) obj.description = embed.description;
422 if (embed.fields.length > 0)
423 obj.fields = embed.fields.map((field) => {
424 return {
425 name: field.name,
426 value: field.value,
427 inline: field.inline ?? false
428 };
429 });
430 if (embed.color) obj.color = embed.color;
431 if (embed.timestamp) obj.timestamp = embed.timestamp;
432 if (embed.footer)
433 obj.footer = {
434 text: embed.footer.text
435 };
436 if (embed.footer?.iconURL) obj.footer!.iconURL = embed.footer.iconURL;
437 if (embed.author)
438 obj.author = {
439 name: embed.author.name
440 };
441 if (embed.author?.iconURL) obj.author!.iconURL = embed.author.iconURL;
442 if (embed.author?.url) obj.author!.url = embed.author.url;
443 return obj;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500444 });
Skyler Greyda16adf2023-03-05 10:22:12 +0000445 if (message.components.length > 0)
446 msg.components = message.components.map((component) =>
447 component.components.map((child) => {
448 const obj: TranscriptComponent = {
449 type: child.type
450 };
451 if (child.type === ComponentType.Button) {
452 obj.style = child.style;
453 obj.label = child.label ?? "";
454 } else if (child.type > 2) {
455 obj.placeholder = child.placeholder ?? "";
456 }
457 return obj;
458 })
459 );
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500460 if (message.editedTimestamp) msg.editedTimestamp = message.editedTimestamp;
461 msg.flags = message.flags.toArray();
462
Skyler Greyda16adf2023-03-05 10:22:12 +0000463 if (message.stickers.size > 0) msg.stickerURLs = message.stickers.map((sticker) => sticker.url);
464 if (message.reference)
465 msg.referencedMessage = [
466 message.reference.guildId ?? "",
467 message.reference.channelId,
468 message.reference.messageId ?? ""
469 ];
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500470 newOut.messages.push(msg);
471 });
472 return newOut;
473 }
474
475 toHumanReadable(transcript: Omit<TranscriptSchema, "code">): string {
476 let out = "";
477 for (const message of transcript.messages) {
478 if (message.referencedMessage) {
479 if (Array.isArray(message.referencedMessage)) {
480 out += `> [Crosspost From] ${message.referencedMessage[0]} in ${message.referencedMessage[1]} in ${message.referencedMessage[2]}\n`;
Skyler Greyda16adf2023-03-05 10:22:12 +0000481 } else out += `> [Reply To] ${message.referencedMessage}\n`;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500482 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000483 out += `${message.author.nickname ?? message.author.username}#${message.author.discriminator} (${
484 message.author.id
485 }) (${message.id})`;
TheCodedProff8ef7942023-03-03 15:32:32 -0500486 out += ` [${new Date(message.createdTimestamp).toISOString()}]`;
487 if (message.editedTimestamp) out += ` [Edited: ${new Date(message.editedTimestamp).toISOString()}]`;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500488 out += "\n";
489 if (message.content) out += `[Content]\n${message.content}\n\n`;
490 if (message.embeds) {
491 for (const embed of message.embeds) {
492 out += `[Embed]\n`;
493 if (embed.title) out += `| Title: ${embed.title}\n`;
494 if (embed.description) out += `| Description: ${embed.description}\n`;
495 if (embed.fields) {
496 for (const field of embed.fields) {
497 out += `| Field: ${field.name} - ${field.value}\n`;
498 }
499 }
500 if (embed.footer) {
501 out += `|Footer: ${embed.footer.text}\n`;
502 }
503 out += "\n";
504 }
505 }
506 if (message.components) {
507 for (const component of message.components) {
508 out += `[Component]\n`;
509 for (const button of component) {
510 out += `| Button: ${button.label ?? button.description}\n`;
511 }
512 out += "\n";
513 }
514 }
515 if (message.attachments) {
516 for (const attachment of message.attachments) {
517 out += `[Attachment] ${attachment.filename} (${attachment.size} bytes) ${attachment.url}\n`;
518 }
519 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000520 out += "\n\n";
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500521 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000522 return out;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500523 }
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500524}
525
pineafan4edb7762022-06-26 19:21:04 +0100526export class History {
527 histories: Collection<HistorySchema>;
pineafan4edb7762022-06-26 19:21:04 +0100528
pineafan3a02ea32022-08-11 21:35:04 +0100529 constructor() {
pineafan4edb7762022-06-26 19:21:04 +0100530 this.histories = database.collection<HistorySchema>("history");
pineafan4edb7762022-06-26 19:21:04 +0100531 }
532
Skyler Grey75ea9172022-08-06 10:22:23 +0100533 async create(
534 type: string,
535 guild: string,
536 user: Discord.User,
537 moderator: Discord.User | null,
538 reason: string | null,
pineafan3a02ea32022-08-11 21:35:04 +0100539 before?: string | null,
540 after?: string | null,
541 amount?: string | null
Skyler Grey75ea9172022-08-06 10:22:23 +0100542 ) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500543 // console.log("History create");
Skyler Greyda16adf2023-03-05 10:22:12 +0000544 await this.histories.insertOne(
545 {
546 type: type,
547 guild: guild,
548 user: user.id,
549 moderator: moderator ? moderator.id : null,
550 reason: reason,
551 occurredAt: new Date(),
552 before: before ?? null,
553 after: after ?? null,
554 amount: amount ?? null
555 },
556 collectionOptions
557 );
pineafan4edb7762022-06-26 19:21:04 +0100558 }
559
560 async read(guild: string, user: string, year: number) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500561 // console.log("History read");
Skyler Grey75ea9172022-08-06 10:22:23 +0100562 const entry = (await this.histories
563 .find({
564 guild: guild,
565 user: user,
566 occurredAt: {
567 $gte: new Date(year - 1, 11, 31, 23, 59, 59),
568 $lt: new Date(year + 1, 0, 1, 0, 0, 0)
569 }
570 })
571 .toArray()) as HistorySchema[];
pineafan4edb7762022-06-26 19:21:04 +0100572 return entry;
573 }
pineafane23c4ec2022-07-27 21:56:27 +0100574
575 async delete(guild: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500576 // console.log("History delete");
pineafane23c4ec2022-07-27 21:56:27 +0100577 await this.histories.deleteMany({ guild: guild });
578 }
pineafan4edb7762022-06-26 19:21:04 +0100579}
580
TheCodedProfb5e9d552023-01-29 15:43:26 -0500581interface ScanCacheSchema {
582 addedAt: Date;
583 hash: string;
584 data: boolean;
585 tags: string[];
586}
587
588export class ScanCache {
589 scanCache: Collection<ScanCacheSchema>;
590
591 constructor() {
592 this.scanCache = database.collection<ScanCacheSchema>("scanCache");
593 }
594
595 async read(hash: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500596 // console.log("ScanCache read");
TheCodedProfb5e9d552023-01-29 15:43:26 -0500597 return await this.scanCache.findOne({ hash: hash });
598 }
599
600 async write(hash: string, data: boolean, tags?: string[]) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500601 // console.log("ScanCache write");
Skyler Greyda16adf2023-03-05 10:22:12 +0000602 await this.scanCache.insertOne(
603 { hash: hash, data: data, tags: tags ?? [], addedAt: new Date() },
604 collectionOptions
605 );
TheCodedProfb5e9d552023-01-29 15:43:26 -0500606 }
607
608 async cleanup() {
TheCodedProff8ef7942023-03-03 15:32:32 -0500609 // console.log("ScanCache cleanup");
Skyler Greyda16adf2023-03-05 10:22:12 +0000610 await this.scanCache.deleteMany({
611 addedAt: { $lt: new Date(Date.now() - 1000 * 60 * 60 * 24 * 31) },
612 hash: { $not$text: "http" }
613 });
TheCodedProfb5e9d552023-01-29 15:43:26 -0500614 }
615}
616
PineaFan538d3752023-01-12 21:48:23 +0000617export class PerformanceTest {
618 performanceData: Collection<PerformanceDataSchema>;
619
620 constructor() {
621 this.performanceData = database.collection<PerformanceDataSchema>("performance");
622 }
623
624 async record(data: PerformanceDataSchema) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500625 // console.log("PerformanceTest record");
PineaFan538d3752023-01-12 21:48:23 +0000626 data.timestamp = new Date();
TheCodedProffaae5332023-03-01 18:16:05 -0500627 await this.performanceData.insertOne(data, collectionOptions);
PineaFan538d3752023-01-12 21:48:23 +0000628 }
629 async read() {
TheCodedProff8ef7942023-03-03 15:32:32 -0500630 // console.log("PerformanceTest read");
PineaFan538d3752023-01-12 21:48:23 +0000631 return await this.performanceData.find({}).toArray();
632 }
633}
634
635export interface PerformanceDataSchema {
636 timestamp?: Date;
637 discord: number;
638 databaseRead: number;
639 resources: {
640 cpu: number;
641 memory: number;
642 temperature: number;
Skyler Greyda16adf2023-03-05 10:22:12 +0000643 };
PineaFan538d3752023-01-12 21:48:23 +0000644}
645
pineafan4edb7762022-06-26 19:21:04 +0100646export class ModNotes {
647 modNotes: Collection<ModNoteSchema>;
pineafan4edb7762022-06-26 19:21:04 +0100648
pineafan3a02ea32022-08-11 21:35:04 +0100649 constructor() {
pineafan4edb7762022-06-26 19:21:04 +0100650 this.modNotes = database.collection<ModNoteSchema>("modNotes");
pineafan4edb7762022-06-26 19:21:04 +0100651 }
652
653 async create(guild: string, user: string, note: string | null) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500654 // console.log("ModNotes create");
Skyler Grey11236ba2022-08-08 21:13:33 +0100655 await this.modNotes.updateOne({ guild: guild, user: user }, { $set: { note: note } }, { upsert: true });
pineafan4edb7762022-06-26 19:21:04 +0100656 }
657
658 async read(guild: string, user: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500659 // console.log("ModNotes read");
pineafan63fc5e22022-08-04 22:04:10 +0100660 const entry = await this.modNotes.findOne({ guild: guild, user: user });
pineafan4edb7762022-06-26 19:21:04 +0100661 return entry?.note ?? null;
662 }
TheCodedProf267563a2023-01-21 17:00:57 -0500663
664 async delete(guild: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500665 // console.log("ModNotes delete");
TheCodedProf267563a2023-01-21 17:00:57 -0500666 await this.modNotes.deleteMany({ guild: guild });
667 }
pineafan4edb7762022-06-26 19:21:04 +0100668}
669
pineafan73a7c4a2022-07-24 10:38:04 +0100670export class Premium {
671 premium: Collection<PremiumSchema>;
Skyler Greyda16adf2023-03-05 10:22:12 +0000672 cache: Map<string, [boolean, string, number, boolean, Date]>; // Date indicates the time one hour after it was created
673 cacheTimeout = 1000 * 60 * 60; // 1 hour
pineafan4edb7762022-06-26 19:21:04 +0100674
pineafan3a02ea32022-08-11 21:35:04 +0100675 constructor() {
pineafan73a7c4a2022-07-24 10:38:04 +0100676 this.premium = database.collection<PremiumSchema>("premium");
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500677 this.cache = new Map<string, [boolean, string, number, boolean, Date]>();
pineafan4edb7762022-06-26 19:21:04 +0100678 }
679
TheCodedProf633866f2023-02-03 17:06:00 -0500680 async updateUser(user: string, level: number) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500681 // console.log("Premium updateUser");
Skyler Greyda16adf2023-03-05 10:22:12 +0000682 if (!(await this.userExists(user))) await this.createUser(user, level);
TheCodedProf633866f2023-02-03 17:06:00 -0500683 await this.premium.updateOne({ user: user }, { $set: { level: level } }, { upsert: true });
684 }
685
686 async userExists(user: string): Promise<boolean> {
TheCodedProff8ef7942023-03-03 15:32:32 -0500687 // console.log("Premium userExists");
TheCodedProf633866f2023-02-03 17:06:00 -0500688 const entry = await this.premium.findOne({ user: user });
689 return entry ? true : false;
690 }
TheCodedProf633866f2023-02-03 17:06:00 -0500691 async createUser(user: string, level: number) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500692 // console.log("Premium createUser");
TheCodedProffaae5332023-03-01 18:16:05 -0500693 await this.premium.insertOne({ user: user, appliesTo: [], level: level }, collectionOptions);
TheCodedProf633866f2023-02-03 17:06:00 -0500694 }
695
TheCodedProfaa3fe992023-02-25 21:53:09 -0500696 async hasPremium(guild: string): Promise<[boolean, string, number, boolean] | null> {
TheCodedProff8ef7942023-03-03 15:32:32 -0500697 // console.log("Premium hasPremium");
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500698 // [Has premium, user giving premium, level, is mod: if given automatically]
699 const cached = this.cache.get(guild);
700 if (cached && cached[4].getTime() < Date.now()) return [cached[0], cached[1], cached[2], cached[3]];
TheCodedProf94ff6de2023-02-22 17:47:26 -0500701 const entries = await this.premium.find({}).toArray();
Skyler Greyda16adf2023-03-05 10:22:12 +0000702 const members = (await client.guilds.fetch(guild)).members.cache;
703 for (const { user } of entries) {
TheCodedProf94ff6de2023-02-22 17:47:26 -0500704 const member = members.get(user);
Skyler Greyda16adf2023-03-05 10:22:12 +0000705 if (member) {
706 //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 -0500707 const modPerms = //TODO: Create list in config for perms
Skyler Greyda16adf2023-03-05 10:22:12 +0000708 member.permissions.has("Administrator") ||
709 member.permissions.has("ManageChannels") ||
710 member.permissions.has("ManageRoles") ||
711 member.permissions.has("ManageEmojisAndStickers") ||
712 member.permissions.has("ManageWebhooks") ||
713 member.permissions.has("ManageGuild") ||
714 member.permissions.has("KickMembers") ||
715 member.permissions.has("BanMembers") ||
716 member.permissions.has("ManageEvents") ||
717 member.permissions.has("ManageMessages") ||
718 member.permissions.has("ManageThreads");
719 const entry = entries.find((e) => e.user === member.id);
720 if (entry && entry.level === 3 && modPerms) {
721 this.cache.set(guild, [
722 true,
723 member.id,
724 entry.level,
725 true,
726 new Date(Date.now() + this.cacheTimeout)
727 ]);
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500728 return [true, member.id, entry.level, true];
729 }
TheCodedProf94ff6de2023-02-22 17:47:26 -0500730 }
731 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100732 const entry = await this.premium.findOne({
TheCodedProf94ff6de2023-02-22 17:47:26 -0500733 appliesTo: {
734 $elemMatch: {
735 $eq: guild
736 }
737 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100738 });
Skyler Greyda16adf2023-03-05 10:22:12 +0000739 this.cache.set(guild, [
740 entry ? true : false,
741 entry?.user ?? "",
742 entry?.level ?? 0,
743 false,
744 new Date(Date.now() + this.cacheTimeout)
745 ]);
TheCodedProfaa3fe992023-02-25 21:53:09 -0500746 return entry ? [true, entry.user, entry.level, false] : null;
TheCodedProf267563a2023-01-21 17:00:57 -0500747 }
748
TheCodedProf633866f2023-02-03 17:06:00 -0500749 async fetchUser(user: string): Promise<PremiumSchema | null> {
TheCodedProff8ef7942023-03-03 15:32:32 -0500750 // console.log("Premium fetchUser");
TheCodedProf267563a2023-01-21 17:00:57 -0500751 const entry = await this.premium.findOne({ user: user });
TheCodedProf633866f2023-02-03 17:06:00 -0500752 if (!entry) return null;
753 return entry;
754 }
755
TheCodedProf94ff6de2023-02-22 17:47:26 -0500756 async checkAllPremium(member?: GuildMember) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500757 // console.log("Premium checkAllPremium");
TheCodedProf633866f2023-02-03 17:06:00 -0500758 const entries = await this.premium.find({}).toArray();
Skyler Greyda16adf2023-03-05 10:22:12 +0000759 if (member) {
760 const entry = entries.find((e) => e.user === member.id);
761 if (entry) {
TheCodedProf94ff6de2023-02-22 17:47:26 -0500762 const expiresAt = entry.expiresAt;
Skyler Greyda16adf2023-03-05 10:22:12 +0000763 if (expiresAt) expiresAt < Date.now() ? await this.premium.deleteOne({ user: member.id }) : null;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500764 }
765 const roles = member.roles;
766 let level = 0;
767 if (roles.cache.has("1066468879309750313")) {
TheCodedProf633866f2023-02-03 17:06:00 -0500768 level = 99;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500769 } else if (roles.cache.has("1066465491713003520")) {
TheCodedProf633866f2023-02-03 17:06:00 -0500770 level = 1;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500771 } else if (roles.cache.has("1066439526496604194")) {
TheCodedProf633866f2023-02-03 17:06:00 -0500772 level = 2;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500773 } else if (roles.cache.has("1066464134322978912")) {
TheCodedProf633866f2023-02-03 17:06:00 -0500774 level = 3;
775 }
TheCodedProf94ff6de2023-02-22 17:47:26 -0500776 await this.updateUser(member.id, level);
TheCodedProf633866f2023-02-03 17:06:00 -0500777 if (level > 0) {
Skyler Greyda16adf2023-03-05 10:22:12 +0000778 await this.premium.updateOne({ user: member.id }, { $unset: { expiresAt: "" } });
TheCodedProf633866f2023-02-03 17:06:00 -0500779 } else {
Skyler Greyda16adf2023-03-05 10:22:12 +0000780 await this.premium.updateOne(
781 { user: member.id },
782 { $set: { expiresAt: Date.now() + 1000 * 60 * 60 * 24 * 3 } }
783 );
TheCodedProf94ff6de2023-02-22 17:47:26 -0500784 }
785 } else {
Skyler Greyda16adf2023-03-05 10:22:12 +0000786 const members = await (await client.guilds.fetch("684492926528651336")).members.fetch();
787 for (const { roles, id } of members.values()) {
788 const entry = entries.find((e) => e.user === id);
789 if (entry) {
TheCodedProf94ff6de2023-02-22 17:47:26 -0500790 const expiresAt = entry.expiresAt;
Skyler Greyda16adf2023-03-05 10:22:12 +0000791 if (expiresAt) expiresAt < Date.now() ? await this.premium.deleteOne({ user: id }) : null;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500792 }
793 let level: number = 0;
794 if (roles.cache.has("1066468879309750313")) {
795 level = 99;
796 } else if (roles.cache.has("1066465491713003520")) {
797 level = 1;
798 } else if (roles.cache.has("1066439526496604194")) {
799 level = 2;
800 } else if (roles.cache.has("1066464134322978912")) {
801 level = 3;
802 }
803 await this.updateUser(id, level);
804 if (level > 0) {
Skyler Greyda16adf2023-03-05 10:22:12 +0000805 await this.premium.updateOne({ user: id }, { $unset: { expiresAt: "" } });
TheCodedProf94ff6de2023-02-22 17:47:26 -0500806 } else {
Skyler Greyda16adf2023-03-05 10:22:12 +0000807 await this.premium.updateOne(
808 { user: id },
809 { $set: { expiresAt: Date.now() + 1000 * 60 * 60 * 24 * 3 } }
810 );
TheCodedProf94ff6de2023-02-22 17:47:26 -0500811 }
TheCodedProf633866f2023-02-03 17:06:00 -0500812 }
813 }
TheCodedProf267563a2023-01-21 17:00:57 -0500814 }
815
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500816 async addPremium(user: string, guild: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500817 // console.log("Premium addPremium");
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500818 const { level } = (await this.fetchUser(user))!;
819 this.cache.set(guild, [true, user, level, false, new Date(Date.now() + this.cacheTimeout)]);
TheCodedProf267563a2023-01-21 17:00:57 -0500820 return this.premium.updateOne({ user: user }, { $addToSet: { appliesTo: guild } }, { upsert: true });
pineafan4edb7762022-06-26 19:21:04 +0100821 }
TheCodedProffc420b72023-01-24 17:14:38 -0500822
TheCodedProf48865eb2023-03-05 15:25:25 -0500823 async removePremium(user: string, guild: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500824 // console.log("Premium removePremium");
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500825 this.cache.set(guild, [false, "", 0, false, new Date(Date.now() + this.cacheTimeout)]);
TheCodedProf48865eb2023-03-05 15:25:25 -0500826 return await this.premium.updateOne({ user: user }, { $pull: { appliesTo: guild } });
TheCodedProffc420b72023-01-24 17:14:38 -0500827 }
pineafan4edb7762022-06-26 19:21:04 +0100828}
829
pineafan6fb3e072022-05-20 19:27:23 +0100830export interface GuildConfig {
Skyler Grey75ea9172022-08-06 10:22:23 +0100831 id: string;
832 version: number;
PineaFan100df682023-01-02 13:26:08 +0000833 singleEventNotifications: Record<string, boolean>;
pineafan6fb3e072022-05-20 19:27:23 +0100834 filters: {
835 images: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100836 NSFW: boolean;
837 size: boolean;
838 };
839 malware: boolean;
pineafan6fb3e072022-05-20 19:27:23 +0100840 wordFilter: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100841 enabled: boolean;
pineafan6fb3e072022-05-20 19:27:23 +0100842 words: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100843 strict: string[];
844 loose: string[];
845 };
pineafan6fb3e072022-05-20 19:27:23 +0100846 allowed: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100847 users: string[];
848 roles: string[];
849 channels: string[];
850 };
851 };
pineafan6fb3e072022-05-20 19:27:23 +0100852 invite: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100853 enabled: boolean;
PineaFan538d3752023-01-12 21:48:23 +0000854 allowed: {
855 channels: string[];
856 roles: string[];
857 users: string[];
858 };
Skyler Grey75ea9172022-08-06 10:22:23 +0100859 };
pineafan6fb3e072022-05-20 19:27:23 +0100860 pings: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100861 mass: number;
862 everyone: boolean;
863 roles: boolean;
pineafan6fb3e072022-05-20 19:27:23 +0100864 allowed: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100865 roles: string[];
866 rolesToMention: string[];
867 users: string[];
868 channels: string[];
869 };
870 };
TheCodedProfad0b8202023-02-14 14:27:09 -0500871 clean: {
872 channels: string[];
873 allowed: {
TheCodedProff8ef7942023-03-03 15:32:32 -0500874 users: string[];
TheCodedProfad0b8202023-02-14 14:27:09 -0500875 roles: string[];
Skyler Greyda16adf2023-03-05 10:22:12 +0000876 };
877 };
Skyler Grey75ea9172022-08-06 10:22:23 +0100878 };
TheCodedProfbaee2c12023-02-18 16:11:06 -0500879 autoPublish: {
880 enabled: boolean;
881 channels: string[];
Skyler Greyda16adf2023-03-05 10:22:12 +0000882 };
pineafan6fb3e072022-05-20 19:27:23 +0100883 welcome: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100884 enabled: boolean;
Skyler Grey75ea9172022-08-06 10:22:23 +0100885 role: string | null;
886 ping: string | null;
887 channel: string | null;
888 message: string | null;
889 };
890 stats: Record<string, { name: string; enabled: boolean }>;
pineafan6fb3e072022-05-20 19:27:23 +0100891 logging: {
892 logs: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100893 enabled: boolean;
894 channel: string | null;
Skyler Greyad002172022-08-16 18:48:26 +0100895 toLog: string;
Skyler Grey75ea9172022-08-06 10:22:23 +0100896 };
pineafan6fb3e072022-05-20 19:27:23 +0100897 staff: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100898 channel: string | null;
899 };
pineafan73a7c4a2022-07-24 10:38:04 +0100900 attachments: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100901 channel: string | null;
902 saved: Record<string, string>;
903 };
904 };
pineafan6fb3e072022-05-20 19:27:23 +0100905 verify: {
PineaFandf4996f2023-01-01 14:20:06 +0000906 enabled: boolean;
Skyler Grey75ea9172022-08-06 10:22:23 +0100907 role: string | null;
908 };
pineafan6fb3e072022-05-20 19:27:23 +0100909 tickets: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100910 enabled: boolean;
911 category: string | null;
Skyler Greyad002172022-08-16 18:48:26 +0100912 types: string;
913 customTypes: string[] | null;
Skyler Grey75ea9172022-08-06 10:22:23 +0100914 useCustom: boolean;
915 supportRole: string | null;
916 maxTickets: number;
917 };
pineafan6fb3e072022-05-20 19:27:23 +0100918 moderation: {
919 mute: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100920 timeout: boolean;
921 role: string | null;
922 text: string | null;
923 link: string | null;
924 };
pineafan6fb3e072022-05-20 19:27:23 +0100925 kick: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100926 text: string | null;
927 link: string | null;
928 };
pineafan6fb3e072022-05-20 19:27:23 +0100929 ban: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100930 text: string | null;
931 link: string | null;
932 };
pineafan6fb3e072022-05-20 19:27:23 +0100933 softban: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100934 text: string | null;
935 link: string | null;
936 };
pineafan6fb3e072022-05-20 19:27:23 +0100937 warn: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100938 text: string | null;
939 link: string | null;
940 };
pineafan6fb3e072022-05-20 19:27:23 +0100941 role: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100942 role: string | null;
TheCodedProfd9636e82023-01-17 22:13:06 -0500943 text: null;
944 link: null;
Skyler Grey75ea9172022-08-06 10:22:23 +0100945 };
PineaFane6ba7882023-01-18 20:41:16 +0000946 nick: {
947 text: string | null;
948 link: string | null;
Skyler Greyda16adf2023-03-05 10:22:12 +0000949 };
Skyler Grey75ea9172022-08-06 10:22:23 +0100950 };
pineafan6fb3e072022-05-20 19:27:23 +0100951 tracks: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100952 name: string;
953 retainPrevious: boolean;
954 nullable: boolean;
955 track: string[];
956 manageableBy: string[];
957 }[];
pineafan6fb3e072022-05-20 19:27:23 +0100958 roleMenu: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100959 enabled: boolean;
960 allowWebUI: boolean;
pineafan6fb3e072022-05-20 19:27:23 +0100961 options: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100962 name: string;
963 description: string;
964 min: number;
965 max: number;
pineafan6fb3e072022-05-20 19:27:23 +0100966 options: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100967 name: string;
968 description: string | null;
969 role: string;
970 }[];
971 }[];
972 };
973 tags: Record<string, string>;
pineafan63fc5e22022-08-04 22:04:10 +0100974}
pineafan4edb7762022-06-26 19:21:04 +0100975
976export interface HistorySchema {
Skyler Grey75ea9172022-08-06 10:22:23 +0100977 type: string;
978 guild: string;
979 user: string;
980 moderator: string | null;
pineafan3a02ea32022-08-11 21:35:04 +0100981 reason: string | null;
Skyler Grey75ea9172022-08-06 10:22:23 +0100982 occurredAt: Date;
983 before: string | null;
984 after: string | null;
985 amount: string | null;
pineafan4edb7762022-06-26 19:21:04 +0100986}
987
988export interface ModNoteSchema {
Skyler Grey75ea9172022-08-06 10:22:23 +0100989 guild: string;
990 user: string;
pineafan3a02ea32022-08-11 21:35:04 +0100991 note: string | null;
pineafan4edb7762022-06-26 19:21:04 +0100992}
993
pineafan73a7c4a2022-07-24 10:38:04 +0100994export interface PremiumSchema {
Skyler Grey75ea9172022-08-06 10:22:23 +0100995 user: string;
996 level: number;
Skyler Grey75ea9172022-08-06 10:22:23 +0100997 appliesTo: string[];
TheCodedProf633866f2023-02-03 17:06:00 -0500998 expiresAt?: number;
Skyler Grey75ea9172022-08-06 10:22:23 +0100999}