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