1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-11-17 16:30:58 -05:00
Daggerbot-TS/src/models/bannedWords.ts

38 lines
1.0 KiB
TypeScript
Raw Normal View History

2023-04-14 06:47:58 -04:00
import TClient from '../client.js';
2023-02-24 19:55:11 -05:00
import mongoose from 'mongoose';
2023-10-02 18:40:03 -04:00
import CacheServer from '../funcs/CacheServer.js';
2023-02-24 19:55:11 -05:00
const Schema = mongoose.model('bannedWords', new mongoose.Schema({
_id: {type: String, required:true}
2023-02-27 02:14:54 -05:00
}, {versionKey: false}));
2023-02-24 19:55:11 -05:00
export default class bannedWords extends Schema {
client: TClient;
_content: typeof Schema;
constructor(client:TClient){
super();
this.client = client;
this._content = Schema;
}
2023-10-02 18:40:03 -04:00
async findInCache(): Promise<any> {
const cacheKey = 'bannedWords';
const cachedResult = await CacheServer.get(cacheKey);
let result;
if (cachedResult) {
try {
result = cachedResult;
} catch (error) {
console.error('Error parsing cached result:', error);
result = await this._content.find();
CacheServer.set(cacheKey, result);
CacheServer.expiry(cacheKey, 180);
}
} else {
result = await this._content.find();
CacheServer.set(cacheKey, result);
CacheServer.expiry(cacheKey, 180);
}
return result;
}
2023-02-24 19:55:11 -05:00
}