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