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