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