Initial commit

This commit is contained in:
2025-11-09 10:23:23 +01:00
commit f890341ffe
34 changed files with 1058 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
import {data} from "../appData.js";
export class MessageSender {
constructor(client) {
this.client = client;
}
async send(channelID, message) {
const channel = await data.client.channels.fetch(channelID);
if (channel && channel.isTextBased()) {
await channel.send(message);
} else {
console.log('❌ Channel not found!');
}
}
}

View File

@@ -0,0 +1,32 @@
import EventEmitter from "events";
import {Logger} from "../logging/logger.js";
export class BasePoller extends EventEmitter {
constructor() {
super();
this.task = null;
}
async pollOnce(){
throw new Error("Not implemented.");
}
start(interval) {
if(this.task){
Logger.error("A task has already been scheduled");
return;
}
super.task = setInterval(async () => {
await this.pollOnce();
}, interval);
}
stop() {
if (this.task) {
clearInterval(this.task);
super.task = null;
}
}
}

View File

@@ -0,0 +1,47 @@
export class BaseTokenManager {
/**
*
* @param usersToken {UsersToken}
*/
constructor(usersToken) {
this.usersToken = usersToken;
this.watchDelay = 3600*1000; //1 hour in milliseconds
}
/**
* Launches watch for all users
*/
startWatching() {
this.usersToken.getAll().forEach((user, index) => {
this.watchUser(index);
})
}
/**
* Watches token for a single user
*/
watchUser(userIndex){
setInterval(async () => {
let userData = await this.getUserData(userIndex);
if(this.mustBeRenewed(userData.expiresAt)){
await this.renew(userData);
}
}, this.watchDelay);
}
renew(){
throw new Error("Not implemented.");
}
mustBeRenewed(expiresAt) {
const expirationThreshold = 3600*1000; //1 hour in milliseconds
const timeBeforeExpiration = expiresAt - Date.now();
return timeBeforeExpiration <= expirationThreshold;
}
getUserData(index){
return this.usersToken.get(index);
}
}