rashi-discord-bot-lib
Version:
🚀 Powerful Discord bot framework with built-in database, event handling, and utilities
37 lines • 1.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChatMemory = void 0;
class ChatMemory {
memory = new Map();
maxMessages;
constructor(maxMessages = 10) {
this.maxMessages = maxMessages;
}
/** Zwraca historię wiadomości dla danego użytkownika */
getHistory(userId) {
return this.memory.get(userId) ?? [];
}
/** Dodaje wiadomość do historii użytkownika */
addMessage(userId, message) {
const history = this.getHistory(userId);
if (history.length >= this.maxMessages) {
history.shift(); // usuwa najstarszą wiadomość
}
history.push(message);
this.memory.set(userId, history);
}
/** Czyści historię użytkownika */
clearHistory(userId) {
this.memory.delete(userId);
}
/** Ustawia historię użytkownika ręcznie */
setHistory(userId, messages) {
this.memory.set(userId, messages.slice(-this.maxMessages));
}
/** Sprawdza, czy użytkownik ma jakąś historię */
hasHistory(userId) {
return this.memory.has(userId);
}
}
exports.ChatMemory = ChatMemory;
//# sourceMappingURL=ChatMemory.js.map