blob: 3121d06950b831f2ed6d5ba338b9c69d7bd4bdb0 [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, "-");
Skyler Greyda16adf2023-03-05 10:22:12 +0000271 for (const message of transcript.messages) {
272 if (message.content) {
TheCodedProf75c51be2023-03-03 17:18:18 -0500273 const encCipher = crypto.createCipheriv("AES-256-CBC", key, iv);
274 message.content = encCipher.update(message.content, "utf8", "base64") + encCipher.final("base64");
275 }
276 }
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500277
TheCodedProffaae5332023-03-01 18:16:05 -0500278 const doc = await this.transcripts.insertOne(Object.assign(transcript, { code: code }), collectionOptions);
Skyler Greyda16adf2023-03-05 10:22:12 +0000279 if (doc.acknowledged) {
Skyler Greyf4f21c42023-03-08 14:36:29 +0000280 await client.database.eventScheduler.schedule(
Skyler Greyda16adf2023-03-05 10:22:12 +0000281 "deleteTranscript",
282 (Date.now() + 1000 * 60 * 60 * 24 * 7).toString(),
283 { guild: transcript.guild, code: code, iv: iv, key: key }
284 );
TheCodedProf003160f2023-03-04 17:09:40 -0500285 return [code, key, iv];
Skyler Greyda16adf2023-03-05 10:22:12 +0000286 } else return [null, null, null];
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500287 }
288
TheCodedProf003160f2023-03-04 17:09:40 -0500289 async delete(code: string) {
290 // console.log("Transcript delete")
291 await this.transcripts.deleteOne({ code: code });
TheCodedProf75c51be2023-03-03 17:18:18 -0500292 }
293
294 async deleteAll(guild: string) {
295 // console.log("Transcript delete")
296 const filteredDocs = await this.transcripts.find({ guild: guild }).toArray();
297 for (const doc of filteredDocs) {
298 await this.transcripts.deleteOne({ code: doc.code });
299 }
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500300 }
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500301
TheCodedProf003160f2023-03-04 17:09:40 -0500302 async readEncrypted(code: string) {
303 // console.log("Transcript read")
304 let doc: TranscriptSchema | null = await this.transcripts.findOne({ code: code });
305 let findDoc: findDocSchema | null = null;
pineafan6de4da52023-03-07 20:43:44 +0000306 if (!doc) findDoc = await this.messageToTranscript.findOne({ transcript: code });
Skyler Greyda16adf2023-03-05 10:22:12 +0000307 if (findDoc) {
308 const message = await (
309 client.channels.cache.get(findDoc.channelID) as Discord.TextBasedChannel | null
310 )?.messages.fetch(findDoc.messageID);
311 if (!message) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500312 const attachment = message.attachments.first();
Skyler Greyda16adf2023-03-05 10:22:12 +0000313 if (!attachment) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500314 const transcript = (await fetch(attachment.url)).body;
Skyler Greyda16adf2023-03-05 10:22:12 +0000315 if (!transcript) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500316 const reader = transcript.getReader();
317 let data: Uint8Array | null = null;
318 let allPacketsReceived = false;
319 while (!allPacketsReceived) {
320 const { value, done } = await reader.read();
Skyler Greyda16adf2023-03-05 10:22:12 +0000321 if (done) {
322 allPacketsReceived = true;
323 continue;
324 }
325 if (!data) {
TheCodedProf003160f2023-03-04 17:09:40 -0500326 data = value;
327 } else {
328 data = new Uint8Array(Buffer.concat([data, value]));
329 }
330 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000331 if (!data) return null;
Skyler Greycf771402023-03-05 07:06:37 +0000332 doc = JSON.parse(Buffer.from(data).toString()) as TranscriptSchema;
TheCodedProf003160f2023-03-04 17:09:40 -0500333 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000334 if (!doc) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500335 return doc;
336 }
337
338 async read(code: string, key: string, iv: string) {
TheCodedProf003160f2023-03-04 17:09:40 -0500339 let doc: TranscriptSchema | null = await this.transcripts.findOne({ code: code });
340 let findDoc: findDocSchema | null = null;
pineafan6de4da52023-03-07 20:43:44 +0000341 if (!doc) findDoc = await this.messageToTranscript.findOne({ transcript: code });
Skyler Greyda16adf2023-03-05 10:22:12 +0000342 if (findDoc) {
343 const message = await (
344 client.channels.cache.get(findDoc.channelID) as Discord.TextBasedChannel | null
345 )?.messages.fetch(findDoc.messageID);
346 if (!message) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500347 const attachment = message.attachments.first();
Skyler Greyda16adf2023-03-05 10:22:12 +0000348 if (!attachment) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500349 const transcript = (await fetch(attachment.url)).body;
Skyler Greyda16adf2023-03-05 10:22:12 +0000350 if (!transcript) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500351 const reader = transcript.getReader();
352 let data: Uint8Array | null = null;
353 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, no-constant-condition
Skyler Greyda16adf2023-03-05 10:22:12 +0000354 while (true) {
TheCodedProf003160f2023-03-04 17:09:40 -0500355 const { value, done } = await reader.read();
356 if (done) break;
Skyler Greyda16adf2023-03-05 10:22:12 +0000357 if (!data) {
TheCodedProf003160f2023-03-04 17:09:40 -0500358 data = value;
359 } else {
360 data = new Uint8Array(Buffer.concat([data, value]));
361 }
362 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000363 if (!data) return null;
Skyler Greycf771402023-03-05 07:06:37 +0000364 doc = JSON.parse(Buffer.from(data).toString()) as TranscriptSchema;
TheCodedProf003160f2023-03-04 17:09:40 -0500365 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000366 if (!doc) return null;
367 for (const message of doc.messages) {
368 if (message.content) {
TheCodedProf003160f2023-03-04 17:09:40 -0500369 const decCipher = crypto.createDecipheriv("AES-256-CBC", key, iv);
370 message.content = decCipher.update(message.content, "base64", "utf8") + decCipher.final("utf8");
371 }
372 }
373 return doc;
374 }
375
Skyler Greyda16adf2023-03-05 10:22:12 +0000376 async createTranscript(
Skyler Greye0c511b2023-03-06 10:30:17 +0000377 type: "ticket" | "purge",
Skyler Greyda16adf2023-03-05 10:22:12 +0000378 messages: Message[],
379 interaction: MessageComponentInteraction | CommandInteraction,
380 member: GuildMember
381 ) {
382 const interactionMember = await interaction.guild?.members.fetch(interaction.user.id);
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500383 const newOut: Omit<TranscriptSchema, "code"> = {
Skyler Greye0c511b2023-03-06 10:30:17 +0000384 type: type,
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500385 for: {
386 username: member!.user.username,
387 discriminator: parseInt(member!.user.discriminator),
388 id: member!.user.id,
389 topRole: {
390 color: member!.roles.highest.color
TheCodedProf088b1b22023-02-28 17:31:11 -0500391 },
Skyler Greyda16adf2023-03-05 10:22:12 +0000392 iconURL: member!.user.displayAvatarURL({ forceStatic: true }),
TheCodedProf088b1b22023-02-28 17:31:11 -0500393 bot: member!.user.bot
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500394 },
395 guild: interaction.guild!.id,
396 channel: interaction.channel!.id,
397 messages: [],
398 createdTimestamp: Date.now(),
399 createdBy: {
400 username: interaction.user.username,
401 discriminator: parseInt(interaction.user.discriminator),
402 id: interaction.user.id,
403 topRole: {
404 color: interactionMember?.roles.highest.color ?? 0x000000
TheCodedProf088b1b22023-02-28 17:31:11 -0500405 },
Skyler Greyda16adf2023-03-05 10:22:12 +0000406 iconURL: interaction.user.displayAvatarURL({ forceStatic: true }),
TheCodedProf088b1b22023-02-28 17:31:11 -0500407 bot: interaction.user.bot
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500408 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000409 };
410 if (member.nickname) newOut.for.nickname = member.nickname;
411 if (interactionMember?.roles.icon) newOut.createdBy.topRole.badgeURL = interactionMember.roles.icon.iconURL()!;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500412 messages.reverse().forEach((message) => {
413 const msg: TranscriptMessage = {
414 id: message.id,
415 author: {
416 username: message.author.username,
417 discriminator: parseInt(message.author.discriminator),
418 id: message.author.id,
419 topRole: {
Skyler Greya0c70242023-03-06 09:56:21 +0000420 color: message.member ? message.member.roles.highest.color : 0x000000
TheCodedProf088b1b22023-02-28 17:31:11 -0500421 },
TheCodedProfe92b9b52023-03-06 17:07:34 -0500422 iconURL: (message.member?.user ?? message.author).displayAvatarURL({ forceStatic: true }),
Skyler Grey67691762023-03-06 09:58:19 +0000423 bot: message.author.bot || false
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500424 },
425 createdTimestamp: message.createdTimestamp
426 };
Skyler Greyda16adf2023-03-05 10:22:12 +0000427 if (message.member?.nickname) msg.author.nickname = message.member.nickname;
Skyler Greya0c70242023-03-06 09:56:21 +0000428 if (message.member?.roles.icon) msg.author.topRole.badgeURL = message.member!.roles.icon.iconURL()!;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500429 if (message.content) msg.content = message.content;
Skyler Greyda16adf2023-03-05 10:22:12 +0000430 if (message.embeds.length > 0)
431 msg.embeds = message.embeds.map((embed) => {
432 const obj: TranscriptEmbed = {};
433 if (embed.title) obj.title = embed.title;
434 if (embed.description) obj.description = embed.description;
435 if (embed.fields.length > 0)
436 obj.fields = embed.fields.map((field) => {
437 return {
438 name: field.name,
439 value: field.value,
440 inline: field.inline ?? false
441 };
442 });
443 if (embed.color) obj.color = embed.color;
444 if (embed.timestamp) obj.timestamp = embed.timestamp;
445 if (embed.footer)
446 obj.footer = {
447 text: embed.footer.text
448 };
449 if (embed.footer?.iconURL) obj.footer!.iconURL = embed.footer.iconURL;
450 if (embed.author)
451 obj.author = {
452 name: embed.author.name
453 };
454 if (embed.author?.iconURL) obj.author!.iconURL = embed.author.iconURL;
455 if (embed.author?.url) obj.author!.url = embed.author.url;
456 return obj;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500457 });
Skyler Greyda16adf2023-03-05 10:22:12 +0000458 if (message.components.length > 0)
459 msg.components = message.components.map((component) =>
460 component.components.map((child) => {
461 const obj: TranscriptComponent = {
462 type: child.type
463 };
464 if (child.type === ComponentType.Button) {
465 obj.style = child.style;
466 obj.label = child.label ?? "";
467 } else if (child.type > 2) {
468 obj.placeholder = child.placeholder ?? "";
469 }
470 return obj;
471 })
472 );
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500473 if (message.editedTimestamp) msg.editedTimestamp = message.editedTimestamp;
474 msg.flags = message.flags.toArray();
475
Skyler Greyda16adf2023-03-05 10:22:12 +0000476 if (message.stickers.size > 0) msg.stickerURLs = message.stickers.map((sticker) => sticker.url);
477 if (message.reference)
478 msg.referencedMessage = [
479 message.reference.guildId ?? "",
480 message.reference.channelId,
481 message.reference.messageId ?? ""
482 ];
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500483 newOut.messages.push(msg);
484 });
485 return newOut;
486 }
487
488 toHumanReadable(transcript: Omit<TranscriptSchema, "code">): string {
489 let out = "";
490 for (const message of transcript.messages) {
491 if (message.referencedMessage) {
492 if (Array.isArray(message.referencedMessage)) {
493 out += `> [Crosspost From] ${message.referencedMessage[0]} in ${message.referencedMessage[1]} in ${message.referencedMessage[2]}\n`;
Skyler Greyda16adf2023-03-05 10:22:12 +0000494 } else out += `> [Reply To] ${message.referencedMessage}\n`;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500495 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000496 out += `${message.author.nickname ?? message.author.username}#${message.author.discriminator} (${
497 message.author.id
498 }) (${message.id})`;
TheCodedProff8ef7942023-03-03 15:32:32 -0500499 out += ` [${new Date(message.createdTimestamp).toISOString()}]`;
500 if (message.editedTimestamp) out += ` [Edited: ${new Date(message.editedTimestamp).toISOString()}]`;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500501 out += "\n";
502 if (message.content) out += `[Content]\n${message.content}\n\n`;
503 if (message.embeds) {
504 for (const embed of message.embeds) {
505 out += `[Embed]\n`;
506 if (embed.title) out += `| Title: ${embed.title}\n`;
507 if (embed.description) out += `| Description: ${embed.description}\n`;
508 if (embed.fields) {
509 for (const field of embed.fields) {
510 out += `| Field: ${field.name} - ${field.value}\n`;
511 }
512 }
513 if (embed.footer) {
514 out += `|Footer: ${embed.footer.text}\n`;
515 }
516 out += "\n";
517 }
518 }
519 if (message.components) {
520 for (const component of message.components) {
521 out += `[Component]\n`;
522 for (const button of component) {
523 out += `| Button: ${button.label ?? button.description}\n`;
524 }
525 out += "\n";
526 }
527 }
528 if (message.attachments) {
529 for (const attachment of message.attachments) {
530 out += `[Attachment] ${attachment.filename} (${attachment.size} bytes) ${attachment.url}\n`;
531 }
532 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000533 out += "\n\n";
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500534 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000535 return out;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500536 }
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500537}
538
pineafan4edb7762022-06-26 19:21:04 +0100539export class History {
540 histories: Collection<HistorySchema>;
pineafan4edb7762022-06-26 19:21:04 +0100541
pineafan3a02ea32022-08-11 21:35:04 +0100542 constructor() {
pineafan4edb7762022-06-26 19:21:04 +0100543 this.histories = database.collection<HistorySchema>("history");
pineafan4edb7762022-06-26 19:21:04 +0100544 }
545
Skyler Grey75ea9172022-08-06 10:22:23 +0100546 async create(
547 type: string,
548 guild: string,
549 user: Discord.User,
550 moderator: Discord.User | null,
551 reason: string | null,
pineafan3a02ea32022-08-11 21:35:04 +0100552 before?: string | null,
553 after?: string | null,
554 amount?: string | null
Skyler Grey75ea9172022-08-06 10:22:23 +0100555 ) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500556 // console.log("History create");
Skyler Greyda16adf2023-03-05 10:22:12 +0000557 await this.histories.insertOne(
558 {
559 type: type,
560 guild: guild,
561 user: user.id,
562 moderator: moderator ? moderator.id : null,
563 reason: reason,
564 occurredAt: new Date(),
565 before: before ?? null,
566 after: after ?? null,
567 amount: amount ?? null
568 },
569 collectionOptions
570 );
pineafan4edb7762022-06-26 19:21:04 +0100571 }
572
573 async read(guild: string, user: string, year: number) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500574 // console.log("History read");
Skyler Grey75ea9172022-08-06 10:22:23 +0100575 const entry = (await this.histories
576 .find({
577 guild: guild,
578 user: user,
579 occurredAt: {
580 $gte: new Date(year - 1, 11, 31, 23, 59, 59),
581 $lt: new Date(year + 1, 0, 1, 0, 0, 0)
582 }
583 })
584 .toArray()) as HistorySchema[];
pineafan4edb7762022-06-26 19:21:04 +0100585 return entry;
586 }
pineafane23c4ec2022-07-27 21:56:27 +0100587
588 async delete(guild: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500589 // console.log("History delete");
pineafane23c4ec2022-07-27 21:56:27 +0100590 await this.histories.deleteMany({ guild: guild });
591 }
pineafan4edb7762022-06-26 19:21:04 +0100592}
593
TheCodedProfb5e9d552023-01-29 15:43:26 -0500594interface ScanCacheSchema {
595 addedAt: Date;
596 hash: string;
Skyler Grey14432712023-03-07 23:40:50 +0000597 nsfw?: boolean;
598 malware?: boolean;
599 bad_link?: boolean;
Skyler Greyd1157312023-03-08 10:07:38 +0000600 tags?: string[];
TheCodedProfb5e9d552023-01-29 15:43:26 -0500601}
602
603export class ScanCache {
604 scanCache: Collection<ScanCacheSchema>;
605
606 constructor() {
607 this.scanCache = database.collection<ScanCacheSchema>("scanCache");
608 }
609
610 async read(hash: string) {
611 return await this.scanCache.findOne({ hash: hash });
612 }
613
Skyler Grey14432712023-03-07 23:40:50 +0000614 async write(hash: string, type: "nsfw" | "malware" | "bad_link", data: boolean, tags?: string[]) {
Skyler Greycf89d4c2023-03-08 00:19:33 +0000615 await this.scanCache.updateOne(
616 { hash: hash },
Skyler Greyd1157312023-03-08 10:07:38 +0000617 {
618 $set: (() => {
619 switch (type) {
620 case "nsfw": {
621 return { nsfw: data, addedAt: new Date() };
622 }
623 case "malware": {
624 return { malware: data, addedAt: new Date() };
625 }
626 case "bad_link": {
627 return { bad_link: data, tags: tags ?? [], addedAt: new Date() };
628 }
629 default: {
630 throw new Error("Invalid type");
631 }
632 }
633 })()
634 // No you can't just do { [type]: data }, yes it's a typescript error, no I don't know how to fix it
635 // cleanly, yes it would be marginally more elegant, no it's not essential, yes I'd be happy to review
636 // PRs that did improve this snippet
637 },
Skyler Greycf89d4c2023-03-08 00:19:33 +0000638 Object.assign({ upsert: true }, collectionOptions)
Skyler Greyda16adf2023-03-05 10:22:12 +0000639 );
TheCodedProfb5e9d552023-01-29 15:43:26 -0500640 }
641
642 async cleanup() {
TheCodedProff8ef7942023-03-03 15:32:32 -0500643 // console.log("ScanCache cleanup");
Skyler Greyda16adf2023-03-05 10:22:12 +0000644 await this.scanCache.deleteMany({
645 addedAt: { $lt: new Date(Date.now() - 1000 * 60 * 60 * 24 * 31) },
646 hash: { $not$text: "http" }
647 });
TheCodedProfb5e9d552023-01-29 15:43:26 -0500648 }
649}
650
PineaFan538d3752023-01-12 21:48:23 +0000651export class PerformanceTest {
652 performanceData: Collection<PerformanceDataSchema>;
653
654 constructor() {
655 this.performanceData = database.collection<PerformanceDataSchema>("performance");
656 }
657
658 async record(data: PerformanceDataSchema) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500659 // console.log("PerformanceTest record");
PineaFan538d3752023-01-12 21:48:23 +0000660 data.timestamp = new Date();
TheCodedProffaae5332023-03-01 18:16:05 -0500661 await this.performanceData.insertOne(data, collectionOptions);
PineaFan538d3752023-01-12 21:48:23 +0000662 }
663 async read() {
TheCodedProff8ef7942023-03-03 15:32:32 -0500664 // console.log("PerformanceTest read");
PineaFan538d3752023-01-12 21:48:23 +0000665 return await this.performanceData.find({}).toArray();
666 }
667}
668
669export interface PerformanceDataSchema {
670 timestamp?: Date;
671 discord: number;
672 databaseRead: number;
673 resources: {
674 cpu: number;
675 memory: number;
676 temperature: number;
Skyler Greyda16adf2023-03-05 10:22:12 +0000677 };
PineaFan538d3752023-01-12 21:48:23 +0000678}
679
pineafan4edb7762022-06-26 19:21:04 +0100680export class ModNotes {
681 modNotes: Collection<ModNoteSchema>;
pineafan4edb7762022-06-26 19:21:04 +0100682
pineafan3a02ea32022-08-11 21:35:04 +0100683 constructor() {
pineafan4edb7762022-06-26 19:21:04 +0100684 this.modNotes = database.collection<ModNoteSchema>("modNotes");
pineafan4edb7762022-06-26 19:21:04 +0100685 }
686
687 async create(guild: string, user: string, note: string | null) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500688 // console.log("ModNotes create");
Skyler Grey11236ba2022-08-08 21:13:33 +0100689 await this.modNotes.updateOne({ guild: guild, user: user }, { $set: { note: note } }, { upsert: true });
pineafan4edb7762022-06-26 19:21:04 +0100690 }
691
692 async read(guild: string, user: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500693 // console.log("ModNotes read");
pineafan63fc5e22022-08-04 22:04:10 +0100694 const entry = await this.modNotes.findOne({ guild: guild, user: user });
pineafan4edb7762022-06-26 19:21:04 +0100695 return entry?.note ?? null;
696 }
TheCodedProf267563a2023-01-21 17:00:57 -0500697
698 async delete(guild: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500699 // console.log("ModNotes delete");
TheCodedProf267563a2023-01-21 17:00:57 -0500700 await this.modNotes.deleteMany({ guild: guild });
701 }
pineafan4edb7762022-06-26 19:21:04 +0100702}
703
pineafan73a7c4a2022-07-24 10:38:04 +0100704export class Premium {
705 premium: Collection<PremiumSchema>;
Skyler Greyda16adf2023-03-05 10:22:12 +0000706 cache: Map<string, [boolean, string, number, boolean, Date]>; // Date indicates the time one hour after it was created
707 cacheTimeout = 1000 * 60 * 60; // 1 hour
pineafan4edb7762022-06-26 19:21:04 +0100708
pineafan3a02ea32022-08-11 21:35:04 +0100709 constructor() {
pineafan73a7c4a2022-07-24 10:38:04 +0100710 this.premium = database.collection<PremiumSchema>("premium");
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500711 this.cache = new Map<string, [boolean, string, number, boolean, Date]>();
pineafan4edb7762022-06-26 19:21:04 +0100712 }
713
TheCodedProf633866f2023-02-03 17:06:00 -0500714 async updateUser(user: string, level: number) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500715 // console.log("Premium updateUser");
Skyler Greyda16adf2023-03-05 10:22:12 +0000716 if (!(await this.userExists(user))) await this.createUser(user, level);
TheCodedProf633866f2023-02-03 17:06:00 -0500717 await this.premium.updateOne({ user: user }, { $set: { level: level } }, { upsert: true });
718 }
719
720 async userExists(user: string): Promise<boolean> {
TheCodedProff8ef7942023-03-03 15:32:32 -0500721 // console.log("Premium userExists");
TheCodedProf633866f2023-02-03 17:06:00 -0500722 const entry = await this.premium.findOne({ user: user });
723 return entry ? true : false;
724 }
TheCodedProf633866f2023-02-03 17:06:00 -0500725 async createUser(user: string, level: number) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500726 // console.log("Premium createUser");
TheCodedProffaae5332023-03-01 18:16:05 -0500727 await this.premium.insertOne({ user: user, appliesTo: [], level: level }, collectionOptions);
TheCodedProf633866f2023-02-03 17:06:00 -0500728 }
729
TheCodedProfaa3fe992023-02-25 21:53:09 -0500730 async hasPremium(guild: string): Promise<[boolean, string, number, boolean] | null> {
TheCodedProff8ef7942023-03-03 15:32:32 -0500731 // console.log("Premium hasPremium");
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500732 // [Has premium, user giving premium, level, is mod: if given automatically]
733 const cached = this.cache.get(guild);
734 if (cached && cached[4].getTime() < Date.now()) return [cached[0], cached[1], cached[2], cached[3]];
TheCodedProf94ff6de2023-02-22 17:47:26 -0500735 const entries = await this.premium.find({}).toArray();
Skyler Greyda16adf2023-03-05 10:22:12 +0000736 const members = (await client.guilds.fetch(guild)).members.cache;
737 for (const { user } of entries) {
TheCodedProf94ff6de2023-02-22 17:47:26 -0500738 const member = members.get(user);
Skyler Greyda16adf2023-03-05 10:22:12 +0000739 if (member) {
740 //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 -0500741 const modPerms = //TODO: Create list in config for perms
Skyler Greyda16adf2023-03-05 10:22:12 +0000742 member.permissions.has("Administrator") ||
743 member.permissions.has("ManageChannels") ||
744 member.permissions.has("ManageRoles") ||
745 member.permissions.has("ManageEmojisAndStickers") ||
746 member.permissions.has("ManageWebhooks") ||
747 member.permissions.has("ManageGuild") ||
748 member.permissions.has("KickMembers") ||
749 member.permissions.has("BanMembers") ||
750 member.permissions.has("ManageEvents") ||
751 member.permissions.has("ManageMessages") ||
752 member.permissions.has("ManageThreads");
753 const entry = entries.find((e) => e.user === member.id);
754 if (entry && entry.level === 3 && modPerms) {
755 this.cache.set(guild, [
756 true,
757 member.id,
758 entry.level,
759 true,
760 new Date(Date.now() + this.cacheTimeout)
761 ]);
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500762 return [true, member.id, entry.level, true];
763 }
TheCodedProf94ff6de2023-02-22 17:47:26 -0500764 }
765 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100766 const entry = await this.premium.findOne({
TheCodedProf94ff6de2023-02-22 17:47:26 -0500767 appliesTo: {
768 $elemMatch: {
769 $eq: guild
770 }
771 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100772 });
Skyler Greyda16adf2023-03-05 10:22:12 +0000773 this.cache.set(guild, [
774 entry ? true : false,
775 entry?.user ?? "",
776 entry?.level ?? 0,
777 false,
778 new Date(Date.now() + this.cacheTimeout)
779 ]);
TheCodedProfaa3fe992023-02-25 21:53:09 -0500780 return entry ? [true, entry.user, entry.level, false] : null;
TheCodedProf267563a2023-01-21 17:00:57 -0500781 }
782
TheCodedProf633866f2023-02-03 17:06:00 -0500783 async fetchUser(user: string): Promise<PremiumSchema | null> {
TheCodedProff8ef7942023-03-03 15:32:32 -0500784 // console.log("Premium fetchUser");
TheCodedProf267563a2023-01-21 17:00:57 -0500785 const entry = await this.premium.findOne({ user: user });
TheCodedProf633866f2023-02-03 17:06:00 -0500786 if (!entry) return null;
787 return entry;
788 }
789
TheCodedProf94ff6de2023-02-22 17:47:26 -0500790 async checkAllPremium(member?: GuildMember) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500791 // console.log("Premium checkAllPremium");
TheCodedProf633866f2023-02-03 17:06:00 -0500792 const entries = await this.premium.find({}).toArray();
Skyler Greyda16adf2023-03-05 10:22:12 +0000793 if (member) {
794 const entry = entries.find((e) => e.user === member.id);
795 if (entry) {
TheCodedProf94ff6de2023-02-22 17:47:26 -0500796 const expiresAt = entry.expiresAt;
Skyler Greyda16adf2023-03-05 10:22:12 +0000797 if (expiresAt) expiresAt < Date.now() ? await this.premium.deleteOne({ user: member.id }) : null;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500798 }
799 const roles = member.roles;
800 let level = 0;
801 if (roles.cache.has("1066468879309750313")) {
TheCodedProf633866f2023-02-03 17:06:00 -0500802 level = 99;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500803 } else if (roles.cache.has("1066465491713003520")) {
TheCodedProf633866f2023-02-03 17:06:00 -0500804 level = 1;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500805 } else if (roles.cache.has("1066439526496604194")) {
TheCodedProf633866f2023-02-03 17:06:00 -0500806 level = 2;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500807 } else if (roles.cache.has("1066464134322978912")) {
TheCodedProf633866f2023-02-03 17:06:00 -0500808 level = 3;
809 }
TheCodedProf94ff6de2023-02-22 17:47:26 -0500810 await this.updateUser(member.id, level);
TheCodedProf633866f2023-02-03 17:06:00 -0500811 if (level > 0) {
Skyler Greyda16adf2023-03-05 10:22:12 +0000812 await this.premium.updateOne({ user: member.id }, { $unset: { expiresAt: "" } });
TheCodedProf633866f2023-02-03 17:06:00 -0500813 } else {
Skyler Greyda16adf2023-03-05 10:22:12 +0000814 await this.premium.updateOne(
815 { user: member.id },
816 { $set: { expiresAt: Date.now() + 1000 * 60 * 60 * 24 * 3 } }
817 );
TheCodedProf94ff6de2023-02-22 17:47:26 -0500818 }
819 } else {
Skyler Greyda16adf2023-03-05 10:22:12 +0000820 const members = await (await client.guilds.fetch("684492926528651336")).members.fetch();
821 for (const { roles, id } of members.values()) {
822 const entry = entries.find((e) => e.user === id);
823 if (entry) {
TheCodedProf94ff6de2023-02-22 17:47:26 -0500824 const expiresAt = entry.expiresAt;
Skyler Greyda16adf2023-03-05 10:22:12 +0000825 if (expiresAt) expiresAt < Date.now() ? await this.premium.deleteOne({ user: id }) : null;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500826 }
827 let level: number = 0;
828 if (roles.cache.has("1066468879309750313")) {
829 level = 99;
830 } else if (roles.cache.has("1066465491713003520")) {
831 level = 1;
832 } else if (roles.cache.has("1066439526496604194")) {
833 level = 2;
834 } else if (roles.cache.has("1066464134322978912")) {
835 level = 3;
836 }
837 await this.updateUser(id, level);
838 if (level > 0) {
Skyler Greyda16adf2023-03-05 10:22:12 +0000839 await this.premium.updateOne({ user: id }, { $unset: { expiresAt: "" } });
TheCodedProf94ff6de2023-02-22 17:47:26 -0500840 } else {
Skyler Greyda16adf2023-03-05 10:22:12 +0000841 await this.premium.updateOne(
842 { user: id },
843 { $set: { expiresAt: Date.now() + 1000 * 60 * 60 * 24 * 3 } }
844 );
TheCodedProf94ff6de2023-02-22 17:47:26 -0500845 }
TheCodedProf633866f2023-02-03 17:06:00 -0500846 }
847 }
TheCodedProf267563a2023-01-21 17:00:57 -0500848 }
849
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500850 async addPremium(user: string, guild: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500851 // console.log("Premium addPremium");
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500852 const { level } = (await this.fetchUser(user))!;
853 this.cache.set(guild, [true, user, level, false, new Date(Date.now() + this.cacheTimeout)]);
TheCodedProf267563a2023-01-21 17:00:57 -0500854 return this.premium.updateOne({ user: user }, { $addToSet: { appliesTo: guild } }, { upsert: true });
pineafan4edb7762022-06-26 19:21:04 +0100855 }
TheCodedProffc420b72023-01-24 17:14:38 -0500856
TheCodedProf48865eb2023-03-05 15:25:25 -0500857 async removePremium(user: string, guild: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500858 // console.log("Premium removePremium");
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500859 this.cache.set(guild, [false, "", 0, false, new Date(Date.now() + this.cacheTimeout)]);
TheCodedProf48865eb2023-03-05 15:25:25 -0500860 return await this.premium.updateOne({ user: user }, { $pull: { appliesTo: guild } });
TheCodedProffc420b72023-01-24 17:14:38 -0500861 }
pineafan4edb7762022-06-26 19:21:04 +0100862}
863
pineafan1e462ab2023-03-07 21:34:06 +0000864// export class Plugins {}
pineafan6de4da52023-03-07 20:43:44 +0000865
pineafan6fb3e072022-05-20 19:27:23 +0100866export interface GuildConfig {
Skyler Grey75ea9172022-08-06 10:22:23 +0100867 id: string;
868 version: number;
PineaFan100df682023-01-02 13:26:08 +0000869 singleEventNotifications: Record<string, boolean>;
pineafan6fb3e072022-05-20 19:27:23 +0100870 filters: {
871 images: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100872 NSFW: boolean;
873 size: boolean;
874 };
875 malware: boolean;
pineafan6fb3e072022-05-20 19:27:23 +0100876 wordFilter: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100877 enabled: boolean;
pineafan6fb3e072022-05-20 19:27:23 +0100878 words: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100879 strict: string[];
880 loose: string[];
881 };
pineafan6fb3e072022-05-20 19:27:23 +0100882 allowed: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100883 users: string[];
884 roles: string[];
885 channels: string[];
886 };
887 };
pineafan6fb3e072022-05-20 19:27:23 +0100888 invite: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100889 enabled: boolean;
PineaFan538d3752023-01-12 21:48:23 +0000890 allowed: {
891 channels: string[];
892 roles: string[];
893 users: string[];
894 };
Skyler Grey75ea9172022-08-06 10:22:23 +0100895 };
pineafan6fb3e072022-05-20 19:27:23 +0100896 pings: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100897 mass: number;
898 everyone: boolean;
899 roles: boolean;
pineafan6fb3e072022-05-20 19:27:23 +0100900 allowed: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100901 roles: string[];
902 rolesToMention: string[];
903 users: string[];
904 channels: string[];
905 };
906 };
TheCodedProfad0b8202023-02-14 14:27:09 -0500907 clean: {
908 channels: string[];
909 allowed: {
TheCodedProff8ef7942023-03-03 15:32:32 -0500910 users: string[];
TheCodedProfad0b8202023-02-14 14:27:09 -0500911 roles: string[];
Skyler Greyda16adf2023-03-05 10:22:12 +0000912 };
913 };
Skyler Grey75ea9172022-08-06 10:22:23 +0100914 };
TheCodedProfbaee2c12023-02-18 16:11:06 -0500915 autoPublish: {
916 enabled: boolean;
917 channels: string[];
Skyler Greyda16adf2023-03-05 10:22:12 +0000918 };
pineafan6fb3e072022-05-20 19:27:23 +0100919 welcome: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100920 enabled: boolean;
Skyler Grey75ea9172022-08-06 10:22:23 +0100921 role: string | null;
922 ping: string | null;
923 channel: string | null;
924 message: string | null;
925 };
926 stats: Record<string, { name: string; enabled: boolean }>;
pineafan6fb3e072022-05-20 19:27:23 +0100927 logging: {
928 logs: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100929 enabled: boolean;
930 channel: string | null;
Skyler Greyad002172022-08-16 18:48:26 +0100931 toLog: string;
Skyler Grey75ea9172022-08-06 10:22:23 +0100932 };
pineafan6fb3e072022-05-20 19:27:23 +0100933 staff: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100934 channel: string | null;
935 };
pineafan73a7c4a2022-07-24 10:38:04 +0100936 attachments: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100937 channel: string | null;
938 saved: Record<string, string>;
939 };
940 };
pineafan6fb3e072022-05-20 19:27:23 +0100941 verify: {
PineaFandf4996f2023-01-01 14:20:06 +0000942 enabled: boolean;
Skyler Grey75ea9172022-08-06 10:22:23 +0100943 role: string | null;
944 };
pineafan6fb3e072022-05-20 19:27:23 +0100945 tickets: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100946 enabled: boolean;
947 category: string | null;
Skyler Greyad002172022-08-16 18:48:26 +0100948 types: string;
949 customTypes: string[] | null;
Skyler Grey75ea9172022-08-06 10:22:23 +0100950 useCustom: boolean;
951 supportRole: string | null;
952 maxTickets: number;
953 };
pineafan6fb3e072022-05-20 19:27:23 +0100954 moderation: {
955 mute: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100956 timeout: boolean;
957 role: string | null;
958 text: string | null;
959 link: string | null;
960 };
pineafan6fb3e072022-05-20 19:27:23 +0100961 kick: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100962 text: string | null;
963 link: string | null;
964 };
pineafan6fb3e072022-05-20 19:27:23 +0100965 ban: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100966 text: string | null;
967 link: string | null;
968 };
pineafan6fb3e072022-05-20 19:27:23 +0100969 softban: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100970 text: string | null;
971 link: string | null;
972 };
pineafan6fb3e072022-05-20 19:27:23 +0100973 warn: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100974 text: string | null;
975 link: string | null;
976 };
pineafan6fb3e072022-05-20 19:27:23 +0100977 role: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100978 role: string | null;
TheCodedProfd9636e82023-01-17 22:13:06 -0500979 text: null;
980 link: null;
Skyler Grey75ea9172022-08-06 10:22:23 +0100981 };
PineaFane6ba7882023-01-18 20:41:16 +0000982 nick: {
983 text: string | null;
984 link: string | null;
Skyler Greyda16adf2023-03-05 10:22:12 +0000985 };
Skyler Grey75ea9172022-08-06 10:22:23 +0100986 };
pineafan6fb3e072022-05-20 19:27:23 +0100987 tracks: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100988 name: string;
989 retainPrevious: boolean;
990 nullable: boolean;
991 track: string[];
992 manageableBy: string[];
993 }[];
pineafan6fb3e072022-05-20 19:27:23 +0100994 roleMenu: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100995 enabled: boolean;
996 allowWebUI: boolean;
pineafan6fb3e072022-05-20 19:27:23 +0100997 options: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100998 name: string;
999 description: string;
1000 min: number;
1001 max: number;
pineafan6fb3e072022-05-20 19:27:23 +01001002 options: {
Skyler Grey75ea9172022-08-06 10:22:23 +01001003 name: string;
1004 description: string | null;
1005 role: string;
1006 }[];
1007 }[];
1008 };
1009 tags: Record<string, string>;
pineafan63fc5e22022-08-04 22:04:10 +01001010}
pineafan4edb7762022-06-26 19:21:04 +01001011
1012export interface HistorySchema {
Skyler Grey75ea9172022-08-06 10:22:23 +01001013 type: string;
1014 guild: string;
1015 user: string;
1016 moderator: string | null;
pineafan3a02ea32022-08-11 21:35:04 +01001017 reason: string | null;
Skyler Grey75ea9172022-08-06 10:22:23 +01001018 occurredAt: Date;
1019 before: string | null;
1020 after: string | null;
1021 amount: string | null;
pineafan4edb7762022-06-26 19:21:04 +01001022}
1023
1024export interface ModNoteSchema {
Skyler Grey75ea9172022-08-06 10:22:23 +01001025 guild: string;
1026 user: string;
pineafan3a02ea32022-08-11 21:35:04 +01001027 note: string | null;
pineafan4edb7762022-06-26 19:21:04 +01001028}
1029
pineafan73a7c4a2022-07-24 10:38:04 +01001030export interface PremiumSchema {
Skyler Grey75ea9172022-08-06 10:22:23 +01001031 user: string;
1032 level: number;
Skyler Grey75ea9172022-08-06 10:22:23 +01001033 appliesTo: string[];
TheCodedProf633866f2023-02-03 17:06:00 -05001034 expiresAt?: number;
Skyler Grey75ea9172022-08-06 10:22:23 +01001035}