TheCodedProf | cfe8e9a | 2023-02-26 17:28:09 -0500 | [diff] [blame^] | 1 | import type { ButtonStyle, GuildMember } 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"; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 6 | |
| 7 | const mongoClient = new MongoClient(config.mongoUrl); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 8 | await mongoClient.connect(); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 9 | const database = mongoClient.db("Nucleus"); |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 10 | |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 11 | export class Guilds { |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 12 | guilds: Collection<GuildConfig>; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 13 | defaultData: GuildConfig | null; |
| 14 | |
| 15 | constructor() { |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 16 | this.guilds = database.collection<GuildConfig>("guilds"); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 17 | this.defaultData = null; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 18 | } |
| 19 | |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 20 | async setup(): Promise<Guilds> { |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 21 | this.defaultData = (await import("../config/default.json", { assert: { type: "json" } })) |
| 22 | .default as unknown as GuildConfig; |
| 23 | return this; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 24 | } |
| 25 | |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 26 | async read(guild: string): Promise<GuildConfig> { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 27 | const entry = await this.guilds.findOne({ id: guild }); |
PineaFan | df4996f | 2023-01-01 14:20:06 +0000 | [diff] [blame] | 28 | return Object.assign({}, this.defaultData, entry); |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 29 | } |
| 30 | |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 31 | async write(guild: string, set: object | null, unset: string[] | string = []) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 32 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 33 | const uo: Record<string, any> = {}; |
| 34 | if (!Array.isArray(unset)) unset = [unset]; |
| 35 | for (const key of unset) { |
pineafan | 0bc0416 | 2022-07-25 17:22:26 +0100 | [diff] [blame] | 36 | uo[key] = null; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 37 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 38 | const out = { $set: {}, $unset: {} }; |
| 39 | if (set) out.$set = set; |
| 40 | if (unset.length) out.$unset = uo; |
pineafan | 0bc0416 | 2022-07-25 17:22:26 +0100 | [diff] [blame] | 41 | await this.guilds.updateOne({ id: guild }, out, { upsert: true }); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 42 | } |
| 43 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 44 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 45 | async append(guild: string, key: string, value: any) { |
| 46 | if (Array.isArray(value)) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 47 | await this.guilds.updateOne( |
| 48 | { id: guild }, |
| 49 | { |
| 50 | $addToSet: { [key]: { $each: value } } |
| 51 | }, |
| 52 | { upsert: true } |
| 53 | ); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 54 | } else { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 55 | await this.guilds.updateOne( |
| 56 | { id: guild }, |
| 57 | { |
| 58 | $addToSet: { [key]: value } |
| 59 | }, |
| 60 | { upsert: true } |
| 61 | ); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 65 | async remove( |
| 66 | guild: string, |
| 67 | key: string, |
Skyler Grey | c634e2b | 2022-08-06 17:50:48 +0100 | [diff] [blame] | 68 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 69 | value: any, |
| 70 | innerKey?: string | null |
| 71 | ) { |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 72 | if (innerKey) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 73 | await this.guilds.updateOne( |
| 74 | { id: guild }, |
| 75 | { |
| 76 | $pull: { [key]: { [innerKey]: { $eq: value } } } |
| 77 | }, |
| 78 | { upsert: true } |
| 79 | ); |
pineafan | 0bc0416 | 2022-07-25 17:22:26 +0100 | [diff] [blame] | 80 | } else if (Array.isArray(value)) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 81 | await this.guilds.updateOne( |
| 82 | { id: guild }, |
| 83 | { |
| 84 | $pullAll: { [key]: value } |
| 85 | }, |
| 86 | { upsert: true } |
| 87 | ); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 88 | } else { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 89 | await this.guilds.updateOne( |
| 90 | { id: guild }, |
| 91 | { |
| 92 | $pullAll: { [key]: [value] } |
| 93 | }, |
| 94 | { upsert: true } |
| 95 | ); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 96 | } |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 97 | } |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 98 | |
| 99 | async delete(guild: string) { |
| 100 | await this.guilds.deleteOne({ id: guild }); |
| 101 | } |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 102 | } |
| 103 | |
TheCodedProf | cfe8e9a | 2023-02-26 17:28:09 -0500 | [diff] [blame^] | 104 | interface TranscriptEmbed { |
| 105 | title?: string; |
| 106 | description?: string; |
| 107 | fields?: { |
| 108 | name: string; |
| 109 | value: string; |
| 110 | inline: boolean; |
| 111 | }[]; |
| 112 | footer?: { |
| 113 | text: string; |
| 114 | iconURL?: string; |
| 115 | }; |
| 116 | } |
| 117 | |
| 118 | interface TranscriptComponent { |
| 119 | type: number; |
| 120 | style?: ButtonStyle; |
| 121 | label?: string; |
| 122 | description?: string; |
| 123 | placeholder?: string; |
| 124 | emojiURL?: string; |
| 125 | } |
| 126 | |
| 127 | interface TranscriptAuthor { |
| 128 | username: string; |
| 129 | discriminator: number; |
| 130 | nickname?: string; |
| 131 | id: string; |
| 132 | iconURL?: string; |
| 133 | topRole: { |
| 134 | color: number; |
| 135 | badgeURL?: string; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | interface TranscriptAttachment { |
| 140 | url: string; |
| 141 | filename: string; |
| 142 | size: number; |
| 143 | log?: string; |
| 144 | } |
| 145 | |
| 146 | interface TranscriptMessage { |
| 147 | id: string; |
| 148 | author: TranscriptAuthor; |
| 149 | content?: string; |
| 150 | embeds?: TranscriptEmbed[]; |
| 151 | components?: TranscriptComponent[][]; |
| 152 | editedTimestamp?: number; |
| 153 | createdTimestamp: number; |
| 154 | flags?: string[]; |
| 155 | attachments?: TranscriptAttachment[]; |
| 156 | stickerURLs?: string[]; |
| 157 | referencedMessage?: string | [string, string, string]; |
| 158 | } |
| 159 | |
| 160 | interface TranscriptSchema { |
| 161 | code: string; |
| 162 | for: TranscriptAuthor; |
| 163 | type: "ticket" | "purge" |
| 164 | guild: string; |
| 165 | channel: string; |
| 166 | messages: TranscriptMessage[]; |
| 167 | createdTimestamp: number; |
| 168 | createdBy: TranscriptAuthor; |
| 169 | } |
| 170 | |
| 171 | export class Transcript { |
| 172 | transcripts: Collection<TranscriptSchema>; |
| 173 | |
| 174 | constructor() { |
| 175 | this.transcripts = database.collection<TranscriptSchema>("transcripts"); |
| 176 | } |
| 177 | |
| 178 | async create(transcript: Omit<TranscriptSchema, "code">) { |
| 179 | let code; |
| 180 | do { |
| 181 | code = Math.random().toString(36).substring(2, 16) + Math.random().toString(36).substring(2, 16); |
| 182 | } while (await this.transcripts.findOne({ code: code })); |
| 183 | |
| 184 | const doc = await this.transcripts.insertOne(Object.assign(transcript, { code: code })); |
| 185 | if(doc.acknowledged) return code; |
| 186 | else return null; |
| 187 | } |
| 188 | |
| 189 | async read(code: string) { |
| 190 | return await this.transcripts.findOne({ code: code }); |
| 191 | } |
| 192 | } |
| 193 | |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 194 | export class History { |
| 195 | histories: Collection<HistorySchema>; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 196 | |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 197 | constructor() { |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 198 | this.histories = database.collection<HistorySchema>("history"); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 199 | } |
| 200 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 201 | async create( |
| 202 | type: string, |
| 203 | guild: string, |
| 204 | user: Discord.User, |
| 205 | moderator: Discord.User | null, |
| 206 | reason: string | null, |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 207 | before?: string | null, |
| 208 | after?: string | null, |
| 209 | amount?: string | null |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 210 | ) { |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 211 | await this.histories.insertOne({ |
| 212 | type: type, |
| 213 | guild: guild, |
| 214 | user: user.id, |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 215 | moderator: moderator ? moderator.id : null, |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 216 | reason: reason, |
| 217 | occurredAt: new Date(), |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 218 | before: before ?? null, |
| 219 | after: after ?? null, |
| 220 | amount: amount ?? null |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 221 | }); |
| 222 | } |
| 223 | |
| 224 | async read(guild: string, user: string, year: number) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 225 | const entry = (await this.histories |
| 226 | .find({ |
| 227 | guild: guild, |
| 228 | user: user, |
| 229 | occurredAt: { |
| 230 | $gte: new Date(year - 1, 11, 31, 23, 59, 59), |
| 231 | $lt: new Date(year + 1, 0, 1, 0, 0, 0) |
| 232 | } |
| 233 | }) |
| 234 | .toArray()) as HistorySchema[]; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 235 | return entry; |
| 236 | } |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 237 | |
| 238 | async delete(guild: string) { |
| 239 | await this.histories.deleteMany({ guild: guild }); |
| 240 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 241 | } |
| 242 | |
TheCodedProf | b5e9d55 | 2023-01-29 15:43:26 -0500 | [diff] [blame] | 243 | interface ScanCacheSchema { |
| 244 | addedAt: Date; |
| 245 | hash: string; |
| 246 | data: boolean; |
| 247 | tags: string[]; |
| 248 | } |
| 249 | |
| 250 | export class ScanCache { |
| 251 | scanCache: Collection<ScanCacheSchema>; |
| 252 | |
| 253 | constructor() { |
| 254 | this.scanCache = database.collection<ScanCacheSchema>("scanCache"); |
| 255 | } |
| 256 | |
| 257 | async read(hash: string) { |
| 258 | return await this.scanCache.findOne({ hash: hash }); |
| 259 | } |
| 260 | |
| 261 | async write(hash: string, data: boolean, tags?: string[]) { |
TheCodedProf | 1f67504 | 2023-02-16 17:01:29 -0500 | [diff] [blame] | 262 | await this.scanCache.insertOne({ hash: hash, data: data, tags: tags ?? [], addedAt: new Date() }); |
TheCodedProf | b5e9d55 | 2023-01-29 15:43:26 -0500 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | async cleanup() { |
| 266 | await this.scanCache.deleteMany({ addedAt: { $lt: new Date(Date.now() - (1000 * 60 * 60 * 24 * 31)) }, hash: { $not$text: "http"} }); |
| 267 | } |
| 268 | } |
| 269 | |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 270 | export class PerformanceTest { |
| 271 | performanceData: Collection<PerformanceDataSchema>; |
| 272 | |
| 273 | constructor() { |
| 274 | this.performanceData = database.collection<PerformanceDataSchema>("performance"); |
| 275 | } |
| 276 | |
| 277 | async record(data: PerformanceDataSchema) { |
| 278 | data.timestamp = new Date(); |
| 279 | await this.performanceData.insertOne(data); |
| 280 | } |
| 281 | async read() { |
| 282 | return await this.performanceData.find({}).toArray(); |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | export interface PerformanceDataSchema { |
| 287 | timestamp?: Date; |
| 288 | discord: number; |
| 289 | databaseRead: number; |
| 290 | resources: { |
| 291 | cpu: number; |
| 292 | memory: number; |
| 293 | temperature: number; |
| 294 | } |
| 295 | } |
| 296 | |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 297 | export class ModNotes { |
| 298 | modNotes: Collection<ModNoteSchema>; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 299 | |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 300 | constructor() { |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 301 | this.modNotes = database.collection<ModNoteSchema>("modNotes"); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | async create(guild: string, user: string, note: string | null) { |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 305 | await this.modNotes.updateOne({ guild: guild, user: user }, { $set: { note: note } }, { upsert: true }); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | async read(guild: string, user: string) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 309 | const entry = await this.modNotes.findOne({ guild: guild, user: user }); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 310 | return entry?.note ?? null; |
| 311 | } |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 312 | |
| 313 | async delete(guild: string) { |
| 314 | await this.modNotes.deleteMany({ guild: guild }); |
| 315 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 316 | } |
| 317 | |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 318 | export class Premium { |
| 319 | premium: Collection<PremiumSchema>; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 320 | |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 321 | constructor() { |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 322 | this.premium = database.collection<PremiumSchema>("premium"); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 323 | } |
| 324 | |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 325 | async updateUser(user: string, level: number) { |
| 326 | if(!(await this.userExists(user))) await this.createUser(user, level); |
| 327 | await this.premium.updateOne({ user: user }, { $set: { level: level } }, { upsert: true }); |
| 328 | } |
| 329 | |
| 330 | async userExists(user: string): Promise<boolean> { |
| 331 | const entry = await this.premium.findOne({ user: user }); |
| 332 | return entry ? true : false; |
| 333 | } |
| 334 | |
| 335 | async createUser(user: string, level: number) { |
| 336 | await this.premium.insertOne({ user: user, appliesTo: [], level: level }); |
| 337 | } |
| 338 | |
TheCodedProf | aa3fe99 | 2023-02-25 21:53:09 -0500 | [diff] [blame] | 339 | async hasPremium(guild: string): Promise<[boolean, string, number, boolean] | null> { |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 340 | const entries = await this.premium.find({}).toArray(); |
| 341 | const members = await (await client.guilds.fetch(guild)).members.fetch() |
| 342 | for(const {user} of entries) { |
| 343 | const member = members.get(user); |
TheCodedProf | aa3fe99 | 2023-02-25 21:53:09 -0500 | [diff] [blame] | 344 | 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] | 345 | const modPerms = //TODO: Create list in config for perms |
| 346 | member.permissions.has("Administrator") || |
| 347 | member.permissions.has("ManageChannels") || |
| 348 | member.permissions.has("ManageRoles") || |
| 349 | member.permissions.has("ManageEmojisAndStickers") || |
| 350 | member.permissions.has("ManageWebhooks") || |
| 351 | member.permissions.has("ManageGuild") || |
| 352 | member.permissions.has("KickMembers") || |
| 353 | member.permissions.has("BanMembers") || |
| 354 | member.permissions.has("ManageEvents") || |
| 355 | member.permissions.has("ManageMessages") || |
| 356 | member.permissions.has("ManageThreads") |
| 357 | const entry = entries.find(e => e.user === member.id); |
TheCodedProf | aa3fe99 | 2023-02-25 21:53:09 -0500 | [diff] [blame] | 358 | if(entry && (entry.level === 3) && modPerms) return [true, member.id, entry.level, true]; |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 359 | } |
| 360 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 361 | const entry = await this.premium.findOne({ |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 362 | appliesTo: { |
| 363 | $elemMatch: { |
| 364 | $eq: guild |
| 365 | } |
| 366 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 367 | }); |
TheCodedProf | aa3fe99 | 2023-02-25 21:53:09 -0500 | [diff] [blame] | 368 | return entry ? [true, entry.user, entry.level, false] : null; |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 369 | } |
| 370 | |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 371 | async fetchUser(user: string): Promise<PremiumSchema | null> { |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 372 | const entry = await this.premium.findOne({ user: user }); |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 373 | if (!entry) return null; |
| 374 | return entry; |
| 375 | } |
| 376 | |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 377 | async checkAllPremium(member?: GuildMember) { |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 378 | const entries = await this.premium.find({}).toArray(); |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 379 | if(member) { |
| 380 | const entry = entries.find(e => e.user === member.id); |
| 381 | if(entry) { |
| 382 | const expiresAt = entry.expiresAt; |
| 383 | if(expiresAt) expiresAt < Date.now() ? await this.premium.deleteOne({user: member.id}) : null; |
| 384 | } |
| 385 | const roles = member.roles; |
| 386 | let level = 0; |
| 387 | if (roles.cache.has("1066468879309750313")) { |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 388 | level = 99; |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 389 | } else if (roles.cache.has("1066465491713003520")) { |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 390 | level = 1; |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 391 | } else if (roles.cache.has("1066439526496604194")) { |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 392 | level = 2; |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 393 | } else if (roles.cache.has("1066464134322978912")) { |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 394 | level = 3; |
| 395 | } |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 396 | await this.updateUser(member.id, level); |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 397 | if (level > 0) { |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 398 | await this.premium.updateOne({ user: member.id }, {$unset: { expiresAt: ""}}) |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 399 | } else { |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 400 | await this.premium.updateOne({ user: member.id }, {$set: { expiresAt: (Date.now() + (1000*60*60*24*3)) }}) |
| 401 | } |
| 402 | } else { |
| 403 | const members = await (await client.guilds.fetch('684492926528651336')).members.fetch(); |
| 404 | for(const {roles, id} of members.values()) { |
| 405 | const entry = entries.find(e => e.user === id); |
| 406 | if(entry) { |
| 407 | const expiresAt = entry.expiresAt; |
| 408 | if(expiresAt) expiresAt < Date.now() ? await this.premium.deleteOne({user: id}) : null; |
| 409 | } |
| 410 | let level: number = 0; |
| 411 | if (roles.cache.has("1066468879309750313")) { |
| 412 | level = 99; |
| 413 | } else if (roles.cache.has("1066465491713003520")) { |
| 414 | level = 1; |
| 415 | } else if (roles.cache.has("1066439526496604194")) { |
| 416 | level = 2; |
| 417 | } else if (roles.cache.has("1066464134322978912")) { |
| 418 | level = 3; |
| 419 | } |
| 420 | await this.updateUser(id, level); |
| 421 | if (level > 0) { |
| 422 | await this.premium.updateOne({ user: id }, {$unset: { expiresAt: ""}}) |
| 423 | } else { |
| 424 | await this.premium.updateOne({ user: id }, {$set: { expiresAt: (Date.now() + (1000*60*60*24*3)) }}) |
| 425 | } |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 426 | } |
| 427 | } |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 428 | } |
| 429 | |
TheCodedProf | fc420b7 | 2023-01-24 17:14:38 -0500 | [diff] [blame] | 430 | addPremium(user: string, guild: string) { |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 431 | return this.premium.updateOne({ user: user }, { $addToSet: { appliesTo: guild } }, { upsert: true }); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 432 | } |
TheCodedProf | fc420b7 | 2023-01-24 17:14:38 -0500 | [diff] [blame] | 433 | |
| 434 | removePremium(user: string, guild: string) { |
| 435 | return this.premium.updateOne({ user: user }, { $pull: { appliesTo: guild } }); |
| 436 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 437 | } |
| 438 | |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 439 | export interface GuildConfig { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 440 | id: string; |
| 441 | version: number; |
PineaFan | 100df68 | 2023-01-02 13:26:08 +0000 | [diff] [blame] | 442 | singleEventNotifications: Record<string, boolean>; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 443 | filters: { |
| 444 | images: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 445 | NSFW: boolean; |
| 446 | size: boolean; |
| 447 | }; |
| 448 | malware: boolean; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 449 | wordFilter: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 450 | enabled: boolean; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 451 | words: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 452 | strict: string[]; |
| 453 | loose: string[]; |
| 454 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 455 | allowed: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 456 | users: string[]; |
| 457 | roles: string[]; |
| 458 | channels: string[]; |
| 459 | }; |
| 460 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 461 | invite: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 462 | enabled: boolean; |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 463 | allowed: { |
| 464 | channels: string[]; |
| 465 | roles: string[]; |
| 466 | users: string[]; |
| 467 | }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 468 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 469 | pings: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 470 | mass: number; |
| 471 | everyone: boolean; |
| 472 | roles: boolean; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 473 | allowed: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 474 | roles: string[]; |
| 475 | rolesToMention: string[]; |
| 476 | users: string[]; |
| 477 | channels: string[]; |
| 478 | }; |
| 479 | }; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 480 | clean: { |
| 481 | channels: string[]; |
| 482 | allowed: { |
| 483 | user: string[]; |
| 484 | roles: string[]; |
| 485 | } |
| 486 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 487 | }; |
TheCodedProf | baee2c1 | 2023-02-18 16:11:06 -0500 | [diff] [blame] | 488 | autoPublish: { |
| 489 | enabled: boolean; |
| 490 | channels: string[]; |
| 491 | } |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 492 | welcome: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 493 | enabled: boolean; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 494 | role: string | null; |
| 495 | ping: string | null; |
| 496 | channel: string | null; |
| 497 | message: string | null; |
| 498 | }; |
| 499 | stats: Record<string, { name: string; enabled: boolean }>; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 500 | logging: { |
| 501 | logs: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 502 | enabled: boolean; |
| 503 | channel: string | null; |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 504 | toLog: string; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 505 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 506 | staff: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 507 | channel: string | null; |
| 508 | }; |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 509 | attachments: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 510 | channel: string | null; |
| 511 | saved: Record<string, string>; |
| 512 | }; |
| 513 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 514 | verify: { |
PineaFan | df4996f | 2023-01-01 14:20:06 +0000 | [diff] [blame] | 515 | enabled: boolean; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 516 | role: string | null; |
| 517 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 518 | tickets: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 519 | enabled: boolean; |
| 520 | category: string | null; |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 521 | types: string; |
| 522 | customTypes: string[] | null; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 523 | useCustom: boolean; |
| 524 | supportRole: string | null; |
| 525 | maxTickets: number; |
| 526 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 527 | moderation: { |
| 528 | mute: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 529 | timeout: boolean; |
| 530 | role: string | null; |
| 531 | text: string | null; |
| 532 | link: string | null; |
| 533 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 534 | kick: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 535 | text: string | null; |
| 536 | link: string | null; |
| 537 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 538 | ban: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 539 | text: string | null; |
| 540 | link: string | null; |
| 541 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 542 | softban: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 543 | text: string | null; |
| 544 | link: string | null; |
| 545 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 546 | warn: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 547 | text: string | null; |
| 548 | link: string | null; |
| 549 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 550 | role: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 551 | role: string | null; |
TheCodedProf | d9636e8 | 2023-01-17 22:13:06 -0500 | [diff] [blame] | 552 | text: null; |
| 553 | link: null; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 554 | }; |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 555 | nick: { |
| 556 | text: string | null; |
| 557 | link: string | null; |
| 558 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 559 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 560 | tracks: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 561 | name: string; |
| 562 | retainPrevious: boolean; |
| 563 | nullable: boolean; |
| 564 | track: string[]; |
| 565 | manageableBy: string[]; |
| 566 | }[]; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 567 | roleMenu: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 568 | enabled: boolean; |
| 569 | allowWebUI: boolean; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 570 | options: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 571 | name: string; |
| 572 | description: string; |
| 573 | min: number; |
| 574 | max: number; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 575 | options: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 576 | name: string; |
| 577 | description: string | null; |
| 578 | role: string; |
| 579 | }[]; |
| 580 | }[]; |
| 581 | }; |
| 582 | tags: Record<string, string>; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 583 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 584 | |
| 585 | export interface HistorySchema { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 586 | type: string; |
| 587 | guild: string; |
| 588 | user: string; |
| 589 | moderator: string | null; |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 590 | reason: string | null; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 591 | occurredAt: Date; |
| 592 | before: string | null; |
| 593 | after: string | null; |
| 594 | amount: string | null; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | export interface ModNoteSchema { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 598 | guild: string; |
| 599 | user: string; |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 600 | note: string | null; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 601 | } |
| 602 | |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 603 | export interface PremiumSchema { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 604 | user: string; |
| 605 | level: number; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 606 | appliesTo: string[]; |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 607 | expiresAt?: number; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 608 | } |