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