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