chore: reformat all code with prettier

This commit is contained in:
modeco80
2024-04-24 03:50:17 -04:00
parent bcbf7db8d9
commit ddae307874
13 changed files with 1053 additions and 1074 deletions

View File

@@ -1,36 +1,36 @@
import { EventEmitter } from "events";
import { EventEmitter } from 'events';
// Class to ratelimit a resource (chatting, logging in, etc)
export default class RateLimiter extends EventEmitter {
private limit : number;
private interval : number;
private requestCount : number;
private limiter? : NodeJS.Timeout;
private limiterSet : boolean;
constructor(limit : number, interval : number) {
super();
this.limit = limit;
this.interval = interval;
this.requestCount = 0;
this.limiterSet = false;
}
// Return value is whether or not the action should be continued
request() : boolean {
this.requestCount++;
if (this.requestCount === this.limit) {
this.emit('limit');
clearTimeout(this.limiter);
this.limiterSet = false;
this.requestCount = 0;
return false;
}
if (!this.limiterSet) {
this.limiter = setTimeout(() => {
this.limiterSet = false;
this.requestCount = 0;
}, this.interval * 1000);
this.limiterSet = true;
}
return true;
}
}
private limit: number;
private interval: number;
private requestCount: number;
private limiter?: NodeJS.Timeout;
private limiterSet: boolean;
constructor(limit: number, interval: number) {
super();
this.limit = limit;
this.interval = interval;
this.requestCount = 0;
this.limiterSet = false;
}
// Return value is whether or not the action should be continued
request(): boolean {
this.requestCount++;
if (this.requestCount === this.limit) {
this.emit('limit');
clearTimeout(this.limiter);
this.limiterSet = false;
this.requestCount = 0;
return false;
}
if (!this.limiterSet) {
this.limiter = setTimeout(() => {
this.limiterSet = false;
this.requestCount = 0;
}, this.interval * 1000);
this.limiterSet = true;
}
return true;
}
}