import { Client, GatewayIntentBits, Guild, Collection, GuildMember, Message, TextChannel } from 'discord.js' import * as dotenv from 'dotenv' import { DyFM_Error, DyFM_Log, hour, week } from '@futdevpro/fsm-dynamo' import { DyNTS_global_settings } from '../../../_collections/global-settings.const' import { DyNTS_DiBo_IO_ControlService } from '../../discord-bot/_services/dibo-io.control-service' import { DyNTS_DiAs_Main_ControlService } from './dias-main.control-service' import { DyNTS_DiBo_global_settings } from '../../discord-bot/_collections/dibo-global-settings.conts' import { DyNTS_OAI_LLMChat_ServiceBase } from '../../ai/_modules/open-ai/_services/oai-llm-chat.service-base' import { DyFM_AI_Message } from '@futdevpro/fsm-dynamo/ai'; import { DyNTS_DiAs_Util } from '../_collections/dias.util' export abstract class DyNTS_DiAs_IO_ControlService extends DyNTS_DiBo_IO_ControlService { /* static override getInstance(): DyNTS_DiAs_IO_ControlService { return DyNTS_DiAs_IO_ControlService.getSingletonInstance(); } */ /* abstract override getMainDiscordBotControlService(): DyNTS_DiAs_Main_ControlService; */ protected abstract override getMainDiscordBotControlService(): DyNTS_DiAs_Main_ControlService; protected abstract override mainDiscordBot_CS: DyNTS_DiAs_Main_ControlService; /* = this.getMainDiscordBotControlService(); */ /* protected dontSendErrorReply?: boolean; */ get llmChat_CS(): DyNTS_OAI_LLMChat_ServiceBase { return this.mainDiscordBot_CS.llmChat_CS; } override async handleMessage(message: Message, issuer: string): Promise { try { const messages: Message[] = await this.mainDiscordBot_CS.gatherDiscordMessagesForMessage(message); const oaiMessages: DyFM_AI_Message[] = DyNTS_DiAs_Util.convertDiscordMessagesToOAIConversation({ messages: messages, botClientId: this.mainDiscordBot_CS.botClientId, botDisplayName: this.mainDiscordBot_CS.botDisplayName, issuer: issuer, }); const gptResult: string = await this.llmChat_CS.requestSimpleMessageInConversation({ conversation: oaiMessages, settings: { systemPrompt: this.mainDiscordBot_CS.defaultSystemPrompt, }, issuer: issuer, }); return await message.reply(gptResult); } catch (error) { DyFM_Error.logSimple('❌❌ Error handleNewMessage:', error); if (!this.dontSendErrorReply && DyNTS_DiBo_global_settings.debugLevel >= 1) { await message.reply( `[SYSTEM|ERROR|${DyNTS_global_settings.systemShortCodeName}|DyNTS-DiAs-IOCS-H0] Error occurred while handling the message:\n` + DyFM_Error.getAnyMessage(error) ).catch(error => { DyFM_Error.logSimple('❌❌ Error sending message to report channel:', error); }); } throw new DyFM_Error({ ...this.getDefaultErrorSettings('handleMessage', error, issuer), errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DiAs-IOCS-H0`, }) } } }