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