mirror of
https://github.com/pacnpal/markov-discord.git
synced 2025-12-20 11:01:04 -05:00
Fix error when final message page is exactly the page length.
This commit is contained in:
7
index.ts
7
index.ts
@@ -214,7 +214,7 @@ function validateMessage(message: Discord.Message): string | null {
|
|||||||
async function fetchMessages(message: Discord.Message): Promise<void> {
|
async function fetchMessages(message: Discord.Message): Promise<void> {
|
||||||
let historyCache: MessageRecord[] = [];
|
let historyCache: MessageRecord[] = [];
|
||||||
let keepGoing = true;
|
let keepGoing = true;
|
||||||
let oldestMessageID;
|
let oldestMessageID: string | undefined;
|
||||||
|
|
||||||
while (keepGoing) {
|
while (keepGoing) {
|
||||||
const messages: Discord.Collection<
|
const messages: Discord.Collection<
|
||||||
@@ -238,9 +238,10 @@ async function fetchMessages(message: Discord.Message): Promise<void> {
|
|||||||
return dbObj;
|
return dbObj;
|
||||||
});
|
});
|
||||||
historyCache = historyCache.concat(nonBotMessageFormatted);
|
historyCache = historyCache.concat(nonBotMessageFormatted);
|
||||||
oldestMessageID = messages.last().id;
|
if (!messages.last() || messages.size < PAGE_SIZE) {
|
||||||
if (messages.size < PAGE_SIZE) {
|
|
||||||
keepGoing = false;
|
keepGoing = false;
|
||||||
|
} else {
|
||||||
|
oldestMessageID = messages.last().id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(`Trained from ${historyCache.length} past human authored messages.`);
|
console.log(`Trained from ${historyCache.length} past human authored messages.`);
|
||||||
|
|||||||
Reference in New Issue
Block a user