Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1 | import { |
| 2 | ButtonStyle, |
| 3 | CommandInteraction, |
| 4 | ComponentType, |
| 5 | GuildMember, |
| 6 | Message, |
| 7 | MessageComponentInteraction |
| 8 | } from "discord.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 9 | import type Discord from "discord.js"; |
| 10 | import { Collection, MongoClient } from "mongodb"; |
pineafan | a2e39c7 | 2023-02-21 18:37:32 +0000 | [diff] [blame] | 11 | import config from "../config/main.js"; |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 12 | import client from "../utils/client.js"; |
TheCodedProf | 088b1b2 | 2023-02-28 17:31:11 -0500 | [diff] [blame] | 13 | import * as crypto from "crypto"; |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 14 | import _ from "lodash"; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 15 | import defaultData from "../config/default.js"; |
TheCodedProf | 7527657 | 2023-03-04 13:49:16 -0500 | [diff] [blame] | 16 | |
TheCodedProf | faae533 | 2023-03-01 18:16:05 -0500 | [diff] [blame] | 17 | const username = encodeURIComponent(config.mongoOptions.username); |
| 18 | const password = encodeURIComponent(config.mongoOptions.password); |
Samuel Shuert | d66098b | 2023-03-04 14:05:26 -0500 | [diff] [blame] | 19 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 20 | const 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 | ); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 26 | await mongoClient.connect(); |
TheCodedProf | 8d577fa | 2023-03-01 13:06:40 -0500 | [diff] [blame] | 27 | const database = mongoClient.db(); |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 28 | |
TheCodedProf | 78b9033 | 2023-03-04 14:02:21 -0500 | [diff] [blame] | 29 | const collectionOptions = { authdb: config.mongoOptions.authSource, w: "majority" }; |
TheCodedProf | 75c51be | 2023-03-03 17:18:18 -0500 | [diff] [blame] | 30 | const getIV = () => crypto.randomBytes(16); |
TheCodedProf | faae533 | 2023-03-01 18:16:05 -0500 | [diff] [blame] | 31 | |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 32 | export class Guilds { |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 33 | guilds: Collection<GuildConfig>; |
TheCodedProf | 8a2d7cd | 2023-03-05 14:53:59 -0500 | [diff] [blame^] | 34 | oldGuilds: Collection<GuildConfig>; |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 35 | defaultData: GuildConfig; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 36 | |
| 37 | constructor() { |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 38 | this.guilds = database.collection<GuildConfig>("guilds"); |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 39 | this.defaultData = defaultData; |
TheCodedProf | 8a2d7cd | 2023-03-05 14:53:59 -0500 | [diff] [blame^] | 40 | 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 ?? {}; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 47 | } |
| 48 | |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 49 | async read(guild: string): Promise<GuildConfig> { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 50 | // console.log("Guild read") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 51 | const entry = await this.guilds.findOne({ id: guild }); |
TheCodedProf | 9f4cf9f | 2023-03-04 14:18:19 -0500 | [diff] [blame] | 52 | const data = _.cloneDeep(this.defaultData); |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 53 | return _.merge(data, entry ?? {}); |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 54 | } |
| 55 | |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 56 | async write(guild: string, set: object | null, unset: string[] | string = []) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 57 | // console.log("Guild write") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 58 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 59 | const uo: Record<string, any> = {}; |
| 60 | if (!Array.isArray(unset)) unset = [unset]; |
| 61 | for (const key of unset) { |
pineafan | 0bc0416 | 2022-07-25 17:22:26 +0100 | [diff] [blame] | 62 | uo[key] = null; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 63 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 64 | const out = { $set: {}, $unset: {} }; |
| 65 | if (set) out.$set = set; |
| 66 | if (unset.length) out.$unset = uo; |
pineafan | 0bc0416 | 2022-07-25 17:22:26 +0100 | [diff] [blame] | 67 | await this.guilds.updateOne({ id: guild }, out, { upsert: true }); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 68 | } |
| 69 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 70 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 71 | async append(guild: string, key: string, value: any) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 72 | // console.log("Guild append") |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 73 | if (Array.isArray(value)) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 74 | await this.guilds.updateOne( |
| 75 | { id: guild }, |
| 76 | { |
| 77 | $addToSet: { [key]: { $each: value } } |
| 78 | }, |
| 79 | { upsert: true } |
| 80 | ); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 81 | } else { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 82 | await this.guilds.updateOne( |
| 83 | { id: guild }, |
| 84 | { |
| 85 | $addToSet: { [key]: value } |
| 86 | }, |
| 87 | { upsert: true } |
| 88 | ); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 89 | } |
| 90 | } |
| 91 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 92 | async remove( |
| 93 | guild: string, |
| 94 | key: string, |
Skyler Grey | c634e2b | 2022-08-06 17:50:48 +0100 | [diff] [blame] | 95 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 96 | value: any, |
| 97 | innerKey?: string | null |
| 98 | ) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 99 | // console.log("Guild remove") |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 100 | if (innerKey) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 101 | await this.guilds.updateOne( |
| 102 | { id: guild }, |
| 103 | { |
| 104 | $pull: { [key]: { [innerKey]: { $eq: value } } } |
| 105 | }, |
| 106 | { upsert: true } |
| 107 | ); |
pineafan | 0bc0416 | 2022-07-25 17:22:26 +0100 | [diff] [blame] | 108 | } else if (Array.isArray(value)) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 109 | await this.guilds.updateOne( |
| 110 | { id: guild }, |
| 111 | { |
| 112 | $pullAll: { [key]: value } |
| 113 | }, |
| 114 | { upsert: true } |
| 115 | ); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 116 | } else { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 117 | await this.guilds.updateOne( |
| 118 | { id: guild }, |
| 119 | { |
| 120 | $pullAll: { [key]: [value] } |
| 121 | }, |
| 122 | { upsert: true } |
| 123 | ); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 124 | } |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 125 | } |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 126 | |
| 127 | async delete(guild: string) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 128 | // console.log("Guild delete") |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 129 | await this.guilds.deleteOne({ id: guild }); |
| 130 | } |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 131 | } |
| 132 | |
TheCodedProf | cfe8e9a | 2023-02-26 17:28:09 -0500 | [diff] [blame] | 133 | interface TranscriptEmbed { |
| 134 | title?: string; |
| 135 | description?: string; |
| 136 | fields?: { |
| 137 | name: string; |
| 138 | value: string; |
| 139 | inline: boolean; |
| 140 | }[]; |
| 141 | footer?: { |
| 142 | text: string; |
| 143 | iconURL?: string; |
| 144 | }; |
TheCodedProf | faae533 | 2023-03-01 18:16:05 -0500 | [diff] [blame] | 145 | color?: number; |
| 146 | timestamp?: string; |
| 147 | author?: { |
| 148 | name: string; |
| 149 | iconURL?: string; |
| 150 | url?: string; |
| 151 | }; |
TheCodedProf | cfe8e9a | 2023-02-26 17:28:09 -0500 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | interface TranscriptComponent { |
| 155 | type: number; |
| 156 | style?: ButtonStyle; |
| 157 | label?: string; |
| 158 | description?: string; |
| 159 | placeholder?: string; |
| 160 | emojiURL?: string; |
| 161 | } |
| 162 | |
| 163 | interface TranscriptAuthor { |
| 164 | username: string; |
| 165 | discriminator: number; |
| 166 | nickname?: string; |
| 167 | id: string; |
| 168 | iconURL?: string; |
| 169 | topRole: { |
| 170 | color: number; |
| 171 | badgeURL?: string; |
TheCodedProf | 088b1b2 | 2023-02-28 17:31:11 -0500 | [diff] [blame] | 172 | }; |
| 173 | bot: boolean; |
TheCodedProf | cfe8e9a | 2023-02-26 17:28:09 -0500 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | interface TranscriptAttachment { |
| 177 | url: string; |
| 178 | filename: string; |
| 179 | size: number; |
| 180 | log?: string; |
| 181 | } |
| 182 | |
| 183 | interface TranscriptMessage { |
| 184 | id: string; |
| 185 | author: TranscriptAuthor; |
| 186 | content?: string; |
| 187 | embeds?: TranscriptEmbed[]; |
| 188 | components?: TranscriptComponent[][]; |
| 189 | editedTimestamp?: number; |
| 190 | createdTimestamp: number; |
| 191 | flags?: string[]; |
| 192 | attachments?: TranscriptAttachment[]; |
| 193 | stickerURLs?: string[]; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 194 | referencedMessage?: string | [string, string, string]; // the message id, the channel id, the guild id |
TheCodedProf | cfe8e9a | 2023-02-26 17:28:09 -0500 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | interface TranscriptSchema { |
| 198 | code: string; |
| 199 | for: TranscriptAuthor; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 200 | type: "ticket" | "purge"; |
TheCodedProf | cfe8e9a | 2023-02-26 17:28:09 -0500 | [diff] [blame] | 201 | guild: string; |
| 202 | channel: string; |
| 203 | messages: TranscriptMessage[]; |
| 204 | createdTimestamp: number; |
| 205 | createdBy: TranscriptAuthor; |
| 206 | } |
| 207 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 208 | interface findDocSchema { |
| 209 | channelID: string; |
| 210 | messageID: string; |
| 211 | transcript: string; |
| 212 | } |
TheCodedProf | 003160f | 2023-03-04 17:09:40 -0500 | [diff] [blame] | 213 | |
TheCodedProf | cfe8e9a | 2023-02-26 17:28:09 -0500 | [diff] [blame] | 214 | export class Transcript { |
| 215 | transcripts: Collection<TranscriptSchema>; |
TheCodedProf | 003160f | 2023-03-04 17:09:40 -0500 | [diff] [blame] | 216 | messageToTranscript: Collection<findDocSchema>; |
TheCodedProf | cfe8e9a | 2023-02-26 17:28:09 -0500 | [diff] [blame] | 217 | |
| 218 | constructor() { |
| 219 | this.transcripts = database.collection<TranscriptSchema>("transcripts"); |
TheCodedProf | 003160f | 2023-03-04 17:09:40 -0500 | [diff] [blame] | 220 | this.messageToTranscript = database.collection<findDocSchema>("messageToTranscript"); |
| 221 | } |
| 222 | |
| 223 | async upload(data: findDocSchema) { |
| 224 | // console.log("Transcript upload") |
| 225 | await this.messageToTranscript.insertOne(data); |
TheCodedProf | cfe8e9a | 2023-02-26 17:28:09 -0500 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | async create(transcript: Omit<TranscriptSchema, "code">) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 229 | // console.log("Transcript create") |
TheCodedProf | cfe8e9a | 2023-02-26 17:28:09 -0500 | [diff] [blame] | 230 | let code; |
| 231 | do { |
TheCodedProf | 088b1b2 | 2023-02-28 17:31:11 -0500 | [diff] [blame] | 232 | code = crypto.randomBytes(64).toString("base64").replace(/=/g, "").replace(/\//g, "_").replace(/\+/g, "-"); |
TheCodedProf | cfe8e9a | 2023-02-26 17:28:09 -0500 | [diff] [blame] | 233 | } while (await this.transcripts.findOne({ code: code })); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 234 | const key = crypto |
| 235 | .randomBytes(32 ** 2) |
| 236 | .toString("base64") |
| 237 | .replace(/=/g, "") |
| 238 | .replace(/\//g, "_") |
| 239 | .replace(/\+/g, "-") |
| 240 | .substring(0, 32); |
TheCodedProf | 75c51be | 2023-03-03 17:18:18 -0500 | [diff] [blame] | 241 | const iv = getIV().toString("base64").replace(/=/g, "").replace(/\//g, "_").replace(/\+/g, "-"); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 242 | for (const message of transcript.messages) { |
| 243 | if (message.content) { |
TheCodedProf | 75c51be | 2023-03-03 17:18:18 -0500 | [diff] [blame] | 244 | const encCipher = crypto.createCipheriv("AES-256-CBC", key, iv); |
| 245 | message.content = encCipher.update(message.content, "utf8", "base64") + encCipher.final("base64"); |
| 246 | } |
| 247 | } |
TheCodedProf | cfe8e9a | 2023-02-26 17:28:09 -0500 | [diff] [blame] | 248 | |
TheCodedProf | faae533 | 2023-03-01 18:16:05 -0500 | [diff] [blame] | 249 | const doc = await this.transcripts.insertOne(Object.assign(transcript, { code: code }), collectionOptions); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 250 | if (doc.acknowledged) { |
| 251 | client.database.eventScheduler.schedule( |
| 252 | "deleteTranscript", |
| 253 | (Date.now() + 1000 * 60 * 60 * 24 * 7).toString(), |
| 254 | { guild: transcript.guild, code: code, iv: iv, key: key } |
| 255 | ); |
TheCodedProf | 003160f | 2023-03-04 17:09:40 -0500 | [diff] [blame] | 256 | return [code, key, iv]; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 257 | } else return [null, null, null]; |
TheCodedProf | cfe8e9a | 2023-02-26 17:28:09 -0500 | [diff] [blame] | 258 | } |
| 259 | |
TheCodedProf | 003160f | 2023-03-04 17:09:40 -0500 | [diff] [blame] | 260 | async delete(code: string) { |
| 261 | // console.log("Transcript delete") |
| 262 | await this.transcripts.deleteOne({ code: code }); |
TheCodedProf | 75c51be | 2023-03-03 17:18:18 -0500 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | async deleteAll(guild: string) { |
| 266 | // console.log("Transcript delete") |
| 267 | const filteredDocs = await this.transcripts.find({ guild: guild }).toArray(); |
| 268 | for (const doc of filteredDocs) { |
| 269 | await this.transcripts.deleteOne({ code: doc.code }); |
| 270 | } |
TheCodedProf | cfe8e9a | 2023-02-26 17:28:09 -0500 | [diff] [blame] | 271 | } |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 272 | |
TheCodedProf | 003160f | 2023-03-04 17:09:40 -0500 | [diff] [blame] | 273 | async readEncrypted(code: string) { |
| 274 | // console.log("Transcript read") |
| 275 | let doc: TranscriptSchema | null = await this.transcripts.findOne({ code: code }); |
| 276 | let findDoc: findDocSchema | null = null; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 277 | if (!doc) findDoc = await this.messageToTranscript.findOne({ transcript: code }); |
| 278 | if (findDoc) { |
| 279 | const message = await ( |
| 280 | client.channels.cache.get(findDoc.channelID) as Discord.TextBasedChannel | null |
| 281 | )?.messages.fetch(findDoc.messageID); |
| 282 | if (!message) return null; |
TheCodedProf | 003160f | 2023-03-04 17:09:40 -0500 | [diff] [blame] | 283 | const attachment = message.attachments.first(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 284 | if (!attachment) return null; |
TheCodedProf | 003160f | 2023-03-04 17:09:40 -0500 | [diff] [blame] | 285 | const transcript = (await fetch(attachment.url)).body; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 286 | if (!transcript) return null; |
TheCodedProf | 003160f | 2023-03-04 17:09:40 -0500 | [diff] [blame] | 287 | const reader = transcript.getReader(); |
| 288 | let data: Uint8Array | null = null; |
| 289 | let allPacketsReceived = false; |
| 290 | while (!allPacketsReceived) { |
| 291 | const { value, done } = await reader.read(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 292 | if (done) { |
| 293 | allPacketsReceived = true; |
| 294 | continue; |
| 295 | } |
| 296 | if (!data) { |
TheCodedProf | 003160f | 2023-03-04 17:09:40 -0500 | [diff] [blame] | 297 | data = value; |
| 298 | } else { |
| 299 | data = new Uint8Array(Buffer.concat([data, value])); |
| 300 | } |
| 301 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 302 | if (!data) return null; |
Skyler Grey | cf77140 | 2023-03-05 07:06:37 +0000 | [diff] [blame] | 303 | doc = JSON.parse(Buffer.from(data).toString()) as TranscriptSchema; |
TheCodedProf | 003160f | 2023-03-04 17:09:40 -0500 | [diff] [blame] | 304 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 305 | if (!doc) return null; |
TheCodedProf | 003160f | 2023-03-04 17:09:40 -0500 | [diff] [blame] | 306 | return doc; |
| 307 | } |
| 308 | |
| 309 | async read(code: string, key: string, iv: string) { |
| 310 | // console.log("Transcript read") |
| 311 | let doc: TranscriptSchema | null = await this.transcripts.findOne({ code: code }); |
| 312 | let findDoc: findDocSchema | null = null; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 313 | if (!doc) findDoc = await this.messageToTranscript.findOne({ transcript: code }); |
| 314 | if (findDoc) { |
| 315 | const message = await ( |
| 316 | client.channels.cache.get(findDoc.channelID) as Discord.TextBasedChannel | null |
| 317 | )?.messages.fetch(findDoc.messageID); |
| 318 | if (!message) return null; |
TheCodedProf | 003160f | 2023-03-04 17:09:40 -0500 | [diff] [blame] | 319 | const attachment = message.attachments.first(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 320 | if (!attachment) return null; |
TheCodedProf | 003160f | 2023-03-04 17:09:40 -0500 | [diff] [blame] | 321 | const transcript = (await fetch(attachment.url)).body; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 322 | if (!transcript) return null; |
TheCodedProf | 003160f | 2023-03-04 17:09:40 -0500 | [diff] [blame] | 323 | const reader = transcript.getReader(); |
| 324 | let data: Uint8Array | null = null; |
| 325 | // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, no-constant-condition |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 326 | while (true) { |
TheCodedProf | 003160f | 2023-03-04 17:09:40 -0500 | [diff] [blame] | 327 | const { value, done } = await reader.read(); |
| 328 | if (done) break; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 329 | if (!data) { |
TheCodedProf | 003160f | 2023-03-04 17:09:40 -0500 | [diff] [blame] | 330 | data = value; |
| 331 | } else { |
| 332 | data = new Uint8Array(Buffer.concat([data, value])); |
| 333 | } |
| 334 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 335 | if (!data) return null; |
Skyler Grey | cf77140 | 2023-03-05 07:06:37 +0000 | [diff] [blame] | 336 | doc = JSON.parse(Buffer.from(data).toString()) as TranscriptSchema; |
TheCodedProf | 003160f | 2023-03-04 17:09:40 -0500 | [diff] [blame] | 337 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 338 | if (!doc) return null; |
| 339 | for (const message of doc.messages) { |
| 340 | if (message.content) { |
TheCodedProf | 003160f | 2023-03-04 17:09:40 -0500 | [diff] [blame] | 341 | const decCipher = crypto.createDecipheriv("AES-256-CBC", key, iv); |
| 342 | message.content = decCipher.update(message.content, "base64", "utf8") + decCipher.final("utf8"); |
| 343 | } |
| 344 | } |
| 345 | return doc; |
| 346 | } |
| 347 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 348 | async createTranscript( |
| 349 | messages: Message[], |
| 350 | interaction: MessageComponentInteraction | CommandInteraction, |
| 351 | member: GuildMember |
| 352 | ) { |
| 353 | const interactionMember = await interaction.guild?.members.fetch(interaction.user.id); |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 354 | const newOut: Omit<TranscriptSchema, "code"> = { |
| 355 | type: "ticket", |
| 356 | for: { |
| 357 | username: member!.user.username, |
| 358 | discriminator: parseInt(member!.user.discriminator), |
| 359 | id: member!.user.id, |
| 360 | topRole: { |
| 361 | color: member!.roles.highest.color |
TheCodedProf | 088b1b2 | 2023-02-28 17:31:11 -0500 | [diff] [blame] | 362 | }, |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 363 | iconURL: member!.user.displayAvatarURL({ forceStatic: true }), |
TheCodedProf | 088b1b2 | 2023-02-28 17:31:11 -0500 | [diff] [blame] | 364 | bot: member!.user.bot |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 365 | }, |
| 366 | guild: interaction.guild!.id, |
| 367 | channel: interaction.channel!.id, |
| 368 | messages: [], |
| 369 | createdTimestamp: Date.now(), |
| 370 | createdBy: { |
| 371 | username: interaction.user.username, |
| 372 | discriminator: parseInt(interaction.user.discriminator), |
| 373 | id: interaction.user.id, |
| 374 | topRole: { |
| 375 | color: interactionMember?.roles.highest.color ?? 0x000000 |
TheCodedProf | 088b1b2 | 2023-02-28 17:31:11 -0500 | [diff] [blame] | 376 | }, |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 377 | iconURL: interaction.user.displayAvatarURL({ forceStatic: true }), |
TheCodedProf | 088b1b2 | 2023-02-28 17:31:11 -0500 | [diff] [blame] | 378 | bot: interaction.user.bot |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 379 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 380 | }; |
| 381 | if (member.nickname) newOut.for.nickname = member.nickname; |
| 382 | if (interactionMember?.roles.icon) newOut.createdBy.topRole.badgeURL = interactionMember.roles.icon.iconURL()!; |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 383 | messages.reverse().forEach((message) => { |
| 384 | const msg: TranscriptMessage = { |
| 385 | id: message.id, |
| 386 | author: { |
| 387 | username: message.author.username, |
| 388 | discriminator: parseInt(message.author.discriminator), |
| 389 | id: message.author.id, |
| 390 | topRole: { |
| 391 | color: message.member!.roles.highest.color |
TheCodedProf | 088b1b2 | 2023-02-28 17:31:11 -0500 | [diff] [blame] | 392 | }, |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 393 | iconURL: message.member!.user.displayAvatarURL({ forceStatic: true }), |
TheCodedProf | 088b1b2 | 2023-02-28 17:31:11 -0500 | [diff] [blame] | 394 | bot: message.author.bot |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 395 | }, |
| 396 | createdTimestamp: message.createdTimestamp |
| 397 | }; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 398 | if (message.member?.nickname) msg.author.nickname = message.member.nickname; |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 399 | if (message.member!.roles.icon) msg.author.topRole.badgeURL = message.member!.roles.icon.iconURL()!; |
| 400 | if (message.content) msg.content = message.content; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 401 | if (message.embeds.length > 0) |
| 402 | msg.embeds = message.embeds.map((embed) => { |
| 403 | const obj: TranscriptEmbed = {}; |
| 404 | if (embed.title) obj.title = embed.title; |
| 405 | if (embed.description) obj.description = embed.description; |
| 406 | if (embed.fields.length > 0) |
| 407 | obj.fields = embed.fields.map((field) => { |
| 408 | return { |
| 409 | name: field.name, |
| 410 | value: field.value, |
| 411 | inline: field.inline ?? false |
| 412 | }; |
| 413 | }); |
| 414 | if (embed.color) obj.color = embed.color; |
| 415 | if (embed.timestamp) obj.timestamp = embed.timestamp; |
| 416 | if (embed.footer) |
| 417 | obj.footer = { |
| 418 | text: embed.footer.text |
| 419 | }; |
| 420 | if (embed.footer?.iconURL) obj.footer!.iconURL = embed.footer.iconURL; |
| 421 | if (embed.author) |
| 422 | obj.author = { |
| 423 | name: embed.author.name |
| 424 | }; |
| 425 | if (embed.author?.iconURL) obj.author!.iconURL = embed.author.iconURL; |
| 426 | if (embed.author?.url) obj.author!.url = embed.author.url; |
| 427 | return obj; |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 428 | }); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 429 | if (message.components.length > 0) |
| 430 | msg.components = message.components.map((component) => |
| 431 | component.components.map((child) => { |
| 432 | const obj: TranscriptComponent = { |
| 433 | type: child.type |
| 434 | }; |
| 435 | if (child.type === ComponentType.Button) { |
| 436 | obj.style = child.style; |
| 437 | obj.label = child.label ?? ""; |
| 438 | } else if (child.type > 2) { |
| 439 | obj.placeholder = child.placeholder ?? ""; |
| 440 | } |
| 441 | return obj; |
| 442 | }) |
| 443 | ); |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 444 | if (message.editedTimestamp) msg.editedTimestamp = message.editedTimestamp; |
| 445 | msg.flags = message.flags.toArray(); |
| 446 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 447 | if (message.stickers.size > 0) msg.stickerURLs = message.stickers.map((sticker) => sticker.url); |
| 448 | if (message.reference) |
| 449 | msg.referencedMessage = [ |
| 450 | message.reference.guildId ?? "", |
| 451 | message.reference.channelId, |
| 452 | message.reference.messageId ?? "" |
| 453 | ]; |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 454 | newOut.messages.push(msg); |
| 455 | }); |
| 456 | return newOut; |
| 457 | } |
| 458 | |
| 459 | toHumanReadable(transcript: Omit<TranscriptSchema, "code">): string { |
| 460 | let out = ""; |
| 461 | for (const message of transcript.messages) { |
| 462 | if (message.referencedMessage) { |
| 463 | if (Array.isArray(message.referencedMessage)) { |
| 464 | out += `> [Crosspost From] ${message.referencedMessage[0]} in ${message.referencedMessage[1]} in ${message.referencedMessage[2]}\n`; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 465 | } else out += `> [Reply To] ${message.referencedMessage}\n`; |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 466 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 467 | out += `${message.author.nickname ?? message.author.username}#${message.author.discriminator} (${ |
| 468 | message.author.id |
| 469 | }) (${message.id})`; |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 470 | out += ` [${new Date(message.createdTimestamp).toISOString()}]`; |
| 471 | if (message.editedTimestamp) out += ` [Edited: ${new Date(message.editedTimestamp).toISOString()}]`; |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 472 | out += "\n"; |
| 473 | if (message.content) out += `[Content]\n${message.content}\n\n`; |
| 474 | if (message.embeds) { |
| 475 | for (const embed of message.embeds) { |
| 476 | out += `[Embed]\n`; |
| 477 | if (embed.title) out += `| Title: ${embed.title}\n`; |
| 478 | if (embed.description) out += `| Description: ${embed.description}\n`; |
| 479 | if (embed.fields) { |
| 480 | for (const field of embed.fields) { |
| 481 | out += `| Field: ${field.name} - ${field.value}\n`; |
| 482 | } |
| 483 | } |
| 484 | if (embed.footer) { |
| 485 | out += `|Footer: ${embed.footer.text}\n`; |
| 486 | } |
| 487 | out += "\n"; |
| 488 | } |
| 489 | } |
| 490 | if (message.components) { |
| 491 | for (const component of message.components) { |
| 492 | out += `[Component]\n`; |
| 493 | for (const button of component) { |
| 494 | out += `| Button: ${button.label ?? button.description}\n`; |
| 495 | } |
| 496 | out += "\n"; |
| 497 | } |
| 498 | } |
| 499 | if (message.attachments) { |
| 500 | for (const attachment of message.attachments) { |
| 501 | out += `[Attachment] ${attachment.filename} (${attachment.size} bytes) ${attachment.url}\n`; |
| 502 | } |
| 503 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 504 | out += "\n\n"; |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 505 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 506 | return out; |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 507 | } |
TheCodedProf | cfe8e9a | 2023-02-26 17:28:09 -0500 | [diff] [blame] | 508 | } |
| 509 | |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 510 | export class History { |
| 511 | histories: Collection<HistorySchema>; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 512 | |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 513 | constructor() { |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 514 | this.histories = database.collection<HistorySchema>("history"); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 515 | } |
| 516 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 517 | async create( |
| 518 | type: string, |
| 519 | guild: string, |
| 520 | user: Discord.User, |
| 521 | moderator: Discord.User | null, |
| 522 | reason: string | null, |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 523 | before?: string | null, |
| 524 | after?: string | null, |
| 525 | amount?: string | null |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 526 | ) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 527 | // console.log("History create"); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 528 | await this.histories.insertOne( |
| 529 | { |
| 530 | type: type, |
| 531 | guild: guild, |
| 532 | user: user.id, |
| 533 | moderator: moderator ? moderator.id : null, |
| 534 | reason: reason, |
| 535 | occurredAt: new Date(), |
| 536 | before: before ?? null, |
| 537 | after: after ?? null, |
| 538 | amount: amount ?? null |
| 539 | }, |
| 540 | collectionOptions |
| 541 | ); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | async read(guild: string, user: string, year: number) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 545 | // console.log("History read"); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 546 | const entry = (await this.histories |
| 547 | .find({ |
| 548 | guild: guild, |
| 549 | user: user, |
| 550 | occurredAt: { |
| 551 | $gte: new Date(year - 1, 11, 31, 23, 59, 59), |
| 552 | $lt: new Date(year + 1, 0, 1, 0, 0, 0) |
| 553 | } |
| 554 | }) |
| 555 | .toArray()) as HistorySchema[]; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 556 | return entry; |
| 557 | } |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 558 | |
| 559 | async delete(guild: string) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 560 | // console.log("History delete"); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 561 | await this.histories.deleteMany({ guild: guild }); |
| 562 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 563 | } |
| 564 | |
TheCodedProf | b5e9d55 | 2023-01-29 15:43:26 -0500 | [diff] [blame] | 565 | interface ScanCacheSchema { |
| 566 | addedAt: Date; |
| 567 | hash: string; |
| 568 | data: boolean; |
| 569 | tags: string[]; |
| 570 | } |
| 571 | |
| 572 | export class ScanCache { |
| 573 | scanCache: Collection<ScanCacheSchema>; |
| 574 | |
| 575 | constructor() { |
| 576 | this.scanCache = database.collection<ScanCacheSchema>("scanCache"); |
| 577 | } |
| 578 | |
| 579 | async read(hash: string) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 580 | // console.log("ScanCache read"); |
TheCodedProf | b5e9d55 | 2023-01-29 15:43:26 -0500 | [diff] [blame] | 581 | return await this.scanCache.findOne({ hash: hash }); |
| 582 | } |
| 583 | |
| 584 | async write(hash: string, data: boolean, tags?: string[]) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 585 | // console.log("ScanCache write"); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 586 | await this.scanCache.insertOne( |
| 587 | { hash: hash, data: data, tags: tags ?? [], addedAt: new Date() }, |
| 588 | collectionOptions |
| 589 | ); |
TheCodedProf | b5e9d55 | 2023-01-29 15:43:26 -0500 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | async cleanup() { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 593 | // console.log("ScanCache cleanup"); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 594 | await this.scanCache.deleteMany({ |
| 595 | addedAt: { $lt: new Date(Date.now() - 1000 * 60 * 60 * 24 * 31) }, |
| 596 | hash: { $not$text: "http" } |
| 597 | }); |
TheCodedProf | b5e9d55 | 2023-01-29 15:43:26 -0500 | [diff] [blame] | 598 | } |
| 599 | } |
| 600 | |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 601 | export class PerformanceTest { |
| 602 | performanceData: Collection<PerformanceDataSchema>; |
| 603 | |
| 604 | constructor() { |
| 605 | this.performanceData = database.collection<PerformanceDataSchema>("performance"); |
| 606 | } |
| 607 | |
| 608 | async record(data: PerformanceDataSchema) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 609 | // console.log("PerformanceTest record"); |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 610 | data.timestamp = new Date(); |
TheCodedProf | faae533 | 2023-03-01 18:16:05 -0500 | [diff] [blame] | 611 | await this.performanceData.insertOne(data, collectionOptions); |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 612 | } |
| 613 | async read() { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 614 | // console.log("PerformanceTest read"); |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 615 | return await this.performanceData.find({}).toArray(); |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | export interface PerformanceDataSchema { |
| 620 | timestamp?: Date; |
| 621 | discord: number; |
| 622 | databaseRead: number; |
| 623 | resources: { |
| 624 | cpu: number; |
| 625 | memory: number; |
| 626 | temperature: number; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 627 | }; |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 628 | } |
| 629 | |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 630 | export class ModNotes { |
| 631 | modNotes: Collection<ModNoteSchema>; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 632 | |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 633 | constructor() { |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 634 | this.modNotes = database.collection<ModNoteSchema>("modNotes"); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | async create(guild: string, user: string, note: string | null) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 638 | // console.log("ModNotes create"); |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 639 | await this.modNotes.updateOne({ guild: guild, user: user }, { $set: { note: note } }, { upsert: true }); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | async read(guild: string, user: string) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 643 | // console.log("ModNotes read"); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 644 | const entry = await this.modNotes.findOne({ guild: guild, user: user }); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 645 | return entry?.note ?? null; |
| 646 | } |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 647 | |
| 648 | async delete(guild: string) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 649 | // console.log("ModNotes delete"); |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 650 | await this.modNotes.deleteMany({ guild: guild }); |
| 651 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 652 | } |
| 653 | |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 654 | export class Premium { |
| 655 | premium: Collection<PremiumSchema>; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 656 | cache: Map<string, [boolean, string, number, boolean, Date]>; // Date indicates the time one hour after it was created |
| 657 | cacheTimeout = 1000 * 60 * 60; // 1 hour |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 658 | |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 659 | constructor() { |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 660 | this.premium = database.collection<PremiumSchema>("premium"); |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 661 | this.cache = new Map<string, [boolean, string, number, boolean, Date]>(); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 662 | } |
| 663 | |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 664 | async updateUser(user: string, level: number) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 665 | // console.log("Premium updateUser"); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 666 | if (!(await this.userExists(user))) await this.createUser(user, level); |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 667 | await this.premium.updateOne({ user: user }, { $set: { level: level } }, { upsert: true }); |
| 668 | } |
| 669 | |
| 670 | async userExists(user: string): Promise<boolean> { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 671 | // console.log("Premium userExists"); |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 672 | const entry = await this.premium.findOne({ user: user }); |
| 673 | return entry ? true : false; |
| 674 | } |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 675 | async createUser(user: string, level: number) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 676 | // console.log("Premium createUser"); |
TheCodedProf | faae533 | 2023-03-01 18:16:05 -0500 | [diff] [blame] | 677 | await this.premium.insertOne({ user: user, appliesTo: [], level: level }, collectionOptions); |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 678 | } |
| 679 | |
TheCodedProf | aa3fe99 | 2023-02-25 21:53:09 -0500 | [diff] [blame] | 680 | async hasPremium(guild: string): Promise<[boolean, string, number, boolean] | null> { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 681 | // console.log("Premium hasPremium"); |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 682 | // [Has premium, user giving premium, level, is mod: if given automatically] |
| 683 | const cached = this.cache.get(guild); |
| 684 | if (cached && cached[4].getTime() < Date.now()) return [cached[0], cached[1], cached[2], cached[3]]; |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 685 | const entries = await this.premium.find({}).toArray(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 686 | const members = (await client.guilds.fetch(guild)).members.cache; |
| 687 | for (const { user } of entries) { |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 688 | const member = members.get(user); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 689 | if (member) { |
| 690 | //TODO: Notify user if they've given premium to a server that has since gotten premium via a mod. |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 691 | const modPerms = //TODO: Create list in config for perms |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 692 | member.permissions.has("Administrator") || |
| 693 | member.permissions.has("ManageChannels") || |
| 694 | member.permissions.has("ManageRoles") || |
| 695 | member.permissions.has("ManageEmojisAndStickers") || |
| 696 | member.permissions.has("ManageWebhooks") || |
| 697 | member.permissions.has("ManageGuild") || |
| 698 | member.permissions.has("KickMembers") || |
| 699 | member.permissions.has("BanMembers") || |
| 700 | member.permissions.has("ManageEvents") || |
| 701 | member.permissions.has("ManageMessages") || |
| 702 | member.permissions.has("ManageThreads"); |
| 703 | const entry = entries.find((e) => e.user === member.id); |
| 704 | if (entry && entry.level === 3 && modPerms) { |
| 705 | this.cache.set(guild, [ |
| 706 | true, |
| 707 | member.id, |
| 708 | entry.level, |
| 709 | true, |
| 710 | new Date(Date.now() + this.cacheTimeout) |
| 711 | ]); |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 712 | return [true, member.id, entry.level, true]; |
| 713 | } |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 714 | } |
| 715 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 716 | const entry = await this.premium.findOne({ |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 717 | appliesTo: { |
| 718 | $elemMatch: { |
| 719 | $eq: guild |
| 720 | } |
| 721 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 722 | }); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 723 | this.cache.set(guild, [ |
| 724 | entry ? true : false, |
| 725 | entry?.user ?? "", |
| 726 | entry?.level ?? 0, |
| 727 | false, |
| 728 | new Date(Date.now() + this.cacheTimeout) |
| 729 | ]); |
TheCodedProf | aa3fe99 | 2023-02-25 21:53:09 -0500 | [diff] [blame] | 730 | return entry ? [true, entry.user, entry.level, false] : null; |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 731 | } |
| 732 | |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 733 | async fetchUser(user: string): Promise<PremiumSchema | null> { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 734 | // console.log("Premium fetchUser"); |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 735 | const entry = await this.premium.findOne({ user: user }); |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 736 | if (!entry) return null; |
| 737 | return entry; |
| 738 | } |
| 739 | |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 740 | async checkAllPremium(member?: GuildMember) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 741 | // console.log("Premium checkAllPremium"); |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 742 | const entries = await this.premium.find({}).toArray(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 743 | if (member) { |
| 744 | const entry = entries.find((e) => e.user === member.id); |
| 745 | if (entry) { |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 746 | const expiresAt = entry.expiresAt; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 747 | if (expiresAt) expiresAt < Date.now() ? await this.premium.deleteOne({ user: member.id }) : null; |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 748 | } |
| 749 | const roles = member.roles; |
| 750 | let level = 0; |
| 751 | if (roles.cache.has("1066468879309750313")) { |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 752 | level = 99; |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 753 | } else if (roles.cache.has("1066465491713003520")) { |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 754 | level = 1; |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 755 | } else if (roles.cache.has("1066439526496604194")) { |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 756 | level = 2; |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 757 | } else if (roles.cache.has("1066464134322978912")) { |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 758 | level = 3; |
| 759 | } |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 760 | await this.updateUser(member.id, level); |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 761 | if (level > 0) { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 762 | await this.premium.updateOne({ user: member.id }, { $unset: { expiresAt: "" } }); |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 763 | } else { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 764 | await this.premium.updateOne( |
| 765 | { user: member.id }, |
| 766 | { $set: { expiresAt: Date.now() + 1000 * 60 * 60 * 24 * 3 } } |
| 767 | ); |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 768 | } |
| 769 | } else { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 770 | const members = await (await client.guilds.fetch("684492926528651336")).members.fetch(); |
| 771 | for (const { roles, id } of members.values()) { |
| 772 | const entry = entries.find((e) => e.user === id); |
| 773 | if (entry) { |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 774 | const expiresAt = entry.expiresAt; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 775 | if (expiresAt) expiresAt < Date.now() ? await this.premium.deleteOne({ user: id }) : null; |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 776 | } |
| 777 | let level: number = 0; |
| 778 | if (roles.cache.has("1066468879309750313")) { |
| 779 | level = 99; |
| 780 | } else if (roles.cache.has("1066465491713003520")) { |
| 781 | level = 1; |
| 782 | } else if (roles.cache.has("1066439526496604194")) { |
| 783 | level = 2; |
| 784 | } else if (roles.cache.has("1066464134322978912")) { |
| 785 | level = 3; |
| 786 | } |
| 787 | await this.updateUser(id, level); |
| 788 | if (level > 0) { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 789 | await this.premium.updateOne({ user: id }, { $unset: { expiresAt: "" } }); |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 790 | } else { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 791 | await this.premium.updateOne( |
| 792 | { user: id }, |
| 793 | { $set: { expiresAt: Date.now() + 1000 * 60 * 60 * 24 * 3 } } |
| 794 | ); |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 795 | } |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 796 | } |
| 797 | } |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 798 | } |
| 799 | |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 800 | async addPremium(user: string, guild: string) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 801 | // console.log("Premium addPremium"); |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 802 | const { level } = (await this.fetchUser(user))!; |
| 803 | this.cache.set(guild, [true, user, level, false, new Date(Date.now() + this.cacheTimeout)]); |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 804 | return this.premium.updateOne({ user: user }, { $addToSet: { appliesTo: guild } }, { upsert: true }); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 805 | } |
TheCodedProf | fc420b7 | 2023-01-24 17:14:38 -0500 | [diff] [blame] | 806 | |
| 807 | removePremium(user: string, guild: string) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 808 | // console.log("Premium removePremium"); |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 809 | this.cache.set(guild, [false, "", 0, false, new Date(Date.now() + this.cacheTimeout)]); |
TheCodedProf | fc420b7 | 2023-01-24 17:14:38 -0500 | [diff] [blame] | 810 | return this.premium.updateOne({ user: user }, { $pull: { appliesTo: guild } }); |
| 811 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 812 | } |
| 813 | |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 814 | export interface GuildConfig { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 815 | id: string; |
| 816 | version: number; |
PineaFan | 100df68 | 2023-01-02 13:26:08 +0000 | [diff] [blame] | 817 | singleEventNotifications: Record<string, boolean>; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 818 | filters: { |
| 819 | images: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 820 | NSFW: boolean; |
| 821 | size: boolean; |
| 822 | }; |
| 823 | malware: boolean; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 824 | wordFilter: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 825 | enabled: boolean; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 826 | words: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 827 | strict: string[]; |
| 828 | loose: string[]; |
| 829 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 830 | allowed: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 831 | users: string[]; |
| 832 | roles: string[]; |
| 833 | channels: string[]; |
| 834 | }; |
| 835 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 836 | invite: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 837 | enabled: boolean; |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 838 | allowed: { |
| 839 | channels: string[]; |
| 840 | roles: string[]; |
| 841 | users: string[]; |
| 842 | }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 843 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 844 | pings: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 845 | mass: number; |
| 846 | everyone: boolean; |
| 847 | roles: boolean; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 848 | allowed: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 849 | roles: string[]; |
| 850 | rolesToMention: string[]; |
| 851 | users: string[]; |
| 852 | channels: string[]; |
| 853 | }; |
| 854 | }; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 855 | clean: { |
| 856 | channels: string[]; |
| 857 | allowed: { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 858 | users: string[]; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 859 | roles: string[]; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 860 | }; |
| 861 | }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 862 | }; |
TheCodedProf | baee2c1 | 2023-02-18 16:11:06 -0500 | [diff] [blame] | 863 | autoPublish: { |
| 864 | enabled: boolean; |
| 865 | channels: string[]; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 866 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 867 | welcome: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 868 | enabled: boolean; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 869 | role: string | null; |
| 870 | ping: string | null; |
| 871 | channel: string | null; |
| 872 | message: string | null; |
| 873 | }; |
| 874 | stats: Record<string, { name: string; enabled: boolean }>; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 875 | logging: { |
| 876 | logs: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 877 | enabled: boolean; |
| 878 | channel: string | null; |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 879 | toLog: string; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 880 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 881 | staff: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 882 | channel: string | null; |
| 883 | }; |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 884 | attachments: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 885 | channel: string | null; |
| 886 | saved: Record<string, string>; |
| 887 | }; |
| 888 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 889 | verify: { |
PineaFan | df4996f | 2023-01-01 14:20:06 +0000 | [diff] [blame] | 890 | enabled: boolean; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 891 | role: string | null; |
| 892 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 893 | tickets: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 894 | enabled: boolean; |
| 895 | category: string | null; |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 896 | types: string; |
| 897 | customTypes: string[] | null; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 898 | useCustom: boolean; |
| 899 | supportRole: string | null; |
| 900 | maxTickets: number; |
| 901 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 902 | moderation: { |
| 903 | mute: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 904 | timeout: boolean; |
| 905 | role: string | null; |
| 906 | text: string | null; |
| 907 | link: string | null; |
| 908 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 909 | kick: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 910 | text: string | null; |
| 911 | link: string | null; |
| 912 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 913 | ban: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 914 | text: string | null; |
| 915 | link: string | null; |
| 916 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 917 | softban: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 918 | text: string | null; |
| 919 | link: string | null; |
| 920 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 921 | warn: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 922 | text: string | null; |
| 923 | link: string | null; |
| 924 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 925 | role: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 926 | role: string | null; |
TheCodedProf | d9636e8 | 2023-01-17 22:13:06 -0500 | [diff] [blame] | 927 | text: null; |
| 928 | link: null; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 929 | }; |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 930 | nick: { |
| 931 | text: string | null; |
| 932 | link: string | null; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 933 | }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 934 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 935 | tracks: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 936 | name: string; |
| 937 | retainPrevious: boolean; |
| 938 | nullable: boolean; |
| 939 | track: string[]; |
| 940 | manageableBy: string[]; |
| 941 | }[]; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 942 | roleMenu: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 943 | enabled: boolean; |
| 944 | allowWebUI: boolean; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 945 | options: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 946 | name: string; |
| 947 | description: string; |
| 948 | min: number; |
| 949 | max: number; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 950 | options: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 951 | name: string; |
| 952 | description: string | null; |
| 953 | role: string; |
| 954 | }[]; |
| 955 | }[]; |
| 956 | }; |
| 957 | tags: Record<string, string>; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 958 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 959 | |
| 960 | export interface HistorySchema { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 961 | type: string; |
| 962 | guild: string; |
| 963 | user: string; |
| 964 | moderator: string | null; |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 965 | reason: string | null; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 966 | occurredAt: Date; |
| 967 | before: string | null; |
| 968 | after: string | null; |
| 969 | amount: string | null; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | export interface ModNoteSchema { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 973 | guild: string; |
| 974 | user: string; |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 975 | note: string | null; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 976 | } |
| 977 | |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 978 | export interface PremiumSchema { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 979 | user: string; |
| 980 | level: number; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 981 | appliesTo: string[]; |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 982 | expiresAt?: number; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 983 | } |