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