Skip to content

Commit

Permalink
Name changes, remove redundant func param
Browse files Browse the repository at this point in the history
  • Loading branch information
theimperious1 committed Nov 10, 2024
1 parent def8d3c commit 23d3b31
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/discord/commands/global/d.ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {
import { SlashCommand } from '../../@types/commandDef';
import { embedTemplate } from '../../utils/embedTemplate';
import commandContext from '../../utils/context';
import aiChat, { aiModerate, handleMessage } from '../../../global/commands/g.ai';
import aiChat, { aiModerate, handleAiMessageQueue } from '../../../global/commands/g.ai';

/* TODO
* only direct @ message should trigger a response
Expand Down Expand Up @@ -2175,7 +2175,7 @@ export async function aiMessage(
}, 30000); // Failsafe to stop typing indicator after 30 seconds

try {
const chatResponse = await handleMessage(messageData.author.id, aiPersona, messageList, messageData, attachmentInfo);
const chatResponse = await handleAiMessageQueue(aiPersona, messageList, messageData, attachmentInfo);
response = chatResponse.response;
promptTokens = chatResponse.promptTokens;
completionTokens = chatResponse.completionTokens;
Expand Down
11 changes: 5 additions & 6 deletions src/global/commands/g.ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ const aiFunctions = [
];

// Main function for aiChat to handle incoming messages and return a Promise with response data
export function handleMessage(
userId: string,
export function handleAiMessageQueue(
aiPersona: ai_personas,
messages: { role: 'user'; content: string }[],
messageData: Message<boolean>,
Expand All @@ -134,11 +133,11 @@ export function handleMessage(
promptTokens: number;
completionTokens: number;
}> {
if (!userQueues.has(userId)) {
userQueues.set(userId, { queue: [], isProcessing: false });
if (!userQueues.has(messageData.author.id)) {
userQueues.set(messageData.author.id, { queue: [], isProcessing: false });
}

const userQueue = userQueues.get(userId)!;
const userQueue = userQueues.get(messageData.author.id)!;

// Push the new message data into the user's queue
return new Promise((resolve) => {
Expand All @@ -152,7 +151,7 @@ export function handleMessage(

// If the user is not currently processing, start processing
if (!userQueue.isProcessing) {
processNextMessage(userId);
processNextMessage(messageData.author.id);
}
});
}
Expand Down

0 comments on commit 23d3b31

Please sign in to comment.