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