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