mirror of
https://github.com/pacnpal/markov-discord.git
synced 2025-12-20 03: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> {
|
||||
let historyCache: MessageRecord[] = [];
|
||||
let keepGoing = true;
|
||||
let oldestMessageID;
|
||||
let oldestMessageID: string | undefined;
|
||||
|
||||
while (keepGoing) {
|
||||
const messages: Discord.Collection<
|
||||
@@ -238,9 +238,10 @@ async function fetchMessages(message: Discord.Message): Promise<void> {
|
||||
return dbObj;
|
||||
});
|
||||
historyCache = historyCache.concat(nonBotMessageFormatted);
|
||||
oldestMessageID = messages.last().id;
|
||||
if (messages.size < PAGE_SIZE) {
|
||||
if (!messages.last() || messages.size < PAGE_SIZE) {
|
||||
keepGoing = false;
|
||||
} else {
|
||||
oldestMessageID = messages.last().id;
|
||||
}
|
||||
}
|
||||
console.log(`Trained from ${historyCache.length} past human authored messages.`);
|
||||
|
||||
Reference in New Issue
Block a user