blob: 8f37466e7655d7e04a42a92758485bbfd249aaa6 [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);
TheCodedProf75c51be2023-03-03 17:18:18 -0500254 const iv = getIV().toString("base64").replace(/=/g, "").replace(/\//g, "_").replace(/\+/g, "-");
Skyler Greyda16adf2023-03-05 10:22:12 +0000255 for (const message of transcript.messages) {
256 if (message.content) {
TheCodedProf75c51be2023-03-03 17:18:18 -0500257 const encCipher = crypto.createCipheriv("AES-256-CBC", key, iv);
258 message.content = encCipher.update(message.content, "utf8", "base64") + encCipher.final("base64");
259 }
260 }
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500261
TheCodedProffaae5332023-03-01 18:16:05 -0500262 const doc = await this.transcripts.insertOne(Object.assign(transcript, { code: code }), collectionOptions);
Skyler Greyda16adf2023-03-05 10:22:12 +0000263 if (doc.acknowledged) {
264 client.database.eventScheduler.schedule(
265 "deleteTranscript",
266 (Date.now() + 1000 * 60 * 60 * 24 * 7).toString(),
267 { guild: transcript.guild, code: code, iv: iv, key: key }
268 );
TheCodedProf003160f2023-03-04 17:09:40 -0500269 return [code, key, iv];
Skyler Greyda16adf2023-03-05 10:22:12 +0000270 } else return [null, null, null];
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500271 }
272
TheCodedProf003160f2023-03-04 17:09:40 -0500273 async delete(code: string) {
274 // console.log("Transcript delete")
275 await this.transcripts.deleteOne({ code: code });
TheCodedProf75c51be2023-03-03 17:18:18 -0500276 }
277
278 async deleteAll(guild: string) {
279 // console.log("Transcript delete")
280 const filteredDocs = await this.transcripts.find({ guild: guild }).toArray();
281 for (const doc of filteredDocs) {
282 await this.transcripts.deleteOne({ code: doc.code });
283 }
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500284 }
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500285
TheCodedProf003160f2023-03-04 17:09:40 -0500286 async readEncrypted(code: string) {
287 // console.log("Transcript read")
288 let doc: TranscriptSchema | null = await this.transcripts.findOne({ code: code });
289 let findDoc: findDocSchema | null = null;
Skyler Greyda16adf2023-03-05 10:22:12 +0000290 if (!doc) findDoc = await this.messageToTranscript.findOne({ transcript: code });
291 if (findDoc) {
292 const message = await (
293 client.channels.cache.get(findDoc.channelID) as Discord.TextBasedChannel | null
294 )?.messages.fetch(findDoc.messageID);
295 if (!message) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500296 const attachment = message.attachments.first();
Skyler Greyda16adf2023-03-05 10:22:12 +0000297 if (!attachment) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500298 const transcript = (await fetch(attachment.url)).body;
Skyler Greyda16adf2023-03-05 10:22:12 +0000299 if (!transcript) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500300 const reader = transcript.getReader();
301 let data: Uint8Array | null = null;
302 let allPacketsReceived = false;
303 while (!allPacketsReceived) {
304 const { value, done } = await reader.read();
Skyler Greyda16adf2023-03-05 10:22:12 +0000305 if (done) {
306 allPacketsReceived = true;
307 continue;
308 }
309 if (!data) {
TheCodedProf003160f2023-03-04 17:09:40 -0500310 data = value;
311 } else {
312 data = new Uint8Array(Buffer.concat([data, value]));
313 }
314 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000315 if (!data) return null;
Skyler Greycf771402023-03-05 07:06:37 +0000316 doc = JSON.parse(Buffer.from(data).toString()) as TranscriptSchema;
TheCodedProf003160f2023-03-04 17:09:40 -0500317 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000318 if (!doc) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500319 return doc;
320 }
321
322 async read(code: string, key: string, iv: string) {
323 // console.log("Transcript read")
324 let doc: TranscriptSchema | null = await this.transcripts.findOne({ code: code });
325 let findDoc: findDocSchema | null = null;
Skyler Greyda16adf2023-03-05 10:22:12 +0000326 if (!doc) findDoc = await this.messageToTranscript.findOne({ transcript: code });
327 if (findDoc) {
328 const message = await (
329 client.channels.cache.get(findDoc.channelID) as Discord.TextBasedChannel | null
330 )?.messages.fetch(findDoc.messageID);
331 if (!message) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500332 const attachment = message.attachments.first();
Skyler Greyda16adf2023-03-05 10:22:12 +0000333 if (!attachment) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500334 const transcript = (await fetch(attachment.url)).body;
Skyler Greyda16adf2023-03-05 10:22:12 +0000335 if (!transcript) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500336 const reader = transcript.getReader();
337 let data: Uint8Array | null = null;
338 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, no-constant-condition
Skyler Greyda16adf2023-03-05 10:22:12 +0000339 while (true) {
TheCodedProf003160f2023-03-04 17:09:40 -0500340 const { value, done } = await reader.read();
341 if (done) break;
Skyler Greyda16adf2023-03-05 10:22:12 +0000342 if (!data) {
TheCodedProf003160f2023-03-04 17:09:40 -0500343 data = value;
344 } else {
345 data = new Uint8Array(Buffer.concat([data, value]));
346 }
347 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000348 if (!data) return null;
Skyler Greycf771402023-03-05 07:06:37 +0000349 doc = JSON.parse(Buffer.from(data).toString()) as TranscriptSchema;
TheCodedProf003160f2023-03-04 17:09:40 -0500350 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000351 if (!doc) return null;
352 for (const message of doc.messages) {
353 if (message.content) {
TheCodedProf003160f2023-03-04 17:09:40 -0500354 const decCipher = crypto.createDecipheriv("AES-256-CBC", key, iv);
355 message.content = decCipher.update(message.content, "base64", "utf8") + decCipher.final("utf8");
356 }
357 }
358 return doc;
359 }
360
Skyler Greyda16adf2023-03-05 10:22:12 +0000361 async createTranscript(
362 messages: Message[],
363 interaction: MessageComponentInteraction | CommandInteraction,
364 member: GuildMember
365 ) {
366 const interactionMember = await interaction.guild?.members.fetch(interaction.user.id);
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500367 const newOut: Omit<TranscriptSchema, "code"> = {
368 type: "ticket",
369 for: {
370 username: member!.user.username,
371 discriminator: parseInt(member!.user.discriminator),
372 id: member!.user.id,
373 topRole: {
374 color: member!.roles.highest.color
TheCodedProf088b1b22023-02-28 17:31:11 -0500375 },
Skyler Greyda16adf2023-03-05 10:22:12 +0000376 iconURL: member!.user.displayAvatarURL({ forceStatic: true }),
TheCodedProf088b1b22023-02-28 17:31:11 -0500377 bot: member!.user.bot
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500378 },
379 guild: interaction.guild!.id,
380 channel: interaction.channel!.id,
381 messages: [],
382 createdTimestamp: Date.now(),
383 createdBy: {
384 username: interaction.user.username,
385 discriminator: parseInt(interaction.user.discriminator),
386 id: interaction.user.id,
387 topRole: {
388 color: interactionMember?.roles.highest.color ?? 0x000000
TheCodedProf088b1b22023-02-28 17:31:11 -0500389 },
Skyler Greyda16adf2023-03-05 10:22:12 +0000390 iconURL: interaction.user.displayAvatarURL({ forceStatic: true }),
TheCodedProf088b1b22023-02-28 17:31:11 -0500391 bot: interaction.user.bot
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500392 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000393 };
394 if (member.nickname) newOut.for.nickname = member.nickname;
395 if (interactionMember?.roles.icon) newOut.createdBy.topRole.badgeURL = interactionMember.roles.icon.iconURL()!;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500396 messages.reverse().forEach((message) => {
397 const msg: TranscriptMessage = {
398 id: message.id,
399 author: {
400 username: message.author.username,
401 discriminator: parseInt(message.author.discriminator),
402 id: message.author.id,
403 topRole: {
404 color: message.member!.roles.highest.color
TheCodedProf088b1b22023-02-28 17:31:11 -0500405 },
Skyler Greyda16adf2023-03-05 10:22:12 +0000406 iconURL: message.member!.user.displayAvatarURL({ forceStatic: true }),
TheCodedProf088b1b22023-02-28 17:31:11 -0500407 bot: message.author.bot
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500408 },
409 createdTimestamp: message.createdTimestamp
410 };
Skyler Greyda16adf2023-03-05 10:22:12 +0000411 if (message.member?.nickname) msg.author.nickname = message.member.nickname;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500412 if (message.member!.roles.icon) msg.author.topRole.badgeURL = message.member!.roles.icon.iconURL()!;
413 if (message.content) msg.content = message.content;
Skyler Greyda16adf2023-03-05 10:22:12 +0000414 if (message.embeds.length > 0)
415 msg.embeds = message.embeds.map((embed) => {
416 const obj: TranscriptEmbed = {};
417 if (embed.title) obj.title = embed.title;
418 if (embed.description) obj.description = embed.description;
419 if (embed.fields.length > 0)
420 obj.fields = embed.fields.map((field) => {
421 return {
422 name: field.name,
423 value: field.value,
424 inline: field.inline ?? false
425 };
426 });
427 if (embed.color) obj.color = embed.color;
428 if (embed.timestamp) obj.timestamp = embed.timestamp;
429 if (embed.footer)
430 obj.footer = {
431 text: embed.footer.text
432 };
433 if (embed.footer?.iconURL) obj.footer!.iconURL = embed.footer.iconURL;
434 if (embed.author)
435 obj.author = {
436 name: embed.author.name
437 };
438 if (embed.author?.iconURL) obj.author!.iconURL = embed.author.iconURL;
439 if (embed.author?.url) obj.author!.url = embed.author.url;
440 return obj;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500441 });
Skyler Greyda16adf2023-03-05 10:22:12 +0000442 if (message.components.length > 0)
443 msg.components = message.components.map((component) =>
444 component.components.map((child) => {
445 const obj: TranscriptComponent = {
446 type: child.type
447 };
448 if (child.type === ComponentType.Button) {
449 obj.style = child.style;
450 obj.label = child.label ?? "";
451 } else if (child.type > 2) {
452 obj.placeholder = child.placeholder ?? "";
453 }
454 return obj;
455 })
456 );
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500457 if (message.editedTimestamp) msg.editedTimestamp = message.editedTimestamp;
458 msg.flags = message.flags.toArray();
459
Skyler Greyda16adf2023-03-05 10:22:12 +0000460 if (message.stickers.size > 0) msg.stickerURLs = message.stickers.map((sticker) => sticker.url);
461 if (message.reference)
462 msg.referencedMessage = [
463 message.reference.guildId ?? "",
464 message.reference.channelId,
465 message.reference.messageId ?? ""
466 ];
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500467 newOut.messages.push(msg);
468 });
469 return newOut;
470 }
471
472 toHumanReadable(transcript: Omit<TranscriptSchema, "code">): string {
473 let out = "";
474 for (const message of transcript.messages) {
475 if (message.referencedMessage) {
476 if (Array.isArray(message.referencedMessage)) {
477 out += `> [Crosspost From] ${message.referencedMessage[0]} in ${message.referencedMessage[1]} in ${message.referencedMessage[2]}\n`;
Skyler Greyda16adf2023-03-05 10:22:12 +0000478 } else out += `> [Reply To] ${message.referencedMessage}\n`;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500479 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000480 out += `${message.author.nickname ?? message.author.username}#${message.author.discriminator} (${
481 message.author.id
482 }) (${message.id})`;
TheCodedProff8ef7942023-03-03 15:32:32 -0500483 out += ` [${new Date(message.createdTimestamp).toISOString()}]`;
484 if (message.editedTimestamp) out += ` [Edited: ${new Date(message.editedTimestamp).toISOString()}]`;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500485 out += "\n";
486 if (message.content) out += `[Content]\n${message.content}\n\n`;
487 if (message.embeds) {
488 for (const embed of message.embeds) {
489 out += `[Embed]\n`;
490 if (embed.title) out += `| Title: ${embed.title}\n`;
491 if (embed.description) out += `| Description: ${embed.description}\n`;
492 if (embed.fields) {
493 for (const field of embed.fields) {
494 out += `| Field: ${field.name} - ${field.value}\n`;
495 }
496 }
497 if (embed.footer) {
498 out += `|Footer: ${embed.footer.text}\n`;
499 }
500 out += "\n";
501 }
502 }
503 if (message.components) {
504 for (const component of message.components) {
505 out += `[Component]\n`;
506 for (const button of component) {
507 out += `| Button: ${button.label ?? button.description}\n`;
508 }
509 out += "\n";
510 }
511 }
512 if (message.attachments) {
513 for (const attachment of message.attachments) {
514 out += `[Attachment] ${attachment.filename} (${attachment.size} bytes) ${attachment.url}\n`;
515 }
516 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000517 out += "\n\n";
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500518 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000519 return out;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500520 }
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500521}
522
pineafan4edb7762022-06-26 19:21:04 +0100523export class History {
524 histories: Collection<HistorySchema>;
pineafan4edb7762022-06-26 19:21:04 +0100525
pineafan3a02ea32022-08-11 21:35:04 +0100526 constructor() {
pineafan4edb7762022-06-26 19:21:04 +0100527 this.histories = database.collection<HistorySchema>("history");
pineafan4edb7762022-06-26 19:21:04 +0100528 }
529
Skyler Grey75ea9172022-08-06 10:22:23 +0100530 async create(
531 type: string,
532 guild: string,
533 user: Discord.User,
534 moderator: Discord.User | null,
535 reason: string | null,
pineafan3a02ea32022-08-11 21:35:04 +0100536 before?: string | null,
537 after?: string | null,
538 amount?: string | null
Skyler Grey75ea9172022-08-06 10:22:23 +0100539 ) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500540 // console.log("History create");
Skyler Greyda16adf2023-03-05 10:22:12 +0000541 await this.histories.insertOne(
542 {
543 type: type,
544 guild: guild,
545 user: user.id,
546 moderator: moderator ? moderator.id : null,
547 reason: reason,
548 occurredAt: new Date(),
549 before: before ?? null,
550 after: after ?? null,
551 amount: amount ?? null
552 },
553 collectionOptions
554 );
pineafan4edb7762022-06-26 19:21:04 +0100555 }
556
557 async read(guild: string, user: string, year: number) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500558 // console.log("History read");
Skyler Grey75ea9172022-08-06 10:22:23 +0100559 const entry = (await this.histories
560 .find({
561 guild: guild,
562 user: user,
563 occurredAt: {
564 $gte: new Date(year - 1, 11, 31, 23, 59, 59),
565 $lt: new Date(year + 1, 0, 1, 0, 0, 0)
566 }
567 })
568 .toArray()) as HistorySchema[];
pineafan4edb7762022-06-26 19:21:04 +0100569 return entry;
570 }
pineafane23c4ec2022-07-27 21:56:27 +0100571
572 async delete(guild: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500573 // console.log("History delete");
pineafane23c4ec2022-07-27 21:56:27 +0100574 await this.histories.deleteMany({ guild: guild });
575 }
pineafan4edb7762022-06-26 19:21:04 +0100576}
577
TheCodedProfb5e9d552023-01-29 15:43:26 -0500578interface ScanCacheSchema {
579 addedAt: Date;
580 hash: string;
581 data: boolean;
582 tags: string[];
583}
584
585export class ScanCache {
586 scanCache: Collection<ScanCacheSchema>;
587
588 constructor() {
589 this.scanCache = database.collection<ScanCacheSchema>("scanCache");
590 }
591
592 async read(hash: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500593 // console.log("ScanCache read");
TheCodedProfb5e9d552023-01-29 15:43:26 -0500594 return await this.scanCache.findOne({ hash: hash });
595 }
596
597 async write(hash: string, data: boolean, tags?: string[]) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500598 // console.log("ScanCache write");
Skyler Greyda16adf2023-03-05 10:22:12 +0000599 await this.scanCache.insertOne(
600 { hash: hash, data: data, tags: tags ?? [], addedAt: new Date() },
601 collectionOptions
602 );
TheCodedProfb5e9d552023-01-29 15:43:26 -0500603 }
604
605 async cleanup() {
TheCodedProff8ef7942023-03-03 15:32:32 -0500606 // console.log("ScanCache cleanup");
Skyler Greyda16adf2023-03-05 10:22:12 +0000607 await this.scanCache.deleteMany({
608 addedAt: { $lt: new Date(Date.now() - 1000 * 60 * 60 * 24 * 31) },
609 hash: { $not$text: "http" }
610 });
TheCodedProfb5e9d552023-01-29 15:43:26 -0500611 }
612}
613
PineaFan538d3752023-01-12 21:48:23 +0000614export class PerformanceTest {
615 performanceData: Collection<PerformanceDataSchema>;
616
617 constructor() {
618 this.performanceData = database.collection<PerformanceDataSchema>("performance");
619 }
620
621 async record(data: PerformanceDataSchema) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500622 // console.log("PerformanceTest record");
PineaFan538d3752023-01-12 21:48:23 +0000623 data.timestamp = new Date();
TheCodedProffaae5332023-03-01 18:16:05 -0500624 await this.performanceData.insertOne(data, collectionOptions);
PineaFan538d3752023-01-12 21:48:23 +0000625 }
626 async read() {
TheCodedProff8ef7942023-03-03 15:32:32 -0500627 // console.log("PerformanceTest read");
PineaFan538d3752023-01-12 21:48:23 +0000628 return await this.performanceData.find({}).toArray();
629 }
630}
631
632export interface PerformanceDataSchema {
633 timestamp?: Date;
634 discord: number;
635 databaseRead: number;
636 resources: {
637 cpu: number;
638 memory: number;
639 temperature: number;
Skyler Greyda16adf2023-03-05 10:22:12 +0000640 };
PineaFan538d3752023-01-12 21:48:23 +0000641}
642
pineafan4edb7762022-06-26 19:21:04 +0100643export class ModNotes {
644 modNotes: Collection<ModNoteSchema>;
pineafan4edb7762022-06-26 19:21:04 +0100645
pineafan3a02ea32022-08-11 21:35:04 +0100646 constructor() {
pineafan4edb7762022-06-26 19:21:04 +0100647 this.modNotes = database.collection<ModNoteSchema>("modNotes");
pineafan4edb7762022-06-26 19:21:04 +0100648 }
649
650 async create(guild: string, user: string, note: string | null) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500651 // console.log("ModNotes create");
Skyler Grey11236ba2022-08-08 21:13:33 +0100652 await this.modNotes.updateOne({ guild: guild, user: user }, { $set: { note: note } }, { upsert: true });
pineafan4edb7762022-06-26 19:21:04 +0100653 }
654
655 async read(guild: string, user: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500656 // console.log("ModNotes read");
pineafan63fc5e22022-08-04 22:04:10 +0100657 const entry = await this.modNotes.findOne({ guild: guild, user: user });
pineafan4edb7762022-06-26 19:21:04 +0100658 return entry?.note ?? null;
659 }
TheCodedProf267563a2023-01-21 17:00:57 -0500660
661 async delete(guild: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500662 // console.log("ModNotes delete");
TheCodedProf267563a2023-01-21 17:00:57 -0500663 await this.modNotes.deleteMany({ guild: guild });
664 }
pineafan4edb7762022-06-26 19:21:04 +0100665}
666
pineafan73a7c4a2022-07-24 10:38:04 +0100667export class Premium {
668 premium: Collection<PremiumSchema>;
Skyler Greyda16adf2023-03-05 10:22:12 +0000669 cache: Map<string, [boolean, string, number, boolean, Date]>; // Date indicates the time one hour after it was created
670 cacheTimeout = 1000 * 60 * 60; // 1 hour
pineafan4edb7762022-06-26 19:21:04 +0100671
pineafan3a02ea32022-08-11 21:35:04 +0100672 constructor() {
pineafan73a7c4a2022-07-24 10:38:04 +0100673 this.premium = database.collection<PremiumSchema>("premium");
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500674 this.cache = new Map<string, [boolean, string, number, boolean, Date]>();
pineafan4edb7762022-06-26 19:21:04 +0100675 }
676
TheCodedProf633866f2023-02-03 17:06:00 -0500677 async updateUser(user: string, level: number) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500678 // console.log("Premium updateUser");
Skyler Greyda16adf2023-03-05 10:22:12 +0000679 if (!(await this.userExists(user))) await this.createUser(user, level);
TheCodedProf633866f2023-02-03 17:06:00 -0500680 await this.premium.updateOne({ user: user }, { $set: { level: level } }, { upsert: true });
681 }
682
683 async userExists(user: string): Promise<boolean> {
TheCodedProff8ef7942023-03-03 15:32:32 -0500684 // console.log("Premium userExists");
TheCodedProf633866f2023-02-03 17:06:00 -0500685 const entry = await this.premium.findOne({ user: user });
686 return entry ? true : false;
687 }
TheCodedProf633866f2023-02-03 17:06:00 -0500688 async createUser(user: string, level: number) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500689 // console.log("Premium createUser");
TheCodedProffaae5332023-03-01 18:16:05 -0500690 await this.premium.insertOne({ user: user, appliesTo: [], level: level }, collectionOptions);
TheCodedProf633866f2023-02-03 17:06:00 -0500691 }
692
TheCodedProfaa3fe992023-02-25 21:53:09 -0500693 async hasPremium(guild: string): Promise<[boolean, string, number, boolean] | null> {
TheCodedProff8ef7942023-03-03 15:32:32 -0500694 // console.log("Premium hasPremium");
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500695 // [Has premium, user giving premium, level, is mod: if given automatically]
696 const cached = this.cache.get(guild);
697 if (cached && cached[4].getTime() < Date.now()) return [cached[0], cached[1], cached[2], cached[3]];
TheCodedProf94ff6de2023-02-22 17:47:26 -0500698 const entries = await this.premium.find({}).toArray();
Skyler Greyda16adf2023-03-05 10:22:12 +0000699 const members = (await client.guilds.fetch(guild)).members.cache;
700 for (const { user } of entries) {
TheCodedProf94ff6de2023-02-22 17:47:26 -0500701 const member = members.get(user);
Skyler Greyda16adf2023-03-05 10:22:12 +0000702 if (member) {
703 //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 -0500704 const modPerms = //TODO: Create list in config for perms
Skyler Greyda16adf2023-03-05 10:22:12 +0000705 member.permissions.has("Administrator") ||
706 member.permissions.has("ManageChannels") ||
707 member.permissions.has("ManageRoles") ||
708 member.permissions.has("ManageEmojisAndStickers") ||
709 member.permissions.has("ManageWebhooks") ||
710 member.permissions.has("ManageGuild") ||
711 member.permissions.has("KickMembers") ||
712 member.permissions.has("BanMembers") ||
713 member.permissions.has("ManageEvents") ||
714 member.permissions.has("ManageMessages") ||
715 member.permissions.has("ManageThreads");
716 const entry = entries.find((e) => e.user === member.id);
717 if (entry && entry.level === 3 && modPerms) {
718 this.cache.set(guild, [
719 true,
720 member.id,
721 entry.level,
722 true,
723 new Date(Date.now() + this.cacheTimeout)
724 ]);
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500725 return [true, member.id, entry.level, true];
726 }
TheCodedProf94ff6de2023-02-22 17:47:26 -0500727 }
728 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100729 const entry = await this.premium.findOne({
TheCodedProf94ff6de2023-02-22 17:47:26 -0500730 appliesTo: {
731 $elemMatch: {
732 $eq: guild
733 }
734 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100735 });
Skyler Greyda16adf2023-03-05 10:22:12 +0000736 this.cache.set(guild, [
737 entry ? true : false,
738 entry?.user ?? "",
739 entry?.level ?? 0,
740 false,
741 new Date(Date.now() + this.cacheTimeout)
742 ]);
TheCodedProfaa3fe992023-02-25 21:53:09 -0500743 return entry ? [true, entry.user, entry.level, false] : null;
TheCodedProf267563a2023-01-21 17:00:57 -0500744 }
745
TheCodedProf633866f2023-02-03 17:06:00 -0500746 async fetchUser(user: string): Promise<PremiumSchema | null> {
TheCodedProff8ef7942023-03-03 15:32:32 -0500747 // console.log("Premium fetchUser");
TheCodedProf267563a2023-01-21 17:00:57 -0500748 const entry = await this.premium.findOne({ user: user });
TheCodedProf633866f2023-02-03 17:06:00 -0500749 if (!entry) return null;
750 return entry;
751 }
752
TheCodedProf94ff6de2023-02-22 17:47:26 -0500753 async checkAllPremium(member?: GuildMember) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500754 // console.log("Premium checkAllPremium");
TheCodedProf633866f2023-02-03 17:06:00 -0500755 const entries = await this.premium.find({}).toArray();
Skyler Greyda16adf2023-03-05 10:22:12 +0000756 if (member) {
757 const entry = entries.find((e) => e.user === member.id);
758 if (entry) {
TheCodedProf94ff6de2023-02-22 17:47:26 -0500759 const expiresAt = entry.expiresAt;
Skyler Greyda16adf2023-03-05 10:22:12 +0000760 if (expiresAt) expiresAt < Date.now() ? await this.premium.deleteOne({ user: member.id }) : null;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500761 }
762 const roles = member.roles;
763 let level = 0;
764 if (roles.cache.has("1066468879309750313")) {
TheCodedProf633866f2023-02-03 17:06:00 -0500765 level = 99;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500766 } else if (roles.cache.has("1066465491713003520")) {
TheCodedProf633866f2023-02-03 17:06:00 -0500767 level = 1;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500768 } else if (roles.cache.has("1066439526496604194")) {
TheCodedProf633866f2023-02-03 17:06:00 -0500769 level = 2;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500770 } else if (roles.cache.has("1066464134322978912")) {
TheCodedProf633866f2023-02-03 17:06:00 -0500771 level = 3;
772 }
TheCodedProf94ff6de2023-02-22 17:47:26 -0500773 await this.updateUser(member.id, level);
TheCodedProf633866f2023-02-03 17:06:00 -0500774 if (level > 0) {
Skyler Greyda16adf2023-03-05 10:22:12 +0000775 await this.premium.updateOne({ user: member.id }, { $unset: { expiresAt: "" } });
TheCodedProf633866f2023-02-03 17:06:00 -0500776 } else {
Skyler Greyda16adf2023-03-05 10:22:12 +0000777 await this.premium.updateOne(
778 { user: member.id },
779 { $set: { expiresAt: Date.now() + 1000 * 60 * 60 * 24 * 3 } }
780 );
TheCodedProf94ff6de2023-02-22 17:47:26 -0500781 }
782 } else {
Skyler Greyda16adf2023-03-05 10:22:12 +0000783 const members = await (await client.guilds.fetch("684492926528651336")).members.fetch();
784 for (const { roles, id } of members.values()) {
785 const entry = entries.find((e) => e.user === id);
786 if (entry) {
TheCodedProf94ff6de2023-02-22 17:47:26 -0500787 const expiresAt = entry.expiresAt;
Skyler Greyda16adf2023-03-05 10:22:12 +0000788 if (expiresAt) expiresAt < Date.now() ? await this.premium.deleteOne({ user: id }) : null;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500789 }
790 let level: number = 0;
791 if (roles.cache.has("1066468879309750313")) {
792 level = 99;
793 } else if (roles.cache.has("1066465491713003520")) {
794 level = 1;
795 } else if (roles.cache.has("1066439526496604194")) {
796 level = 2;
797 } else if (roles.cache.has("1066464134322978912")) {
798 level = 3;
799 }
800 await this.updateUser(id, level);
801 if (level > 0) {
Skyler Greyda16adf2023-03-05 10:22:12 +0000802 await this.premium.updateOne({ user: id }, { $unset: { expiresAt: "" } });
TheCodedProf94ff6de2023-02-22 17:47:26 -0500803 } else {
Skyler Greyda16adf2023-03-05 10:22:12 +0000804 await this.premium.updateOne(
805 { user: id },
806 { $set: { expiresAt: Date.now() + 1000 * 60 * 60 * 24 * 3 } }
807 );
TheCodedProf94ff6de2023-02-22 17:47:26 -0500808 }
TheCodedProf633866f2023-02-03 17:06:00 -0500809 }
810 }
TheCodedProf267563a2023-01-21 17:00:57 -0500811 }
812
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500813 async addPremium(user: string, guild: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500814 // console.log("Premium addPremium");
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500815 const { level } = (await this.fetchUser(user))!;
816 this.cache.set(guild, [true, user, level, false, new Date(Date.now() + this.cacheTimeout)]);
TheCodedProf267563a2023-01-21 17:00:57 -0500817 return this.premium.updateOne({ user: user }, { $addToSet: { appliesTo: guild } }, { upsert: true });
pineafan4edb7762022-06-26 19:21:04 +0100818 }
TheCodedProffc420b72023-01-24 17:14:38 -0500819
TheCodedProf48865eb2023-03-05 15:25:25 -0500820 async removePremium(user: string, guild: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500821 // console.log("Premium removePremium");
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500822 this.cache.set(guild, [false, "", 0, false, new Date(Date.now() + this.cacheTimeout)]);
TheCodedProf48865eb2023-03-05 15:25:25 -0500823 return await this.premium.updateOne({ user: user }, { $pull: { appliesTo: guild } });
TheCodedProffc420b72023-01-24 17:14:38 -0500824 }
pineafan4edb7762022-06-26 19:21:04 +0100825}
826
pineafan6fb3e072022-05-20 19:27:23 +0100827export interface GuildConfig {
Skyler Grey75ea9172022-08-06 10:22:23 +0100828 id: string;
829 version: number;
PineaFan100df682023-01-02 13:26:08 +0000830 singleEventNotifications: Record<string, boolean>;
pineafan6fb3e072022-05-20 19:27:23 +0100831 filters: {
832 images: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100833 NSFW: boolean;
834 size: boolean;
835 };
836 malware: boolean;
pineafan6fb3e072022-05-20 19:27:23 +0100837 wordFilter: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100838 enabled: boolean;
pineafan6fb3e072022-05-20 19:27:23 +0100839 words: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100840 strict: string[];
841 loose: string[];
842 };
pineafan6fb3e072022-05-20 19:27:23 +0100843 allowed: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100844 users: string[];
845 roles: string[];
846 channels: string[];
847 };
848 };
pineafan6fb3e072022-05-20 19:27:23 +0100849 invite: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100850 enabled: boolean;
PineaFan538d3752023-01-12 21:48:23 +0000851 allowed: {
852 channels: string[];
853 roles: string[];
854 users: string[];
855 };
Skyler Grey75ea9172022-08-06 10:22:23 +0100856 };
pineafan6fb3e072022-05-20 19:27:23 +0100857 pings: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100858 mass: number;
859 everyone: boolean;
860 roles: boolean;
pineafan6fb3e072022-05-20 19:27:23 +0100861 allowed: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100862 roles: string[];
863 rolesToMention: string[];
864 users: string[];
865 channels: string[];
866 };
867 };
TheCodedProfad0b8202023-02-14 14:27:09 -0500868 clean: {
869 channels: string[];
870 allowed: {
TheCodedProff8ef7942023-03-03 15:32:32 -0500871 users: string[];
TheCodedProfad0b8202023-02-14 14:27:09 -0500872 roles: string[];
Skyler Greyda16adf2023-03-05 10:22:12 +0000873 };
874 };
Skyler Grey75ea9172022-08-06 10:22:23 +0100875 };
TheCodedProfbaee2c12023-02-18 16:11:06 -0500876 autoPublish: {
877 enabled: boolean;
878 channels: string[];
Skyler Greyda16adf2023-03-05 10:22:12 +0000879 };
pineafan6fb3e072022-05-20 19:27:23 +0100880 welcome: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100881 enabled: boolean;
Skyler Grey75ea9172022-08-06 10:22:23 +0100882 role: string | null;
883 ping: string | null;
884 channel: string | null;
885 message: string | null;
886 };
887 stats: Record<string, { name: string; enabled: boolean }>;
pineafan6fb3e072022-05-20 19:27:23 +0100888 logging: {
889 logs: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100890 enabled: boolean;
891 channel: string | null;
Skyler Greyad002172022-08-16 18:48:26 +0100892 toLog: string;
Skyler Grey75ea9172022-08-06 10:22:23 +0100893 };
pineafan6fb3e072022-05-20 19:27:23 +0100894 staff: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100895 channel: string | null;
896 };
pineafan73a7c4a2022-07-24 10:38:04 +0100897 attachments: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100898 channel: string | null;
899 saved: Record<string, string>;
900 };
901 };
pineafan6fb3e072022-05-20 19:27:23 +0100902 verify: {
PineaFandf4996f2023-01-01 14:20:06 +0000903 enabled: boolean;
Skyler Grey75ea9172022-08-06 10:22:23 +0100904 role: string | null;
905 };
pineafan6fb3e072022-05-20 19:27:23 +0100906 tickets: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100907 enabled: boolean;
908 category: string | null;
Skyler Greyad002172022-08-16 18:48:26 +0100909 types: string;
910 customTypes: string[] | null;
Skyler Grey75ea9172022-08-06 10:22:23 +0100911 useCustom: boolean;
912 supportRole: string | null;
913 maxTickets: number;
914 };
pineafan6fb3e072022-05-20 19:27:23 +0100915 moderation: {
916 mute: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100917 timeout: boolean;
918 role: string | null;
919 text: string | null;
920 link: string | null;
921 };
pineafan6fb3e072022-05-20 19:27:23 +0100922 kick: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100923 text: string | null;
924 link: string | null;
925 };
pineafan6fb3e072022-05-20 19:27:23 +0100926 ban: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100927 text: string | null;
928 link: string | null;
929 };
pineafan6fb3e072022-05-20 19:27:23 +0100930 softban: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100931 text: string | null;
932 link: string | null;
933 };
pineafan6fb3e072022-05-20 19:27:23 +0100934 warn: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100935 text: string | null;
936 link: string | null;
937 };
pineafan6fb3e072022-05-20 19:27:23 +0100938 role: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100939 role: string | null;
TheCodedProfd9636e82023-01-17 22:13:06 -0500940 text: null;
941 link: null;
Skyler Grey75ea9172022-08-06 10:22:23 +0100942 };
PineaFane6ba7882023-01-18 20:41:16 +0000943 nick: {
944 text: string | null;
945 link: string | null;
Skyler Greyda16adf2023-03-05 10:22:12 +0000946 };
Skyler Grey75ea9172022-08-06 10:22:23 +0100947 };
pineafan6fb3e072022-05-20 19:27:23 +0100948 tracks: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100949 name: string;
950 retainPrevious: boolean;
951 nullable: boolean;
952 track: string[];
953 manageableBy: string[];
954 }[];
pineafan6fb3e072022-05-20 19:27:23 +0100955 roleMenu: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100956 enabled: boolean;
957 allowWebUI: boolean;
pineafan6fb3e072022-05-20 19:27:23 +0100958 options: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100959 name: string;
960 description: string;
961 min: number;
962 max: number;
pineafan6fb3e072022-05-20 19:27:23 +0100963 options: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100964 name: string;
965 description: string | null;
966 role: string;
967 }[];
968 }[];
969 };
970 tags: Record<string, string>;
pineafan63fc5e22022-08-04 22:04:10 +0100971}
pineafan4edb7762022-06-26 19:21:04 +0100972
973export interface HistorySchema {
Skyler Grey75ea9172022-08-06 10:22:23 +0100974 type: string;
975 guild: string;
976 user: string;
977 moderator: string | null;
pineafan3a02ea32022-08-11 21:35:04 +0100978 reason: string | null;
Skyler Grey75ea9172022-08-06 10:22:23 +0100979 occurredAt: Date;
980 before: string | null;
981 after: string | null;
982 amount: string | null;
pineafan4edb7762022-06-26 19:21:04 +0100983}
984
985export interface ModNoteSchema {
Skyler Grey75ea9172022-08-06 10:22:23 +0100986 guild: string;
987 user: string;
pineafan3a02ea32022-08-11 21:35:04 +0100988 note: string | null;
pineafan4edb7762022-06-26 19:21:04 +0100989}
990
pineafan73a7c4a2022-07-24 10:38:04 +0100991export interface PremiumSchema {
Skyler Grey75ea9172022-08-06 10:22:23 +0100992 user: string;
993 level: number;
Skyler Grey75ea9172022-08-06 10:22:23 +0100994 appliesTo: string[];
TheCodedProf633866f2023-02-03 17:06:00 -0500995 expiresAt?: number;
Skyler Grey75ea9172022-08-06 10:22:23 +0100996}