TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame^] | 1 | import type { 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 | |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 104 | export class History { |
| 105 | histories: Collection<HistorySchema>; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 106 | |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 107 | constructor() { |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 108 | this.histories = database.collection<HistorySchema>("history"); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 109 | } |
| 110 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 111 | async create( |
| 112 | type: string, |
| 113 | guild: string, |
| 114 | user: Discord.User, |
| 115 | moderator: Discord.User | null, |
| 116 | reason: string | null, |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 117 | before?: string | null, |
| 118 | after?: string | null, |
| 119 | amount?: string | null |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 120 | ) { |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 121 | await this.histories.insertOne({ |
| 122 | type: type, |
| 123 | guild: guild, |
| 124 | user: user.id, |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 125 | moderator: moderator ? moderator.id : null, |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 126 | reason: reason, |
| 127 | occurredAt: new Date(), |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 128 | before: before ?? null, |
| 129 | after: after ?? null, |
| 130 | amount: amount ?? null |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 131 | }); |
| 132 | } |
| 133 | |
| 134 | async read(guild: string, user: string, year: number) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 135 | const entry = (await this.histories |
| 136 | .find({ |
| 137 | guild: guild, |
| 138 | user: user, |
| 139 | occurredAt: { |
| 140 | $gte: new Date(year - 1, 11, 31, 23, 59, 59), |
| 141 | $lt: new Date(year + 1, 0, 1, 0, 0, 0) |
| 142 | } |
| 143 | }) |
| 144 | .toArray()) as HistorySchema[]; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 145 | return entry; |
| 146 | } |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 147 | |
| 148 | async delete(guild: string) { |
| 149 | await this.histories.deleteMany({ guild: guild }); |
| 150 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 151 | } |
| 152 | |
TheCodedProf | b5e9d55 | 2023-01-29 15:43:26 -0500 | [diff] [blame] | 153 | interface ScanCacheSchema { |
| 154 | addedAt: Date; |
| 155 | hash: string; |
| 156 | data: boolean; |
| 157 | tags: string[]; |
| 158 | } |
| 159 | |
| 160 | export class ScanCache { |
| 161 | scanCache: Collection<ScanCacheSchema>; |
| 162 | |
| 163 | constructor() { |
| 164 | this.scanCache = database.collection<ScanCacheSchema>("scanCache"); |
| 165 | } |
| 166 | |
| 167 | async read(hash: string) { |
| 168 | return await this.scanCache.findOne({ hash: hash }); |
| 169 | } |
| 170 | |
| 171 | async write(hash: string, data: boolean, tags?: string[]) { |
TheCodedProf | 1f67504 | 2023-02-16 17:01:29 -0500 | [diff] [blame] | 172 | await this.scanCache.insertOne({ hash: hash, data: data, tags: tags ?? [], addedAt: new Date() }); |
TheCodedProf | b5e9d55 | 2023-01-29 15:43:26 -0500 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | async cleanup() { |
| 176 | await this.scanCache.deleteMany({ addedAt: { $lt: new Date(Date.now() - (1000 * 60 * 60 * 24 * 31)) }, hash: { $not$text: "http"} }); |
| 177 | } |
| 178 | } |
| 179 | |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 180 | export class PerformanceTest { |
| 181 | performanceData: Collection<PerformanceDataSchema>; |
| 182 | |
| 183 | constructor() { |
| 184 | this.performanceData = database.collection<PerformanceDataSchema>("performance"); |
| 185 | } |
| 186 | |
| 187 | async record(data: PerformanceDataSchema) { |
| 188 | data.timestamp = new Date(); |
| 189 | await this.performanceData.insertOne(data); |
| 190 | } |
| 191 | async read() { |
| 192 | return await this.performanceData.find({}).toArray(); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | export interface PerformanceDataSchema { |
| 197 | timestamp?: Date; |
| 198 | discord: number; |
| 199 | databaseRead: number; |
| 200 | resources: { |
| 201 | cpu: number; |
| 202 | memory: number; |
| 203 | temperature: number; |
| 204 | } |
| 205 | } |
| 206 | |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 207 | export class ModNotes { |
| 208 | modNotes: Collection<ModNoteSchema>; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 209 | |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 210 | constructor() { |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 211 | this.modNotes = database.collection<ModNoteSchema>("modNotes"); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | async create(guild: string, user: string, note: string | null) { |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 215 | await this.modNotes.updateOne({ guild: guild, user: user }, { $set: { note: note } }, { upsert: true }); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | async read(guild: string, user: string) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 219 | const entry = await this.modNotes.findOne({ guild: guild, user: user }); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 220 | return entry?.note ?? null; |
| 221 | } |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 222 | |
| 223 | async delete(guild: string) { |
| 224 | await this.modNotes.deleteMany({ guild: guild }); |
| 225 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 226 | } |
| 227 | |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 228 | export class Premium { |
| 229 | premium: Collection<PremiumSchema>; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 230 | |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 231 | constructor() { |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 232 | this.premium = database.collection<PremiumSchema>("premium"); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 233 | } |
| 234 | |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 235 | async updateUser(user: string, level: number) { |
| 236 | if(!(await this.userExists(user))) await this.createUser(user, level); |
| 237 | await this.premium.updateOne({ user: user }, { $set: { level: level } }, { upsert: true }); |
| 238 | } |
| 239 | |
| 240 | async userExists(user: string): Promise<boolean> { |
| 241 | const entry = await this.premium.findOne({ user: user }); |
| 242 | return entry ? true : false; |
| 243 | } |
| 244 | |
| 245 | async createUser(user: string, level: number) { |
| 246 | await this.premium.insertOne({ user: user, appliesTo: [], level: level }); |
| 247 | } |
| 248 | |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame^] | 249 | async hasPremium(guild: string): Promise<[boolean, string, number] | null> { |
| 250 | const entries = await this.premium.find({}).toArray(); |
| 251 | const members = await (await client.guilds.fetch(guild)).members.fetch() |
| 252 | for(const {user} of entries) { |
| 253 | const member = members.get(user); |
| 254 | if(member) { |
| 255 | const modPerms = //TODO: Create list in config for perms |
| 256 | member.permissions.has("Administrator") || |
| 257 | member.permissions.has("ManageChannels") || |
| 258 | member.permissions.has("ManageRoles") || |
| 259 | member.permissions.has("ManageEmojisAndStickers") || |
| 260 | member.permissions.has("ManageWebhooks") || |
| 261 | member.permissions.has("ManageGuild") || |
| 262 | member.permissions.has("KickMembers") || |
| 263 | member.permissions.has("BanMembers") || |
| 264 | member.permissions.has("ManageEvents") || |
| 265 | member.permissions.has("ManageMessages") || |
| 266 | member.permissions.has("ManageThreads") |
| 267 | const entry = entries.find(e => e.user === member.id); |
| 268 | if(entry && (entry.level === 3) && modPerms) return [true, member.id, entry.level]; |
| 269 | } |
| 270 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 271 | const entry = await this.premium.findOne({ |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame^] | 272 | appliesTo: { |
| 273 | $elemMatch: { |
| 274 | $eq: guild |
| 275 | } |
| 276 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 277 | }); |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame^] | 278 | return entry ? [true, entry.user, entry.level] : null; |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 279 | } |
| 280 | |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 281 | async fetchUser(user: string): Promise<PremiumSchema | null> { |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 282 | const entry = await this.premium.findOne({ user: user }); |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 283 | if (!entry) return null; |
| 284 | return entry; |
| 285 | } |
| 286 | |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame^] | 287 | async checkAllPremium(member?: GuildMember) { |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 288 | const entries = await this.premium.find({}).toArray(); |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame^] | 289 | if(member) { |
| 290 | const entry = entries.find(e => e.user === member.id); |
| 291 | if(entry) { |
| 292 | const expiresAt = entry.expiresAt; |
| 293 | if(expiresAt) expiresAt < Date.now() ? await this.premium.deleteOne({user: member.id}) : null; |
| 294 | } |
| 295 | const roles = member.roles; |
| 296 | let level = 0; |
| 297 | if (roles.cache.has("1066468879309750313")) { |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 298 | level = 99; |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame^] | 299 | } else if (roles.cache.has("1066465491713003520")) { |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 300 | level = 1; |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame^] | 301 | } else if (roles.cache.has("1066439526496604194")) { |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 302 | level = 2; |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame^] | 303 | } else if (roles.cache.has("1066464134322978912")) { |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 304 | level = 3; |
| 305 | } |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame^] | 306 | await this.updateUser(member.id, level); |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 307 | if (level > 0) { |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame^] | 308 | await this.premium.updateOne({ user: member.id }, {$unset: { expiresAt: ""}}) |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 309 | } else { |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame^] | 310 | await this.premium.updateOne({ user: member.id }, {$set: { expiresAt: (Date.now() + (1000*60*60*24*3)) }}) |
| 311 | } |
| 312 | } else { |
| 313 | const members = await (await client.guilds.fetch('684492926528651336')).members.fetch(); |
| 314 | for(const {roles, id} of members.values()) { |
| 315 | const entry = entries.find(e => e.user === id); |
| 316 | if(entry) { |
| 317 | const expiresAt = entry.expiresAt; |
| 318 | if(expiresAt) expiresAt < Date.now() ? await this.premium.deleteOne({user: id}) : null; |
| 319 | } |
| 320 | let level: number = 0; |
| 321 | if (roles.cache.has("1066468879309750313")) { |
| 322 | level = 99; |
| 323 | } else if (roles.cache.has("1066465491713003520")) { |
| 324 | level = 1; |
| 325 | } else if (roles.cache.has("1066439526496604194")) { |
| 326 | level = 2; |
| 327 | } else if (roles.cache.has("1066464134322978912")) { |
| 328 | level = 3; |
| 329 | } |
| 330 | await this.updateUser(id, level); |
| 331 | if (level > 0) { |
| 332 | await this.premium.updateOne({ user: id }, {$unset: { expiresAt: ""}}) |
| 333 | } else { |
| 334 | await this.premium.updateOne({ user: id }, {$set: { expiresAt: (Date.now() + (1000*60*60*24*3)) }}) |
| 335 | } |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 336 | } |
| 337 | } |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 338 | } |
| 339 | |
TheCodedProf | fc420b7 | 2023-01-24 17:14:38 -0500 | [diff] [blame] | 340 | addPremium(user: string, guild: string) { |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 341 | return this.premium.updateOne({ user: user }, { $addToSet: { appliesTo: guild } }, { upsert: true }); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 342 | } |
TheCodedProf | fc420b7 | 2023-01-24 17:14:38 -0500 | [diff] [blame] | 343 | |
| 344 | removePremium(user: string, guild: string) { |
| 345 | return this.premium.updateOne({ user: user }, { $pull: { appliesTo: guild } }); |
| 346 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 347 | } |
| 348 | |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 349 | export interface GuildConfig { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 350 | id: string; |
| 351 | version: number; |
PineaFan | 100df68 | 2023-01-02 13:26:08 +0000 | [diff] [blame] | 352 | singleEventNotifications: Record<string, boolean>; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 353 | filters: { |
| 354 | images: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 355 | NSFW: boolean; |
| 356 | size: boolean; |
| 357 | }; |
| 358 | malware: boolean; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 359 | wordFilter: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 360 | enabled: boolean; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 361 | words: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 362 | strict: string[]; |
| 363 | loose: string[]; |
| 364 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 365 | allowed: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 366 | users: string[]; |
| 367 | roles: string[]; |
| 368 | channels: string[]; |
| 369 | }; |
| 370 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 371 | invite: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 372 | enabled: boolean; |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 373 | allowed: { |
| 374 | channels: string[]; |
| 375 | roles: string[]; |
| 376 | users: string[]; |
| 377 | }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 378 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 379 | pings: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 380 | mass: number; |
| 381 | everyone: boolean; |
| 382 | roles: boolean; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 383 | allowed: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 384 | roles: string[]; |
| 385 | rolesToMention: string[]; |
| 386 | users: string[]; |
| 387 | channels: string[]; |
| 388 | }; |
| 389 | }; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 390 | clean: { |
| 391 | channels: string[]; |
| 392 | allowed: { |
| 393 | user: string[]; |
| 394 | roles: string[]; |
| 395 | } |
| 396 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 397 | }; |
TheCodedProf | baee2c1 | 2023-02-18 16:11:06 -0500 | [diff] [blame] | 398 | autoPublish: { |
| 399 | enabled: boolean; |
| 400 | channels: string[]; |
| 401 | } |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 402 | welcome: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 403 | enabled: boolean; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 404 | role: string | null; |
| 405 | ping: string | null; |
| 406 | channel: string | null; |
| 407 | message: string | null; |
| 408 | }; |
| 409 | stats: Record<string, { name: string; enabled: boolean }>; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 410 | logging: { |
| 411 | logs: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 412 | enabled: boolean; |
| 413 | channel: string | null; |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 414 | toLog: string; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 415 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 416 | staff: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 417 | channel: string | null; |
| 418 | }; |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 419 | attachments: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 420 | channel: string | null; |
| 421 | saved: Record<string, string>; |
| 422 | }; |
| 423 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 424 | verify: { |
PineaFan | df4996f | 2023-01-01 14:20:06 +0000 | [diff] [blame] | 425 | enabled: boolean; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 426 | role: string | null; |
| 427 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 428 | tickets: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 429 | enabled: boolean; |
| 430 | category: string | null; |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 431 | types: string; |
| 432 | customTypes: string[] | null; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 433 | useCustom: boolean; |
| 434 | supportRole: string | null; |
| 435 | maxTickets: number; |
| 436 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 437 | moderation: { |
| 438 | mute: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 439 | timeout: boolean; |
| 440 | role: string | null; |
| 441 | text: string | null; |
| 442 | link: string | null; |
| 443 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 444 | kick: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 445 | text: string | null; |
| 446 | link: string | null; |
| 447 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 448 | ban: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 449 | text: string | null; |
| 450 | link: string | null; |
| 451 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 452 | softban: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 453 | text: string | null; |
| 454 | link: string | null; |
| 455 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 456 | warn: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 457 | text: string | null; |
| 458 | link: string | null; |
| 459 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 460 | role: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 461 | role: string | null; |
TheCodedProf | d9636e8 | 2023-01-17 22:13:06 -0500 | [diff] [blame] | 462 | text: null; |
| 463 | link: null; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 464 | }; |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 465 | nick: { |
| 466 | text: string | null; |
| 467 | link: string | null; |
| 468 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 469 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 470 | tracks: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 471 | name: string; |
| 472 | retainPrevious: boolean; |
| 473 | nullable: boolean; |
| 474 | track: string[]; |
| 475 | manageableBy: string[]; |
| 476 | }[]; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 477 | roleMenu: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 478 | enabled: boolean; |
| 479 | allowWebUI: boolean; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 480 | options: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 481 | name: string; |
| 482 | description: string; |
| 483 | min: number; |
| 484 | max: number; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 485 | options: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 486 | name: string; |
| 487 | description: string | null; |
| 488 | role: string; |
| 489 | }[]; |
| 490 | }[]; |
| 491 | }; |
| 492 | tags: Record<string, string>; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 493 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 494 | |
| 495 | export interface HistorySchema { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 496 | type: string; |
| 497 | guild: string; |
| 498 | user: string; |
| 499 | moderator: string | null; |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 500 | reason: string | null; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 501 | occurredAt: Date; |
| 502 | before: string | null; |
| 503 | after: string | null; |
| 504 | amount: string | null; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | export interface ModNoteSchema { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 508 | guild: string; |
| 509 | user: string; |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 510 | note: string | null; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 511 | } |
| 512 | |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 513 | export interface PremiumSchema { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 514 | user: string; |
| 515 | level: number; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 516 | appliesTo: string[]; |
TheCodedProf | 633866f | 2023-02-03 17:06:00 -0500 | [diff] [blame] | 517 | expiresAt?: number; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 518 | } |