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