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