blob: 75a79d9d0c75d57e59e3b42d9e121720dd811a5f [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 }
Skyler Grey67691762023-03-06 09:58:19 +000058 if (!guildObj) await this.delete(guild.id);
TheCodedProfb7a7b992023-03-05 16:11:59 -050059 }
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;
TheCodedProfe92b9b52023-03-06 17:07:34 -0500224 code: string;
Skyler Greyda16adf2023-03-05 10:22:12 +0000225}
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 Grey67691762023-03-06 09:58:19 +0000254 const iv = getIV()
255 .toString("base64")
256 .substring(0, 16)
257 .replace(/=/g, "")
258 .replace(/\//g, "_")
259 .replace(/\+/g, "-");
260 console.log(iv);
Skyler Greyda16adf2023-03-05 10:22:12 +0000261 for (const message of transcript.messages) {
262 if (message.content) {
TheCodedProf75c51be2023-03-03 17:18:18 -0500263 const encCipher = crypto.createCipheriv("AES-256-CBC", key, iv);
264 message.content = encCipher.update(message.content, "utf8", "base64") + encCipher.final("base64");
265 }
266 }
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500267
TheCodedProffaae5332023-03-01 18:16:05 -0500268 const doc = await this.transcripts.insertOne(Object.assign(transcript, { code: code }), collectionOptions);
Skyler Greyda16adf2023-03-05 10:22:12 +0000269 if (doc.acknowledged) {
270 client.database.eventScheduler.schedule(
271 "deleteTranscript",
272 (Date.now() + 1000 * 60 * 60 * 24 * 7).toString(),
273 { guild: transcript.guild, code: code, iv: iv, key: key }
274 );
TheCodedProf003160f2023-03-04 17:09:40 -0500275 return [code, key, iv];
Skyler Greyda16adf2023-03-05 10:22:12 +0000276 } else return [null, null, null];
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500277 }
278
TheCodedProf003160f2023-03-04 17:09:40 -0500279 async delete(code: string) {
280 // console.log("Transcript delete")
281 await this.transcripts.deleteOne({ code: code });
TheCodedProf75c51be2023-03-03 17:18:18 -0500282 }
283
284 async deleteAll(guild: string) {
285 // console.log("Transcript delete")
286 const filteredDocs = await this.transcripts.find({ guild: guild }).toArray();
TheCodedProfe92b9b52023-03-06 17:07:34 -0500287 const filteredDocs1 = await this.messageToTranscript.find({ guild: guild }).toArray();
TheCodedProf75c51be2023-03-03 17:18:18 -0500288 for (const doc of filteredDocs) {
289 await this.transcripts.deleteOne({ code: doc.code });
290 }
TheCodedProfe92b9b52023-03-06 17:07:34 -0500291 for (const doc of filteredDocs1) {
292 await this.messageToTranscript.deleteOne({ code: doc.code });
293 }
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500294 }
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500295
TheCodedProf003160f2023-03-04 17:09:40 -0500296 async readEncrypted(code: string) {
297 // console.log("Transcript read")
298 let doc: TranscriptSchema | null = await this.transcripts.findOne({ code: code });
299 let findDoc: findDocSchema | null = null;
TheCodedProfe92b9b52023-03-06 17:07:34 -0500300 if (!doc) findDoc = await this.messageToTranscript.findOne({ code: code });
Skyler Greyda16adf2023-03-05 10:22:12 +0000301 if (findDoc) {
302 const message = await (
303 client.channels.cache.get(findDoc.channelID) as Discord.TextBasedChannel | null
304 )?.messages.fetch(findDoc.messageID);
305 if (!message) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500306 const attachment = message.attachments.first();
Skyler Greyda16adf2023-03-05 10:22:12 +0000307 if (!attachment) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500308 const transcript = (await fetch(attachment.url)).body;
Skyler Greyda16adf2023-03-05 10:22:12 +0000309 if (!transcript) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500310 const reader = transcript.getReader();
311 let data: Uint8Array | null = null;
312 let allPacketsReceived = false;
313 while (!allPacketsReceived) {
314 const { value, done } = await reader.read();
Skyler Greyda16adf2023-03-05 10:22:12 +0000315 if (done) {
316 allPacketsReceived = true;
317 continue;
318 }
319 if (!data) {
TheCodedProf003160f2023-03-04 17:09:40 -0500320 data = value;
321 } else {
322 data = new Uint8Array(Buffer.concat([data, value]));
323 }
324 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000325 if (!data) return null;
Skyler Greycf771402023-03-05 07:06:37 +0000326 doc = JSON.parse(Buffer.from(data).toString()) as TranscriptSchema;
TheCodedProf003160f2023-03-04 17:09:40 -0500327 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000328 if (!doc) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500329 return doc;
330 }
331
332 async read(code: string, key: string, iv: string) {
Skyler Grey67691762023-03-06 09:58:19 +0000333 console.log("Transcript read");
TheCodedProf003160f2023-03-04 17:09:40 -0500334 let doc: TranscriptSchema | null = await this.transcripts.findOne({ code: code });
335 let findDoc: findDocSchema | null = null;
Skyler Grey67691762023-03-06 09:58:19 +0000336 console.log(doc);
TheCodedProfe92b9b52023-03-06 17:07:34 -0500337 if (!doc) findDoc = await this.messageToTranscript.findOne({ code: code });
Skyler Greyda16adf2023-03-05 10:22:12 +0000338 if (findDoc) {
339 const message = await (
340 client.channels.cache.get(findDoc.channelID) as Discord.TextBasedChannel | null
341 )?.messages.fetch(findDoc.messageID);
342 if (!message) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500343 const attachment = message.attachments.first();
Skyler Greyda16adf2023-03-05 10:22:12 +0000344 if (!attachment) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500345 const transcript = (await fetch(attachment.url)).body;
Skyler Greyda16adf2023-03-05 10:22:12 +0000346 if (!transcript) return null;
TheCodedProf003160f2023-03-04 17:09:40 -0500347 const reader = transcript.getReader();
348 let data: Uint8Array | null = null;
349 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, no-constant-condition
Skyler Greyda16adf2023-03-05 10:22:12 +0000350 while (true) {
TheCodedProf003160f2023-03-04 17:09:40 -0500351 const { value, done } = await reader.read();
352 if (done) break;
Skyler Greyda16adf2023-03-05 10:22:12 +0000353 if (!data) {
TheCodedProf003160f2023-03-04 17:09:40 -0500354 data = value;
355 } else {
356 data = new Uint8Array(Buffer.concat([data, value]));
357 }
358 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000359 if (!data) return null;
Skyler Greycf771402023-03-05 07:06:37 +0000360 doc = JSON.parse(Buffer.from(data).toString()) as TranscriptSchema;
TheCodedProf003160f2023-03-04 17:09:40 -0500361 }
Skyler Grey67691762023-03-06 09:58:19 +0000362 console.log(doc);
Skyler Greyda16adf2023-03-05 10:22:12 +0000363 if (!doc) return null;
364 for (const message of doc.messages) {
365 if (message.content) {
TheCodedProf003160f2023-03-04 17:09:40 -0500366 const decCipher = crypto.createDecipheriv("AES-256-CBC", key, iv);
367 message.content = decCipher.update(message.content, "base64", "utf8") + decCipher.final("utf8");
368 }
369 }
370 return doc;
371 }
372
Skyler Greyda16adf2023-03-05 10:22:12 +0000373 async createTranscript(
Skyler Greye0c511b2023-03-06 10:30:17 +0000374 type: "ticket" | "purge",
Skyler Greyda16adf2023-03-05 10:22:12 +0000375 messages: Message[],
376 interaction: MessageComponentInteraction | CommandInteraction,
377 member: GuildMember
378 ) {
379 const interactionMember = await interaction.guild?.members.fetch(interaction.user.id);
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500380 const newOut: Omit<TranscriptSchema, "code"> = {
Skyler Greye0c511b2023-03-06 10:30:17 +0000381 type: type,
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500382 for: {
383 username: member!.user.username,
384 discriminator: parseInt(member!.user.discriminator),
385 id: member!.user.id,
386 topRole: {
387 color: member!.roles.highest.color
TheCodedProf088b1b22023-02-28 17:31:11 -0500388 },
Skyler Greyda16adf2023-03-05 10:22:12 +0000389 iconURL: member!.user.displayAvatarURL({ forceStatic: true }),
TheCodedProf088b1b22023-02-28 17:31:11 -0500390 bot: member!.user.bot
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500391 },
392 guild: interaction.guild!.id,
393 channel: interaction.channel!.id,
394 messages: [],
395 createdTimestamp: Date.now(),
396 createdBy: {
397 username: interaction.user.username,
398 discriminator: parseInt(interaction.user.discriminator),
399 id: interaction.user.id,
400 topRole: {
401 color: interactionMember?.roles.highest.color ?? 0x000000
TheCodedProf088b1b22023-02-28 17:31:11 -0500402 },
Skyler Greyda16adf2023-03-05 10:22:12 +0000403 iconURL: interaction.user.displayAvatarURL({ forceStatic: true }),
TheCodedProf088b1b22023-02-28 17:31:11 -0500404 bot: interaction.user.bot
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500405 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000406 };
407 if (member.nickname) newOut.for.nickname = member.nickname;
408 if (interactionMember?.roles.icon) newOut.createdBy.topRole.badgeURL = interactionMember.roles.icon.iconURL()!;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500409 messages.reverse().forEach((message) => {
410 const msg: TranscriptMessage = {
411 id: message.id,
412 author: {
413 username: message.author.username,
414 discriminator: parseInt(message.author.discriminator),
415 id: message.author.id,
416 topRole: {
Skyler Greya0c70242023-03-06 09:56:21 +0000417 color: message.member ? message.member.roles.highest.color : 0x000000
TheCodedProf088b1b22023-02-28 17:31:11 -0500418 },
TheCodedProfe92b9b52023-03-06 17:07:34 -0500419 iconURL: (message.member?.user ?? message.author).displayAvatarURL({ forceStatic: true }),
Skyler Grey67691762023-03-06 09:58:19 +0000420 bot: message.author.bot || false
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500421 },
422 createdTimestamp: message.createdTimestamp
423 };
Skyler Greyda16adf2023-03-05 10:22:12 +0000424 if (message.member?.nickname) msg.author.nickname = message.member.nickname;
Skyler Greya0c70242023-03-06 09:56:21 +0000425 if (message.member?.roles.icon) msg.author.topRole.badgeURL = message.member!.roles.icon.iconURL()!;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500426 if (message.content) msg.content = message.content;
Skyler Greyda16adf2023-03-05 10:22:12 +0000427 if (message.embeds.length > 0)
428 msg.embeds = message.embeds.map((embed) => {
429 const obj: TranscriptEmbed = {};
430 if (embed.title) obj.title = embed.title;
431 if (embed.description) obj.description = embed.description;
432 if (embed.fields.length > 0)
433 obj.fields = embed.fields.map((field) => {
434 return {
435 name: field.name,
436 value: field.value,
437 inline: field.inline ?? false
438 };
439 });
440 if (embed.color) obj.color = embed.color;
441 if (embed.timestamp) obj.timestamp = embed.timestamp;
442 if (embed.footer)
443 obj.footer = {
444 text: embed.footer.text
445 };
446 if (embed.footer?.iconURL) obj.footer!.iconURL = embed.footer.iconURL;
447 if (embed.author)
448 obj.author = {
449 name: embed.author.name
450 };
451 if (embed.author?.iconURL) obj.author!.iconURL = embed.author.iconURL;
452 if (embed.author?.url) obj.author!.url = embed.author.url;
453 return obj;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500454 });
Skyler Greyda16adf2023-03-05 10:22:12 +0000455 if (message.components.length > 0)
456 msg.components = message.components.map((component) =>
457 component.components.map((child) => {
458 const obj: TranscriptComponent = {
459 type: child.type
460 };
461 if (child.type === ComponentType.Button) {
462 obj.style = child.style;
463 obj.label = child.label ?? "";
464 } else if (child.type > 2) {
465 obj.placeholder = child.placeholder ?? "";
466 }
467 return obj;
468 })
469 );
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500470 if (message.editedTimestamp) msg.editedTimestamp = message.editedTimestamp;
471 msg.flags = message.flags.toArray();
472
Skyler Greyda16adf2023-03-05 10:22:12 +0000473 if (message.stickers.size > 0) msg.stickerURLs = message.stickers.map((sticker) => sticker.url);
474 if (message.reference)
475 msg.referencedMessage = [
476 message.reference.guildId ?? "",
477 message.reference.channelId,
478 message.reference.messageId ?? ""
479 ];
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500480 newOut.messages.push(msg);
481 });
482 return newOut;
483 }
484
485 toHumanReadable(transcript: Omit<TranscriptSchema, "code">): string {
486 let out = "";
487 for (const message of transcript.messages) {
488 if (message.referencedMessage) {
489 if (Array.isArray(message.referencedMessage)) {
490 out += `> [Crosspost From] ${message.referencedMessage[0]} in ${message.referencedMessage[1]} in ${message.referencedMessage[2]}\n`;
Skyler Greyda16adf2023-03-05 10:22:12 +0000491 } else out += `> [Reply To] ${message.referencedMessage}\n`;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500492 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000493 out += `${message.author.nickname ?? message.author.username}#${message.author.discriminator} (${
494 message.author.id
495 }) (${message.id})`;
TheCodedProff8ef7942023-03-03 15:32:32 -0500496 out += ` [${new Date(message.createdTimestamp).toISOString()}]`;
497 if (message.editedTimestamp) out += ` [Edited: ${new Date(message.editedTimestamp).toISOString()}]`;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500498 out += "\n";
499 if (message.content) out += `[Content]\n${message.content}\n\n`;
500 if (message.embeds) {
501 for (const embed of message.embeds) {
502 out += `[Embed]\n`;
503 if (embed.title) out += `| Title: ${embed.title}\n`;
504 if (embed.description) out += `| Description: ${embed.description}\n`;
505 if (embed.fields) {
506 for (const field of embed.fields) {
507 out += `| Field: ${field.name} - ${field.value}\n`;
508 }
509 }
510 if (embed.footer) {
511 out += `|Footer: ${embed.footer.text}\n`;
512 }
513 out += "\n";
514 }
515 }
516 if (message.components) {
517 for (const component of message.components) {
518 out += `[Component]\n`;
519 for (const button of component) {
520 out += `| Button: ${button.label ?? button.description}\n`;
521 }
522 out += "\n";
523 }
524 }
525 if (message.attachments) {
526 for (const attachment of message.attachments) {
527 out += `[Attachment] ${attachment.filename} (${attachment.size} bytes) ${attachment.url}\n`;
528 }
529 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000530 out += "\n\n";
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500531 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000532 return out;
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500533 }
TheCodedProfcfe8e9a2023-02-26 17:28:09 -0500534}
535
pineafan4edb7762022-06-26 19:21:04 +0100536export class History {
537 histories: Collection<HistorySchema>;
pineafan4edb7762022-06-26 19:21:04 +0100538
pineafan3a02ea32022-08-11 21:35:04 +0100539 constructor() {
pineafan4edb7762022-06-26 19:21:04 +0100540 this.histories = database.collection<HistorySchema>("history");
pineafan4edb7762022-06-26 19:21:04 +0100541 }
542
Skyler Grey75ea9172022-08-06 10:22:23 +0100543 async create(
544 type: string,
545 guild: string,
546 user: Discord.User,
547 moderator: Discord.User | null,
548 reason: string | null,
pineafan3a02ea32022-08-11 21:35:04 +0100549 before?: string | null,
550 after?: string | null,
551 amount?: string | null
Skyler Grey75ea9172022-08-06 10:22:23 +0100552 ) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500553 // console.log("History create");
Skyler Greyda16adf2023-03-05 10:22:12 +0000554 await this.histories.insertOne(
555 {
556 type: type,
557 guild: guild,
558 user: user.id,
559 moderator: moderator ? moderator.id : null,
560 reason: reason,
561 occurredAt: new Date(),
562 before: before ?? null,
563 after: after ?? null,
564 amount: amount ?? null
565 },
566 collectionOptions
567 );
pineafan4edb7762022-06-26 19:21:04 +0100568 }
569
570 async read(guild: string, user: string, year: number) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500571 // console.log("History read");
Skyler Grey75ea9172022-08-06 10:22:23 +0100572 const entry = (await this.histories
573 .find({
574 guild: guild,
575 user: user,
576 occurredAt: {
577 $gte: new Date(year - 1, 11, 31, 23, 59, 59),
578 $lt: new Date(year + 1, 0, 1, 0, 0, 0)
579 }
580 })
581 .toArray()) as HistorySchema[];
pineafan4edb7762022-06-26 19:21:04 +0100582 return entry;
583 }
pineafane23c4ec2022-07-27 21:56:27 +0100584
585 async delete(guild: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500586 // console.log("History delete");
pineafane23c4ec2022-07-27 21:56:27 +0100587 await this.histories.deleteMany({ guild: guild });
588 }
pineafan4edb7762022-06-26 19:21:04 +0100589}
590
TheCodedProfb5e9d552023-01-29 15:43:26 -0500591interface ScanCacheSchema {
592 addedAt: Date;
593 hash: string;
594 data: boolean;
595 tags: string[];
596}
597
598export class ScanCache {
599 scanCache: Collection<ScanCacheSchema>;
600
601 constructor() {
602 this.scanCache = database.collection<ScanCacheSchema>("scanCache");
603 }
604
605 async read(hash: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500606 // console.log("ScanCache read");
TheCodedProfb5e9d552023-01-29 15:43:26 -0500607 return await this.scanCache.findOne({ hash: hash });
608 }
609
610 async write(hash: string, data: boolean, tags?: string[]) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500611 // console.log("ScanCache write");
Skyler Greyda16adf2023-03-05 10:22:12 +0000612 await this.scanCache.insertOne(
613 { hash: hash, data: data, tags: tags ?? [], addedAt: new Date() },
614 collectionOptions
615 );
TheCodedProfb5e9d552023-01-29 15:43:26 -0500616 }
617
618 async cleanup() {
TheCodedProff8ef7942023-03-03 15:32:32 -0500619 // console.log("ScanCache cleanup");
Skyler Greyda16adf2023-03-05 10:22:12 +0000620 await this.scanCache.deleteMany({
621 addedAt: { $lt: new Date(Date.now() - 1000 * 60 * 60 * 24 * 31) },
622 hash: { $not$text: "http" }
623 });
TheCodedProfb5e9d552023-01-29 15:43:26 -0500624 }
625}
626
PineaFan538d3752023-01-12 21:48:23 +0000627export class PerformanceTest {
628 performanceData: Collection<PerformanceDataSchema>;
629
630 constructor() {
631 this.performanceData = database.collection<PerformanceDataSchema>("performance");
632 }
633
634 async record(data: PerformanceDataSchema) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500635 // console.log("PerformanceTest record");
PineaFan538d3752023-01-12 21:48:23 +0000636 data.timestamp = new Date();
TheCodedProffaae5332023-03-01 18:16:05 -0500637 await this.performanceData.insertOne(data, collectionOptions);
PineaFan538d3752023-01-12 21:48:23 +0000638 }
639 async read() {
TheCodedProff8ef7942023-03-03 15:32:32 -0500640 // console.log("PerformanceTest read");
PineaFan538d3752023-01-12 21:48:23 +0000641 return await this.performanceData.find({}).toArray();
642 }
643}
644
645export interface PerformanceDataSchema {
646 timestamp?: Date;
647 discord: number;
648 databaseRead: number;
649 resources: {
650 cpu: number;
651 memory: number;
652 temperature: number;
Skyler Greyda16adf2023-03-05 10:22:12 +0000653 };
PineaFan538d3752023-01-12 21:48:23 +0000654}
655
pineafan4edb7762022-06-26 19:21:04 +0100656export class ModNotes {
657 modNotes: Collection<ModNoteSchema>;
pineafan4edb7762022-06-26 19:21:04 +0100658
pineafan3a02ea32022-08-11 21:35:04 +0100659 constructor() {
pineafan4edb7762022-06-26 19:21:04 +0100660 this.modNotes = database.collection<ModNoteSchema>("modNotes");
pineafan4edb7762022-06-26 19:21:04 +0100661 }
662
663 async create(guild: string, user: string, note: string | null) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500664 // console.log("ModNotes create");
Skyler Grey11236ba2022-08-08 21:13:33 +0100665 await this.modNotes.updateOne({ guild: guild, user: user }, { $set: { note: note } }, { upsert: true });
pineafan4edb7762022-06-26 19:21:04 +0100666 }
667
668 async read(guild: string, user: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500669 // console.log("ModNotes read");
pineafan63fc5e22022-08-04 22:04:10 +0100670 const entry = await this.modNotes.findOne({ guild: guild, user: user });
pineafan4edb7762022-06-26 19:21:04 +0100671 return entry?.note ?? null;
672 }
TheCodedProf267563a2023-01-21 17:00:57 -0500673
674 async delete(guild: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500675 // console.log("ModNotes delete");
TheCodedProf267563a2023-01-21 17:00:57 -0500676 await this.modNotes.deleteMany({ guild: guild });
677 }
pineafan4edb7762022-06-26 19:21:04 +0100678}
679
pineafan73a7c4a2022-07-24 10:38:04 +0100680export class Premium {
681 premium: Collection<PremiumSchema>;
Skyler Greyda16adf2023-03-05 10:22:12 +0000682 cache: Map<string, [boolean, string, number, boolean, Date]>; // Date indicates the time one hour after it was created
683 cacheTimeout = 1000 * 60 * 60; // 1 hour
pineafan4edb7762022-06-26 19:21:04 +0100684
pineafan3a02ea32022-08-11 21:35:04 +0100685 constructor() {
pineafan73a7c4a2022-07-24 10:38:04 +0100686 this.premium = database.collection<PremiumSchema>("premium");
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500687 this.cache = new Map<string, [boolean, string, number, boolean, Date]>();
pineafan4edb7762022-06-26 19:21:04 +0100688 }
689
TheCodedProf633866f2023-02-03 17:06:00 -0500690 async updateUser(user: string, level: number) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500691 // console.log("Premium updateUser");
Skyler Greyda16adf2023-03-05 10:22:12 +0000692 if (!(await this.userExists(user))) await this.createUser(user, level);
TheCodedProf633866f2023-02-03 17:06:00 -0500693 await this.premium.updateOne({ user: user }, { $set: { level: level } }, { upsert: true });
694 }
695
696 async userExists(user: string): Promise<boolean> {
TheCodedProff8ef7942023-03-03 15:32:32 -0500697 // console.log("Premium userExists");
TheCodedProf633866f2023-02-03 17:06:00 -0500698 const entry = await this.premium.findOne({ user: user });
699 return entry ? true : false;
700 }
TheCodedProf633866f2023-02-03 17:06:00 -0500701 async createUser(user: string, level: number) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500702 // console.log("Premium createUser");
TheCodedProffaae5332023-03-01 18:16:05 -0500703 await this.premium.insertOne({ user: user, appliesTo: [], level: level }, collectionOptions);
TheCodedProf633866f2023-02-03 17:06:00 -0500704 }
705
TheCodedProfaa3fe992023-02-25 21:53:09 -0500706 async hasPremium(guild: string): Promise<[boolean, string, number, boolean] | null> {
TheCodedProff8ef7942023-03-03 15:32:32 -0500707 // console.log("Premium hasPremium");
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500708 // [Has premium, user giving premium, level, is mod: if given automatically]
709 const cached = this.cache.get(guild);
710 if (cached && cached[4].getTime() < Date.now()) return [cached[0], cached[1], cached[2], cached[3]];
TheCodedProf94ff6de2023-02-22 17:47:26 -0500711 const entries = await this.premium.find({}).toArray();
Skyler Greyda16adf2023-03-05 10:22:12 +0000712 const members = (await client.guilds.fetch(guild)).members.cache;
713 for (const { user } of entries) {
TheCodedProf94ff6de2023-02-22 17:47:26 -0500714 const member = members.get(user);
Skyler Greyda16adf2023-03-05 10:22:12 +0000715 if (member) {
716 //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 -0500717 const modPerms = //TODO: Create list in config for perms
Skyler Greyda16adf2023-03-05 10:22:12 +0000718 member.permissions.has("Administrator") ||
719 member.permissions.has("ManageChannels") ||
720 member.permissions.has("ManageRoles") ||
721 member.permissions.has("ManageEmojisAndStickers") ||
722 member.permissions.has("ManageWebhooks") ||
723 member.permissions.has("ManageGuild") ||
724 member.permissions.has("KickMembers") ||
725 member.permissions.has("BanMembers") ||
726 member.permissions.has("ManageEvents") ||
727 member.permissions.has("ManageMessages") ||
728 member.permissions.has("ManageThreads");
729 const entry = entries.find((e) => e.user === member.id);
730 if (entry && entry.level === 3 && modPerms) {
731 this.cache.set(guild, [
732 true,
733 member.id,
734 entry.level,
735 true,
736 new Date(Date.now() + this.cacheTimeout)
737 ]);
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500738 return [true, member.id, entry.level, true];
739 }
TheCodedProf94ff6de2023-02-22 17:47:26 -0500740 }
741 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100742 const entry = await this.premium.findOne({
TheCodedProf94ff6de2023-02-22 17:47:26 -0500743 appliesTo: {
744 $elemMatch: {
745 $eq: guild
746 }
747 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100748 });
Skyler Greyda16adf2023-03-05 10:22:12 +0000749 this.cache.set(guild, [
750 entry ? true : false,
751 entry?.user ?? "",
752 entry?.level ?? 0,
753 false,
754 new Date(Date.now() + this.cacheTimeout)
755 ]);
TheCodedProfaa3fe992023-02-25 21:53:09 -0500756 return entry ? [true, entry.user, entry.level, false] : null;
TheCodedProf267563a2023-01-21 17:00:57 -0500757 }
758
TheCodedProf633866f2023-02-03 17:06:00 -0500759 async fetchUser(user: string): Promise<PremiumSchema | null> {
TheCodedProff8ef7942023-03-03 15:32:32 -0500760 // console.log("Premium fetchUser");
TheCodedProf267563a2023-01-21 17:00:57 -0500761 const entry = await this.premium.findOne({ user: user });
TheCodedProf633866f2023-02-03 17:06:00 -0500762 if (!entry) return null;
763 return entry;
764 }
765
TheCodedProf94ff6de2023-02-22 17:47:26 -0500766 async checkAllPremium(member?: GuildMember) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500767 // console.log("Premium checkAllPremium");
TheCodedProf633866f2023-02-03 17:06:00 -0500768 const entries = await this.premium.find({}).toArray();
Skyler Greyda16adf2023-03-05 10:22:12 +0000769 if (member) {
770 const entry = entries.find((e) => e.user === member.id);
771 if (entry) {
TheCodedProf94ff6de2023-02-22 17:47:26 -0500772 const expiresAt = entry.expiresAt;
Skyler Greyda16adf2023-03-05 10:22:12 +0000773 if (expiresAt) expiresAt < Date.now() ? await this.premium.deleteOne({ user: member.id }) : null;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500774 }
775 const roles = member.roles;
776 let level = 0;
777 if (roles.cache.has("1066468879309750313")) {
TheCodedProf633866f2023-02-03 17:06:00 -0500778 level = 99;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500779 } else if (roles.cache.has("1066465491713003520")) {
TheCodedProf633866f2023-02-03 17:06:00 -0500780 level = 1;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500781 } else if (roles.cache.has("1066439526496604194")) {
TheCodedProf633866f2023-02-03 17:06:00 -0500782 level = 2;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500783 } else if (roles.cache.has("1066464134322978912")) {
TheCodedProf633866f2023-02-03 17:06:00 -0500784 level = 3;
785 }
TheCodedProf94ff6de2023-02-22 17:47:26 -0500786 await this.updateUser(member.id, level);
TheCodedProf633866f2023-02-03 17:06:00 -0500787 if (level > 0) {
Skyler Greyda16adf2023-03-05 10:22:12 +0000788 await this.premium.updateOne({ user: member.id }, { $unset: { expiresAt: "" } });
TheCodedProf633866f2023-02-03 17:06:00 -0500789 } else {
Skyler Greyda16adf2023-03-05 10:22:12 +0000790 await this.premium.updateOne(
791 { user: member.id },
792 { $set: { expiresAt: Date.now() + 1000 * 60 * 60 * 24 * 3 } }
793 );
TheCodedProf94ff6de2023-02-22 17:47:26 -0500794 }
795 } else {
Skyler Greyda16adf2023-03-05 10:22:12 +0000796 const members = await (await client.guilds.fetch("684492926528651336")).members.fetch();
797 for (const { roles, id } of members.values()) {
798 const entry = entries.find((e) => e.user === id);
799 if (entry) {
TheCodedProf94ff6de2023-02-22 17:47:26 -0500800 const expiresAt = entry.expiresAt;
Skyler Greyda16adf2023-03-05 10:22:12 +0000801 if (expiresAt) expiresAt < Date.now() ? await this.premium.deleteOne({ user: id }) : null;
TheCodedProf94ff6de2023-02-22 17:47:26 -0500802 }
803 let level: number = 0;
804 if (roles.cache.has("1066468879309750313")) {
805 level = 99;
806 } else if (roles.cache.has("1066465491713003520")) {
807 level = 1;
808 } else if (roles.cache.has("1066439526496604194")) {
809 level = 2;
810 } else if (roles.cache.has("1066464134322978912")) {
811 level = 3;
812 }
813 await this.updateUser(id, level);
814 if (level > 0) {
Skyler Greyda16adf2023-03-05 10:22:12 +0000815 await this.premium.updateOne({ user: id }, { $unset: { expiresAt: "" } });
TheCodedProf94ff6de2023-02-22 17:47:26 -0500816 } else {
Skyler Greyda16adf2023-03-05 10:22:12 +0000817 await this.premium.updateOne(
818 { user: id },
819 { $set: { expiresAt: Date.now() + 1000 * 60 * 60 * 24 * 3 } }
820 );
TheCodedProf94ff6de2023-02-22 17:47:26 -0500821 }
TheCodedProf633866f2023-02-03 17:06:00 -0500822 }
823 }
TheCodedProf267563a2023-01-21 17:00:57 -0500824 }
825
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500826 async addPremium(user: string, guild: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500827 // console.log("Premium addPremium");
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500828 const { level } = (await this.fetchUser(user))!;
829 this.cache.set(guild, [true, user, level, false, new Date(Date.now() + this.cacheTimeout)]);
TheCodedProf267563a2023-01-21 17:00:57 -0500830 return this.premium.updateOne({ user: user }, { $addToSet: { appliesTo: guild } }, { upsert: true });
pineafan4edb7762022-06-26 19:21:04 +0100831 }
TheCodedProffc420b72023-01-24 17:14:38 -0500832
TheCodedProf48865eb2023-03-05 15:25:25 -0500833 async removePremium(user: string, guild: string) {
TheCodedProff8ef7942023-03-03 15:32:32 -0500834 // console.log("Premium removePremium");
TheCodedProf9c51a7e2023-02-27 17:11:13 -0500835 this.cache.set(guild, [false, "", 0, false, new Date(Date.now() + this.cacheTimeout)]);
TheCodedProf48865eb2023-03-05 15:25:25 -0500836 return await this.premium.updateOne({ user: user }, { $pull: { appliesTo: guild } });
TheCodedProffc420b72023-01-24 17:14:38 -0500837 }
pineafan4edb7762022-06-26 19:21:04 +0100838}
839
pineafan6fb3e072022-05-20 19:27:23 +0100840export interface GuildConfig {
Skyler Grey75ea9172022-08-06 10:22:23 +0100841 id: string;
842 version: number;
PineaFan100df682023-01-02 13:26:08 +0000843 singleEventNotifications: Record<string, boolean>;
pineafan6fb3e072022-05-20 19:27:23 +0100844 filters: {
845 images: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100846 NSFW: boolean;
847 size: boolean;
848 };
849 malware: boolean;
pineafan6fb3e072022-05-20 19:27:23 +0100850 wordFilter: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100851 enabled: boolean;
pineafan6fb3e072022-05-20 19:27:23 +0100852 words: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100853 strict: string[];
854 loose: string[];
855 };
pineafan6fb3e072022-05-20 19:27:23 +0100856 allowed: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100857 users: string[];
858 roles: string[];
859 channels: string[];
860 };
861 };
pineafan6fb3e072022-05-20 19:27:23 +0100862 invite: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100863 enabled: boolean;
PineaFan538d3752023-01-12 21:48:23 +0000864 allowed: {
865 channels: string[];
866 roles: string[];
867 users: string[];
868 };
Skyler Grey75ea9172022-08-06 10:22:23 +0100869 };
pineafan6fb3e072022-05-20 19:27:23 +0100870 pings: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100871 mass: number;
872 everyone: boolean;
873 roles: boolean;
pineafan6fb3e072022-05-20 19:27:23 +0100874 allowed: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100875 roles: string[];
876 rolesToMention: string[];
877 users: string[];
878 channels: string[];
879 };
880 };
TheCodedProfad0b8202023-02-14 14:27:09 -0500881 clean: {
882 channels: string[];
883 allowed: {
TheCodedProff8ef7942023-03-03 15:32:32 -0500884 users: string[];
TheCodedProfad0b8202023-02-14 14:27:09 -0500885 roles: string[];
Skyler Greyda16adf2023-03-05 10:22:12 +0000886 };
887 };
Skyler Grey75ea9172022-08-06 10:22:23 +0100888 };
TheCodedProfbaee2c12023-02-18 16:11:06 -0500889 autoPublish: {
890 enabled: boolean;
891 channels: string[];
Skyler Greyda16adf2023-03-05 10:22:12 +0000892 };
pineafan6fb3e072022-05-20 19:27:23 +0100893 welcome: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100894 enabled: boolean;
Skyler Grey75ea9172022-08-06 10:22:23 +0100895 role: string | null;
896 ping: string | null;
897 channel: string | null;
898 message: string | null;
899 };
900 stats: Record<string, { name: string; enabled: boolean }>;
pineafan6fb3e072022-05-20 19:27:23 +0100901 logging: {
902 logs: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100903 enabled: boolean;
904 channel: string | null;
Skyler Greyad002172022-08-16 18:48:26 +0100905 toLog: string;
Skyler Grey75ea9172022-08-06 10:22:23 +0100906 };
pineafan6fb3e072022-05-20 19:27:23 +0100907 staff: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100908 channel: string | null;
909 };
pineafan73a7c4a2022-07-24 10:38:04 +0100910 attachments: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100911 channel: string | null;
912 saved: Record<string, string>;
913 };
914 };
pineafan6fb3e072022-05-20 19:27:23 +0100915 verify: {
PineaFandf4996f2023-01-01 14:20:06 +0000916 enabled: boolean;
Skyler Grey75ea9172022-08-06 10:22:23 +0100917 role: string | null;
918 };
pineafan6fb3e072022-05-20 19:27:23 +0100919 tickets: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100920 enabled: boolean;
921 category: string | null;
Skyler Greyad002172022-08-16 18:48:26 +0100922 types: string;
923 customTypes: string[] | null;
Skyler Grey75ea9172022-08-06 10:22:23 +0100924 useCustom: boolean;
925 supportRole: string | null;
926 maxTickets: number;
927 };
pineafan6fb3e072022-05-20 19:27:23 +0100928 moderation: {
929 mute: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100930 timeout: boolean;
931 role: string | null;
932 text: string | null;
933 link: string | null;
934 };
pineafan6fb3e072022-05-20 19:27:23 +0100935 kick: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100936 text: string | null;
937 link: string | null;
938 };
pineafan6fb3e072022-05-20 19:27:23 +0100939 ban: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100940 text: string | null;
941 link: string | null;
942 };
pineafan6fb3e072022-05-20 19:27:23 +0100943 softban: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100944 text: string | null;
945 link: string | null;
946 };
pineafan6fb3e072022-05-20 19:27:23 +0100947 warn: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100948 text: string | null;
949 link: string | null;
950 };
pineafan6fb3e072022-05-20 19:27:23 +0100951 role: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100952 role: string | null;
TheCodedProfd9636e82023-01-17 22:13:06 -0500953 text: null;
954 link: null;
Skyler Grey75ea9172022-08-06 10:22:23 +0100955 };
PineaFane6ba7882023-01-18 20:41:16 +0000956 nick: {
957 text: string | null;
958 link: string | null;
Skyler Greyda16adf2023-03-05 10:22:12 +0000959 };
Skyler Grey75ea9172022-08-06 10:22:23 +0100960 };
pineafan6fb3e072022-05-20 19:27:23 +0100961 tracks: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100962 name: string;
963 retainPrevious: boolean;
964 nullable: boolean;
965 track: string[];
966 manageableBy: string[];
967 }[];
pineafan6fb3e072022-05-20 19:27:23 +0100968 roleMenu: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100969 enabled: boolean;
970 allowWebUI: boolean;
pineafan6fb3e072022-05-20 19:27:23 +0100971 options: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100972 name: string;
973 description: string;
974 min: number;
975 max: number;
pineafan6fb3e072022-05-20 19:27:23 +0100976 options: {
Skyler Grey75ea9172022-08-06 10:22:23 +0100977 name: string;
978 description: string | null;
979 role: string;
980 }[];
981 }[];
982 };
983 tags: Record<string, string>;
pineafan63fc5e22022-08-04 22:04:10 +0100984}
pineafan4edb7762022-06-26 19:21:04 +0100985
986export interface HistorySchema {
Skyler Grey75ea9172022-08-06 10:22:23 +0100987 type: string;
988 guild: string;
989 user: string;
990 moderator: string | null;
pineafan3a02ea32022-08-11 21:35:04 +0100991 reason: string | null;
Skyler Grey75ea9172022-08-06 10:22:23 +0100992 occurredAt: Date;
993 before: string | null;
994 after: string | null;
995 amount: string | null;
pineafan4edb7762022-06-26 19:21:04 +0100996}
997
998export interface ModNoteSchema {
Skyler Grey75ea9172022-08-06 10:22:23 +0100999 guild: string;
1000 user: string;
pineafan3a02ea32022-08-11 21:35:04 +01001001 note: string | null;
pineafan4edb7762022-06-26 19:21:04 +01001002}
1003
pineafan73a7c4a2022-07-24 10:38:04 +01001004export interface PremiumSchema {
Skyler Grey75ea9172022-08-06 10:22:23 +01001005 user: string;
1006 level: number;
Skyler Grey75ea9172022-08-06 10:22:23 +01001007 appliesTo: string[];
TheCodedProf633866f2023-02-03 17:06:00 -05001008 expiresAt?: number;
Skyler Grey75ea9172022-08-06 10:22:23 +01001009}