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