From 229e741bfdd4a6d8b7b2617eec5e88c626d29e00 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Mon, 28 Jun 2021 18:43:22 +0200 Subject: :sparkles: Rate Limit model --- src/models/RateLimit.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/models/RateLimit.ts (limited to 'src/models/RateLimit.ts') diff --git a/src/models/RateLimit.ts b/src/models/RateLimit.ts new file mode 100644 index 00000000..7e4ca3cc --- /dev/null +++ b/src/models/RateLimit.ts @@ -0,0 +1,26 @@ +import { Schema, Document, Types } from "mongoose"; +import db from "../util/Database"; +import { ChannelModel } from "./Channel"; +import { UserModel } from "./User"; +import { GuildModel } from "./Guild"; + +export interface Bucket { + id: "global" | string; // channel_239842397 | guild_238927349823 | webhook_238923423498 + user: string; + hits: number; + blocked: boolean; +} + +export interface BucketDocument extends Bucket, Document { + id: string; +} + +export const BucketSchema = new Schema({ + id: { type: String, required: true }, + user_id: { type: String, required: true }, // bot, user, oauth_application, webhook + hits: { type: Number, required: true }, // Number of times the user hit this bucket + blocked: { type: Boolean, required: true }, +}); + +// @ts-ignore +export const BucketModel = db.model("Bucket", BucketSchema, "ratelimits"); -- cgit 1.5.1 From e13bdc31272f382773a65508ab7bb5626d1c535e Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Wed, 30 Jun 2021 17:49:19 +0200 Subject: :sparkles: RateLimit Bucket --- src/models/RateLimit.ts | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/models/RateLimit.ts') diff --git a/src/models/RateLimit.ts b/src/models/RateLimit.ts index 7e4ca3cc..6ccfafe0 100644 --- a/src/models/RateLimit.ts +++ b/src/models/RateLimit.ts @@ -9,6 +9,7 @@ export interface Bucket { user: string; hits: number; blocked: boolean; + created_at: Date; } export interface BucketDocument extends Bucket, Document { @@ -20,6 +21,7 @@ export const BucketSchema = new Schema({ user_id: { type: String, required: true }, // bot, user, oauth_application, webhook hits: { type: Number, required: true }, // Number of times the user hit this bucket blocked: { type: Boolean, required: true }, + created_at: { type: Date, required: true }, }); // @ts-ignore -- cgit 1.5.1 From 3a8c7ec1c338d52b50a63d4e783820d4d5c55917 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Thu, 1 Jul 2021 11:13:12 +0200 Subject: :sparkles: Rate Limit Bucket --- src/models/RateLimit.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src/models/RateLimit.ts') diff --git a/src/models/RateLimit.ts b/src/models/RateLimit.ts index 6ccfafe0..6a0e1ffd 100644 --- a/src/models/RateLimit.ts +++ b/src/models/RateLimit.ts @@ -1,15 +1,12 @@ import { Schema, Document, Types } from "mongoose"; import db from "../util/Database"; -import { ChannelModel } from "./Channel"; -import { UserModel } from "./User"; -import { GuildModel } from "./Guild"; export interface Bucket { - id: "global" | string; // channel_239842397 | guild_238927349823 | webhook_238923423498 - user: string; + id: "global" | "error" | string; // channel_239842397 | guild_238927349823 | webhook_238923423498 + user_id: string; hits: number; blocked: boolean; - created_at: Date; + expires_at: Date; } export interface BucketDocument extends Bucket, Document { @@ -21,7 +18,7 @@ export const BucketSchema = new Schema({ user_id: { type: String, required: true }, // bot, user, oauth_application, webhook hits: { type: Number, required: true }, // Number of times the user hit this bucket blocked: { type: Boolean, required: true }, - created_at: { type: Date, required: true }, + expires_at: { type: Date, required: true }, }); // @ts-ignore -- cgit 1.5.1