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 |
Skyler Grey | 2e13b6b | 2023-06-14 19:59:56 +0200 | [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 ?? ""; |
pineafan | 435a878 | 2023-06-24 12:45:58 +0100 | [diff] [blame^] | 474 | } else if ( |
| 475 | child.type === ComponentType.StringSelect || |
| 476 | child.type === ComponentType.UserSelect || |
| 477 | child.type === ComponentType.ChannelSelect || |
| 478 | child.type === ComponentType.RoleSelect |
| 479 | ) { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 480 | obj.placeholder = child.placeholder ?? ""; |
| 481 | } |
| 482 | return obj; |
| 483 | }) |
| 484 | ); |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 485 | if (message.editedTimestamp) msg.editedTimestamp = message.editedTimestamp; |
| 486 | msg.flags = message.flags.toArray(); |
| 487 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 488 | if (message.stickers.size > 0) msg.stickerURLs = message.stickers.map((sticker) => sticker.url); |
| 489 | if (message.reference) |
| 490 | msg.referencedMessage = [ |
| 491 | message.reference.guildId ?? "", |
| 492 | message.reference.channelId, |
| 493 | message.reference.messageId ?? "" |
| 494 | ]; |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 495 | newOut.messages.push(msg); |
| 496 | }); |
| 497 | return newOut; |
| 498 | } |
| 499 | |
| 500 | toHumanReadable(transcript: Omit<TranscriptSchema, "code">): string { |
| 501 | let out = ""; |
| 502 | for (const message of transcript.messages) { |
| 503 | if (message.referencedMessage) { |
| 504 | if (Array.isArray(message.referencedMessage)) { |
| 505 | 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] | 506 | } else out += `> [Reply To] ${message.referencedMessage}\n`; |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 507 | } |
pineafan | cfb149f | 2023-05-28 15:46:30 +0100 | [diff] [blame] | 508 | out += `${message.author.nickname ?? message.author.username} (${message.author.id}) (${message.id})`; |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 509 | out += ` [${new Date(message.createdTimestamp).toISOString()}]`; |
| 510 | if (message.editedTimestamp) out += ` [Edited: ${new Date(message.editedTimestamp).toISOString()}]`; |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 511 | out += "\n"; |
| 512 | if (message.content) out += `[Content]\n${message.content}\n\n`; |
| 513 | if (message.embeds) { |
| 514 | for (const embed of message.embeds) { |
| 515 | out += `[Embed]\n`; |
| 516 | if (embed.title) out += `| Title: ${embed.title}\n`; |
| 517 | if (embed.description) out += `| Description: ${embed.description}\n`; |
| 518 | if (embed.fields) { |
| 519 | for (const field of embed.fields) { |
| 520 | out += `| Field: ${field.name} - ${field.value}\n`; |
| 521 | } |
| 522 | } |
| 523 | if (embed.footer) { |
| 524 | out += `|Footer: ${embed.footer.text}\n`; |
| 525 | } |
| 526 | out += "\n"; |
| 527 | } |
| 528 | } |
| 529 | if (message.components) { |
| 530 | for (const component of message.components) { |
| 531 | out += `[Component]\n`; |
| 532 | for (const button of component) { |
| 533 | out += `| Button: ${button.label ?? button.description}\n`; |
| 534 | } |
| 535 | out += "\n"; |
| 536 | } |
| 537 | } |
| 538 | if (message.attachments) { |
| 539 | for (const attachment of message.attachments) { |
| 540 | out += `[Attachment] ${attachment.filename} (${attachment.size} bytes) ${attachment.url}\n`; |
| 541 | } |
| 542 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 543 | out += "\n\n"; |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 544 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 545 | return out; |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 546 | } |
TheCodedProf | cfe8e9a | 2023-02-26 17:28:09 -0500 | [diff] [blame] | 547 | } |
| 548 | |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 549 | export class History { |
| 550 | histories: Collection<HistorySchema>; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 551 | |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 552 | constructor() { |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 553 | this.histories = database.collection<HistorySchema>("history"); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 554 | } |
| 555 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 556 | async create( |
| 557 | type: string, |
| 558 | guild: string, |
| 559 | user: Discord.User, |
| 560 | moderator: Discord.User | null, |
| 561 | reason: string | null, |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 562 | before?: string | null, |
| 563 | after?: string | null, |
| 564 | amount?: string | null |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 565 | ) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 566 | // console.log("History create"); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 567 | await this.histories.insertOne( |
| 568 | { |
| 569 | type: type, |
| 570 | guild: guild, |
| 571 | user: user.id, |
| 572 | moderator: moderator ? moderator.id : null, |
| 573 | reason: reason, |
| 574 | occurredAt: new Date(), |
| 575 | before: before ?? null, |
| 576 | after: after ?? null, |
| 577 | amount: amount ?? null |
| 578 | }, |
| 579 | collectionOptions |
| 580 | ); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | async read(guild: string, user: string, year: number) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 584 | // console.log("History read"); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 585 | const entry = (await this.histories |
| 586 | .find({ |
| 587 | guild: guild, |
| 588 | user: user, |
| 589 | occurredAt: { |
| 590 | $gte: new Date(year - 1, 11, 31, 23, 59, 59), |
| 591 | $lt: new Date(year + 1, 0, 1, 0, 0, 0) |
| 592 | } |
| 593 | }) |
| 594 | .toArray()) as HistorySchema[]; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 595 | return entry; |
| 596 | } |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 597 | |
| 598 | async delete(guild: string) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 599 | // console.log("History delete"); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 600 | await this.histories.deleteMany({ guild: guild }); |
| 601 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 602 | } |
| 603 | |
TheCodedProf | b5e9d55 | 2023-01-29 15:43:26 -0500 | [diff] [blame] | 604 | interface ScanCacheSchema { |
| 605 | addedAt: Date; |
| 606 | hash: string; |
Skyler Grey | 1443271 | 2023-03-07 23:40:50 +0000 | [diff] [blame] | 607 | nsfw?: boolean; |
| 608 | malware?: boolean; |
| 609 | bad_link?: boolean; |
Skyler Grey | d115731 | 2023-03-08 10:07:38 +0000 | [diff] [blame] | 610 | tags?: string[]; |
TheCodedProf | b5e9d55 | 2023-01-29 15:43:26 -0500 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | export class ScanCache { |
| 614 | scanCache: Collection<ScanCacheSchema>; |
| 615 | |
| 616 | constructor() { |
| 617 | this.scanCache = database.collection<ScanCacheSchema>("scanCache"); |
| 618 | } |
| 619 | |
| 620 | async read(hash: string) { |
| 621 | return await this.scanCache.findOne({ hash: hash }); |
| 622 | } |
| 623 | |
Skyler Grey | 1443271 | 2023-03-07 23:40:50 +0000 | [diff] [blame] | 624 | async write(hash: string, type: "nsfw" | "malware" | "bad_link", data: boolean, tags?: string[]) { |
TheCodedProf | 21d4b0f | 2023-04-22 21:02:51 -0400 | [diff] [blame] | 625 | // await this.scanCache.insertOne( |
| 626 | // { hash: hash, [type]: data, tags: tags ?? [], addedAt: new Date() }, |
| 627 | // collectionOptions |
TheCodedProf | 3be348c | 2023-04-22 20:59:14 -0400 | [diff] [blame] | 628 | // ); |
TheCodedProf | 21d4b0f | 2023-04-22 21:02:51 -0400 | [diff] [blame] | 629 | await this.scanCache.updateOne( |
| 630 | { hash: hash }, |
| 631 | { |
| 632 | $set: (() => { |
| 633 | switch (type) { |
| 634 | case "nsfw": { |
| 635 | return { nsfw: data, addedAt: new Date() }; |
| 636 | } |
| 637 | case "malware": { |
| 638 | return { malware: data, addedAt: new Date() }; |
| 639 | } |
| 640 | case "bad_link": { |
| 641 | return { bad_link: data, tags: tags ?? [], addedAt: new Date() }; |
| 642 | } |
| 643 | default: { |
| 644 | throw new Error("Invalid type"); |
| 645 | } |
| 646 | } |
| 647 | })() |
| 648 | // No you can't just do { [type]: data }, yes it's a typescript error, no I don't know how to fix it |
| 649 | // cleanly, yes it would be marginally more elegant, no it's not essential, yes I'd be happy to review |
| 650 | // PRs that did improve this snippet |
| 651 | // Made an attempt... Gave up... Just Leave It |
| 652 | // Counter: 2 |
| 653 | }, |
| 654 | Object.assign({ upsert: true }, collectionOptions) |
| 655 | ); |
TheCodedProf | b5e9d55 | 2023-01-29 15:43:26 -0500 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | async cleanup() { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 659 | // console.log("ScanCache cleanup"); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 660 | await this.scanCache.deleteMany({ |
| 661 | addedAt: { $lt: new Date(Date.now() - 1000 * 60 * 60 * 24 * 31) }, |
| 662 | hash: { $not$text: "http" } |
| 663 | }); |
TheCodedProf | b5e9d55 | 2023-01-29 15:43:26 -0500 | [diff] [blame] | 664 | } |
| 665 | } |
| 666 | |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 667 | export class PerformanceTest { |
| 668 | performanceData: Collection<PerformanceDataSchema>; |
| 669 | |
| 670 | constructor() { |
| 671 | this.performanceData = database.collection<PerformanceDataSchema>("performance"); |
| 672 | } |
| 673 | |
| 674 | async record(data: PerformanceDataSchema) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 675 | // console.log("PerformanceTest record"); |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 676 | data.timestamp = new Date(); |
TheCodedProf | faae533 | 2023-03-01 18:16:05 -0500 | [diff] [blame] | 677 | await this.performanceData.insertOne(data, collectionOptions); |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 678 | } |
| 679 | async read() { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 680 | // console.log("PerformanceTest read"); |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 681 | return await this.performanceData.find({}).toArray(); |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | export interface PerformanceDataSchema { |
| 686 | timestamp?: Date; |
| 687 | discord: number; |
| 688 | databaseRead: number; |
| 689 | resources: { |
| 690 | cpu: number; |
| 691 | memory: number; |
| 692 | temperature: number; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 693 | }; |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 694 | } |
| 695 | |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 696 | export class ModNotes { |
| 697 | modNotes: Collection<ModNoteSchema>; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 698 | |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 699 | constructor() { |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 700 | this.modNotes = database.collection<ModNoteSchema>("modNotes"); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 701 | } |
| 702 | |
TheCodedProf | c016f9f | 2023-04-23 16:01:38 -0400 | [diff] [blame] | 703 | async flag(guild: string, user: string, flag: FlagColors | null) { |
| 704 | const modNote = await this.modNotes.findOne({ guild: guild, user: user }); |
| 705 | modNote |
| 706 | ? await this.modNotes.updateOne({ guild: guild, user: user }, { $set: { flag: flag } }, collectionOptions) |
| 707 | : await this.modNotes.insertOne({ guild: guild, user: user, note: null, flag: flag }, collectionOptions); |
| 708 | } |
| 709 | |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 710 | async create(guild: string, user: string, note: string | null) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 711 | // console.log("ModNotes create"); |
TheCodedProf | e49649c | 2023-04-23 14:31:00 -0400 | [diff] [blame] | 712 | const modNote = await this.modNotes.findOne({ guild: guild, user: user }); |
| 713 | modNote |
| 714 | ? await this.modNotes.updateOne({ guild: guild, user: user }, { $set: { note: note } }, collectionOptions) |
TheCodedProf | c016f9f | 2023-04-23 16:01:38 -0400 | [diff] [blame] | 715 | : await this.modNotes.insertOne({ guild: guild, user: user, note: note, flag: null }, collectionOptions); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | async read(guild: string, user: string) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 719 | // console.log("ModNotes read"); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 720 | const entry = await this.modNotes.findOne({ guild: guild, user: user }); |
TheCodedProf | c016f9f | 2023-04-23 16:01:38 -0400 | [diff] [blame] | 721 | return entry ?? null; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 722 | } |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 723 | |
| 724 | async delete(guild: string) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 725 | // console.log("ModNotes delete"); |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 726 | await this.modNotes.deleteMany({ guild: guild }); |
| 727 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 728 | } |
| 729 | |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 730 | export class Premium { |
| 731 | premium: Collection<PremiumSchema>; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 732 | cache: Map<string, [boolean, string, number, boolean, Date]>; // Date indicates the time one hour after it was created |
| 733 | cacheTimeout = 1000 * 60 * 60; // 1 hour |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 734 | |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 735 | constructor() { |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 736 | this.premium = database.collection<PremiumSchema>("premium"); |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 737 | this.cache = new Map<string, [boolean, string, number, boolean, Date]>(); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 738 | } |
| 739 | |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 740 | async updateUser(user: string, level: number) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 741 | // console.log("Premium updateUser"); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 742 | if (!(await this.userExists(user))) await this.createUser(user, level); |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 743 | await this.premium.updateOne({ user: user }, { $set: { level: level } }, { upsert: true }); |
| 744 | } |
| 745 | |
| 746 | async userExists(user: string): Promise<boolean> { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 747 | // console.log("Premium userExists"); |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 748 | const entry = await this.premium.findOne({ user: user }); |
| 749 | return entry ? true : false; |
| 750 | } |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 751 | async createUser(user: string, level: number) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 752 | // console.log("Premium createUser"); |
TheCodedProf | faae533 | 2023-03-01 18:16:05 -0500 | [diff] [blame] | 753 | await this.premium.insertOne({ user: user, appliesTo: [], level: level }, collectionOptions); |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 754 | } |
| 755 | |
TheCodedProf | aa3fe99 | 2023-02-25 21:53:09 -0500 | [diff] [blame] | 756 | async hasPremium(guild: string): Promise<[boolean, string, number, boolean] | null> { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 757 | // console.log("Premium hasPremium"); |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 758 | // [Has premium, user giving premium, level, is mod: if given automatically] |
| 759 | const cached = this.cache.get(guild); |
| 760 | 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] | 761 | const entries = await this.premium.find({}).toArray(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 762 | const members = (await client.guilds.fetch(guild)).members.cache; |
| 763 | for (const { user } of entries) { |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 764 | const member = members.get(user); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 765 | if (member) { |
| 766 | //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] | 767 | const modPerms = //TODO: Create list in config for perms |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 768 | member.permissions.has("Administrator") || |
| 769 | member.permissions.has("ManageChannels") || |
| 770 | member.permissions.has("ManageRoles") || |
| 771 | member.permissions.has("ManageEmojisAndStickers") || |
| 772 | member.permissions.has("ManageWebhooks") || |
| 773 | member.permissions.has("ManageGuild") || |
| 774 | member.permissions.has("KickMembers") || |
| 775 | member.permissions.has("BanMembers") || |
| 776 | member.permissions.has("ManageEvents") || |
| 777 | member.permissions.has("ManageMessages") || |
| 778 | member.permissions.has("ManageThreads"); |
| 779 | const entry = entries.find((e) => e.user === member.id); |
| 780 | if (entry && entry.level === 3 && modPerms) { |
| 781 | this.cache.set(guild, [ |
| 782 | true, |
| 783 | member.id, |
| 784 | entry.level, |
| 785 | true, |
| 786 | new Date(Date.now() + this.cacheTimeout) |
| 787 | ]); |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 788 | return [true, member.id, entry.level, true]; |
| 789 | } |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 790 | } |
| 791 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 792 | const entry = await this.premium.findOne({ |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 793 | appliesTo: { |
| 794 | $elemMatch: { |
| 795 | $eq: guild |
| 796 | } |
| 797 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 798 | }); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 799 | this.cache.set(guild, [ |
| 800 | entry ? true : false, |
| 801 | entry?.user ?? "", |
| 802 | entry?.level ?? 0, |
| 803 | false, |
| 804 | new Date(Date.now() + this.cacheTimeout) |
| 805 | ]); |
TheCodedProf | aa3fe99 | 2023-02-25 21:53:09 -0500 | [diff] [blame] | 806 | return entry ? [true, entry.user, entry.level, false] : null; |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 807 | } |
| 808 | |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 809 | async fetchUser(user: string): Promise<PremiumSchema | null> { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 810 | // console.log("Premium fetchUser"); |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 811 | const entry = await this.premium.findOne({ user: user }); |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 812 | if (!entry) return null; |
| 813 | return entry; |
| 814 | } |
| 815 | |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 816 | async checkAllPremium(member?: GuildMember) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 817 | // console.log("Premium checkAllPremium"); |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 818 | const entries = await this.premium.find({}).toArray(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 819 | if (member) { |
| 820 | const entry = entries.find((e) => e.user === member.id); |
| 821 | if (entry) { |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 822 | const expiresAt = entry.expiresAt; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 823 | if (expiresAt) expiresAt < Date.now() ? await this.premium.deleteOne({ user: member.id }) : null; |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 824 | } |
| 825 | const roles = member.roles; |
| 826 | let level = 0; |
| 827 | if (roles.cache.has("1066468879309750313")) { |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 828 | level = 99; |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 829 | } else if (roles.cache.has("1066465491713003520")) { |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 830 | level = 1; |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 831 | } else if (roles.cache.has("1066439526496604194")) { |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 832 | level = 2; |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 833 | } else if (roles.cache.has("1066464134322978912")) { |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 834 | level = 3; |
| 835 | } |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 836 | await this.updateUser(member.id, level); |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 837 | if (level > 0) { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 838 | await this.premium.updateOne({ user: member.id }, { $unset: { expiresAt: "" } }); |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 839 | } else { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 840 | await this.premium.updateOne( |
| 841 | { user: member.id }, |
| 842 | { $set: { expiresAt: Date.now() + 1000 * 60 * 60 * 24 * 3 } } |
| 843 | ); |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 844 | } |
| 845 | } else { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 846 | const members = await (await client.guilds.fetch("684492926528651336")).members.fetch(); |
| 847 | for (const { roles, id } of members.values()) { |
| 848 | const entry = entries.find((e) => e.user === id); |
| 849 | if (entry) { |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 850 | const expiresAt = entry.expiresAt; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 851 | if (expiresAt) expiresAt < Date.now() ? await this.premium.deleteOne({ user: id }) : null; |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 852 | } |
| 853 | let level: number = 0; |
| 854 | if (roles.cache.has("1066468879309750313")) { |
| 855 | level = 99; |
| 856 | } else if (roles.cache.has("1066465491713003520")) { |
| 857 | level = 1; |
| 858 | } else if (roles.cache.has("1066439526496604194")) { |
| 859 | level = 2; |
| 860 | } else if (roles.cache.has("1066464134322978912")) { |
| 861 | level = 3; |
| 862 | } |
| 863 | await this.updateUser(id, level); |
| 864 | if (level > 0) { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 865 | await this.premium.updateOne({ user: id }, { $unset: { expiresAt: "" } }); |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 866 | } else { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 867 | await this.premium.updateOne( |
| 868 | { user: id }, |
| 869 | { $set: { expiresAt: Date.now() + 1000 * 60 * 60 * 24 * 3 } } |
| 870 | ); |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 871 | } |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 872 | } |
| 873 | } |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 874 | } |
| 875 | |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 876 | async addPremium(user: string, guild: string) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 877 | // console.log("Premium addPremium"); |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 878 | const { level } = (await this.fetchUser(user))!; |
| 879 | 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] | 880 | return this.premium.updateOne({ user: user }, { $addToSet: { appliesTo: guild } }, { upsert: true }); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 881 | } |
TheCodedProf | fc420b7 | 2023-01-24 17:14:38 -0500 | [diff] [blame] | 882 | |
TheCodedProf | 48865eb | 2023-03-05 15:25:25 -0500 | [diff] [blame] | 883 | async removePremium(user: string, guild: string) { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 884 | // console.log("Premium removePremium"); |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 885 | this.cache.set(guild, [false, "", 0, false, new Date(Date.now() + this.cacheTimeout)]); |
TheCodedProf | 48865eb | 2023-03-05 15:25:25 -0500 | [diff] [blame] | 886 | return await this.premium.updateOne({ user: user }, { $pull: { appliesTo: guild } }); |
TheCodedProf | fc420b7 | 2023-01-24 17:14:38 -0500 | [diff] [blame] | 887 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 888 | } |
| 889 | |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 890 | // export class Plugins {} |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 891 | |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 892 | export interface GuildConfig { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 893 | id: string; |
| 894 | version: number; |
PineaFan | 100df68 | 2023-01-02 13:26:08 +0000 | [diff] [blame] | 895 | singleEventNotifications: Record<string, boolean>; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 896 | filters: { |
| 897 | images: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 898 | NSFW: boolean; |
| 899 | size: boolean; |
| 900 | }; |
| 901 | malware: boolean; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 902 | wordFilter: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 903 | enabled: boolean; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 904 | words: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 905 | strict: string[]; |
| 906 | loose: string[]; |
| 907 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 908 | allowed: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 909 | users: string[]; |
| 910 | roles: string[]; |
| 911 | channels: string[]; |
| 912 | }; |
| 913 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 914 | invite: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 915 | enabled: boolean; |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 916 | allowed: { |
| 917 | channels: string[]; |
| 918 | roles: string[]; |
| 919 | users: string[]; |
| 920 | }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 921 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 922 | pings: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 923 | mass: number; |
| 924 | everyone: boolean; |
| 925 | roles: boolean; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 926 | allowed: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 927 | roles: string[]; |
| 928 | rolesToMention: string[]; |
| 929 | users: string[]; |
| 930 | channels: string[]; |
| 931 | }; |
| 932 | }; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 933 | clean: { |
| 934 | channels: string[]; |
| 935 | allowed: { |
TheCodedProf | f8ef794 | 2023-03-03 15:32:32 -0500 | [diff] [blame] | 936 | users: string[]; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 937 | roles: string[]; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 938 | }; |
| 939 | }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 940 | }; |
TheCodedProf | baee2c1 | 2023-02-18 16:11:06 -0500 | [diff] [blame] | 941 | autoPublish: { |
| 942 | enabled: boolean; |
| 943 | channels: string[]; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 944 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 945 | welcome: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 946 | enabled: boolean; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 947 | role: string | null; |
| 948 | ping: string | null; |
| 949 | channel: string | null; |
| 950 | message: string | null; |
| 951 | }; |
| 952 | stats: Record<string, { name: string; enabled: boolean }>; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 953 | logging: { |
| 954 | logs: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 955 | enabled: boolean; |
| 956 | channel: string | null; |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 957 | toLog: string; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 958 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 959 | staff: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 960 | channel: string | null; |
| 961 | }; |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 962 | attachments: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 963 | channel: string | null; |
| 964 | saved: Record<string, string>; |
| 965 | }; |
| 966 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 967 | verify: { |
PineaFan | df4996f | 2023-01-01 14:20:06 +0000 | [diff] [blame] | 968 | enabled: boolean; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 969 | role: string | null; |
| 970 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 971 | tickets: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 972 | enabled: boolean; |
| 973 | category: string | null; |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 974 | types: string; |
| 975 | customTypes: string[] | null; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 976 | useCustom: boolean; |
| 977 | supportRole: string | null; |
| 978 | maxTickets: number; |
| 979 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 980 | moderation: { |
| 981 | mute: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 982 | timeout: boolean; |
| 983 | role: string | null; |
| 984 | text: string | null; |
| 985 | link: string | null; |
| 986 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 987 | kick: { |
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 | ban: { |
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 | softban: { |
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 | warn: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 1000 | text: string | null; |
| 1001 | link: string | null; |
| 1002 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 1003 | role: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 1004 | role: string | null; |
TheCodedProf | d9636e8 | 2023-01-17 22:13:06 -0500 | [diff] [blame] | 1005 | text: null; |
| 1006 | link: null; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 1007 | }; |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 1008 | nick: { |
| 1009 | text: string | null; |
| 1010 | link: string | null; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1011 | }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 1012 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 1013 | tracks: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 1014 | name: string; |
| 1015 | retainPrevious: boolean; |
| 1016 | nullable: boolean; |
| 1017 | track: string[]; |
| 1018 | manageableBy: string[]; |
| 1019 | }[]; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 1020 | roleMenu: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 1021 | enabled: boolean; |
| 1022 | allowWebUI: boolean; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 1023 | options: { |
TheCodedProf | 4a088b1 | 2023-06-06 15:29:59 -0400 | [diff] [blame] | 1024 | enabled?: boolean; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 1025 | name: string; |
TheCodedProf | 4a088b1 | 2023-06-06 15:29:59 -0400 | [diff] [blame] | 1026 | description?: string; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 1027 | min: number; |
| 1028 | max: number; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 1029 | options: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 1030 | name: string; |
| 1031 | description: string | null; |
| 1032 | role: string; |
| 1033 | }[]; |
| 1034 | }[]; |
| 1035 | }; |
| 1036 | tags: Record<string, string>; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1037 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 1038 | |
| 1039 | export interface HistorySchema { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 1040 | type: string; |
| 1041 | guild: string; |
| 1042 | user: string; |
| 1043 | moderator: string | null; |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 1044 | reason: string | null; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 1045 | occurredAt: Date; |
| 1046 | before: string | null; |
| 1047 | after: string | null; |
| 1048 | amount: string | null; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 1049 | } |
| 1050 | |
TheCodedProf | c016f9f | 2023-04-23 16:01:38 -0400 | [diff] [blame] | 1051 | export type FlagColors = "red" | "yellow" | "green" | "blue" | "purple" | "gray"; |
| 1052 | |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 1053 | export interface ModNoteSchema { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 1054 | guild: string; |
| 1055 | user: string; |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 1056 | note: string | null; |
TheCodedProf | c016f9f | 2023-04-23 16:01:38 -0400 | [diff] [blame] | 1057 | flag: FlagColors | null; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 1058 | } |
| 1059 | |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 1060 | export interface PremiumSchema { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 1061 | user: string; |
| 1062 | level: number; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 1063 | appliesTo: string[]; |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 1064 | expiresAt?: number; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 1065 | } |