Improved information display mode
This commit is contained in:
parent
54417cfb0f
commit
58e9b0c646
@ -2,7 +2,7 @@ import {
|
|||||||
CommandInteraction,
|
CommandInteraction,
|
||||||
Client,
|
Client,
|
||||||
CommandInteractionOptionResolver,
|
CommandInteractionOptionResolver,
|
||||||
TextChannel, ApplicationCommandType, ApplicationCommandOptionType,
|
TextChannel, ApplicationCommandType, ApplicationCommandOptionType, Colors,
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import { ChatCompletionRequestMessage } from 'openai';
|
import { ChatCompletionRequestMessage } from 'openai';
|
||||||
import { Command } from '@/bot/models/command';
|
import { Command } from '@/bot/models/command';
|
||||||
@ -29,7 +29,7 @@ export const ChatCommand: Command = {
|
|||||||
/**
|
/**
|
||||||
* Get the chat history from the channel
|
* Get the chat history from the channel
|
||||||
*/
|
*/
|
||||||
const channel = client.channels.cache.get(interaction.channelId) as TextChannel;
|
const channel = client.channels.cache.get(interaction.channelId) as TextChannel; // Get the channel from the channel id
|
||||||
const messages = await channel.messages.fetch({ limit: 100 }); // Get the last 100 messages from the channel
|
const messages = await channel.messages.fetch({ limit: 100 }); // Get the last 100 messages from the channel
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,8 +48,8 @@ export const ChatCommand: Command = {
|
|||||||
* Create the message object from the embed and add it to the chat history
|
* Create the message object from the embed and add it to the chat history
|
||||||
*/
|
*/
|
||||||
const message: ChatCompletionRequestMessage = {
|
const message: ChatCompletionRequestMessage = {
|
||||||
role: item.footer?.text === 'embed-question' ? 'user' : 'assistant',
|
role: item.footer?.text === 'embed-question' ? 'user' : 'assistant', // Check if the message is a question from the user or an answer from the bot
|
||||||
content: item.description || 'An error occurred during the process, please try again later.',
|
content: item.description || 'An error occurred during the process, please try again later.', // Get the description from the embed or set it to an error message
|
||||||
};
|
};
|
||||||
|
|
||||||
chatHistory.push(message); // Add the message to the chat history
|
chatHistory.push(message); // Add the message to the chat history
|
||||||
@ -58,9 +58,9 @@ export const ChatCommand: Command = {
|
|||||||
/**
|
/**
|
||||||
* Get the options from the interaction
|
* Get the options from the interaction
|
||||||
*/
|
*/
|
||||||
const interactionResolver = (interaction.options as CommandInteractionOptionResolver);
|
const interactionResolver = (interaction.options as CommandInteractionOptionResolver); // Get the options from the interaction
|
||||||
const question = interactionResolver.getString('question') || undefined; // Default to undefined
|
const question = interactionResolver.getString('question') || undefined; // Get the question from the options or set it to undefined
|
||||||
const ephemeral = interactionResolver.getBoolean('ephemeral') || true; // Default to true
|
const ephemeral = interactionResolver.getBoolean('ephemeral') || true; // Get the ephemeral option from the options or set it to true
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the current question to the chat history
|
* Add the current question to the chat history
|
||||||
@ -76,8 +76,8 @@ export const ChatCommand: Command = {
|
|||||||
* Get the answer from the AI
|
* Get the answer from the AI
|
||||||
*/
|
*/
|
||||||
const answer = await ai?.chatCompletion(chatHistory)
|
const answer = await ai?.chatCompletion(chatHistory)
|
||||||
.then((response) => response.content)
|
.then((response) => response.content) // Get the content from the response
|
||||||
.catch((error: Error) => error.message);
|
.catch((error: Error) => error.message); // Get the error message from the error
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the current answer to the chat history and reply to the user on the channel
|
* Add the current answer to the chat history and reply to the user on the channel
|
||||||
@ -87,20 +87,28 @@ export const ChatCommand: Command = {
|
|||||||
fetchReply: true,
|
fetchReply: true,
|
||||||
embeds: [
|
embeds: [
|
||||||
{
|
{
|
||||||
color: 15844367,
|
color: Colors.Gold,
|
||||||
title: '✥ Question',
|
author: {
|
||||||
description: question,
|
name: interaction.user.username, // Get the username from the user
|
||||||
footer: {
|
icon_url: interaction.user.avatarURL() || undefined, // Get the avatar from the user or default to undefined
|
||||||
text: 'embed-question', // embed-question is used to identify is an interaction from user to bot
|
|
||||||
},
|
},
|
||||||
|
description: question, // Get the question from the user
|
||||||
|
footer: {
|
||||||
|
text: 'embed-question', // Mark the embed as a question from the user
|
||||||
|
},
|
||||||
|
timestamp: new Date().toISOString(), // Add the timestamp to the embed
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
color: 5763719,
|
color: Colors.Green,
|
||||||
title: '✥ Answer',
|
author: {
|
||||||
description: answer,
|
name: client.user?.username || 'Aurora GPT', // Get the username from the bot or default to Aurora GPT
|
||||||
footer: {
|
icon_url: client.user?.avatarURL() || undefined, // Get the avatar from the bot or default to undefined
|
||||||
text: 'embed-answer', // embed-answer is used to identify is an interaction from bot to user
|
|
||||||
},
|
},
|
||||||
|
description: answer, // Get the answer from the AI
|
||||||
|
footer: {
|
||||||
|
text: 'embed-answer', // Mark the embed as an answer from the bot
|
||||||
|
},
|
||||||
|
timestamp: new Date().toISOString(), // Add the timestamp to the embed
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
@ -11,13 +11,13 @@ export const ClearCommand: Command = {
|
|||||||
/**
|
/**
|
||||||
* Get the chat history from the channel and filter the messages from the user
|
* Get the chat history from the channel and filter the messages from the user
|
||||||
*/
|
*/
|
||||||
const channel = client.channels.cache.get(interaction.channelId) as TextChannel;
|
const channel = client.channels.cache.get(interaction.channelId) as TextChannel; // Get the channel from the channel id
|
||||||
const messages = await channel.messages.fetch({ limit: 100 }); // Get the last 100 messages from the channel
|
const messages = await channel.messages.fetch({ limit: 100 }); // Get the last 100 messages from the channel
|
||||||
const consistentMessages = messages
|
const consistentMessages = messages
|
||||||
.filter((x) => x.interaction?.user.id === interaction.user.id);
|
.filter((x) => x.interaction?.user.id === interaction.user.id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete the messages from the channel
|
* Check if the channel is a guild text channel or a DM channel
|
||||||
*/
|
*/
|
||||||
if (channel.type === ChannelType.GuildText) {
|
if (channel.type === ChannelType.GuildText) {
|
||||||
/**
|
/**
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import { CommandInteraction, Client, ApplicationCommandType } from 'discord.js';
|
import {
|
||||||
|
CommandInteraction, Client, ApplicationCommandType, Colors,
|
||||||
|
} from 'discord.js';
|
||||||
import { Command } from '@/bot/models/command';
|
import { Command } from '@/bot/models/command';
|
||||||
|
|
||||||
export const PingCommand: Command = {
|
export const PingCommand: Command = {
|
||||||
@ -6,13 +8,27 @@ export const PingCommand: Command = {
|
|||||||
description: 'Ping the bot to check if it is online',
|
description: 'Ping the bot to check if it is online',
|
||||||
type: ApplicationCommandType.ChatInput,
|
type: ApplicationCommandType.ChatInput,
|
||||||
execute: async (client: Client, interaction: CommandInteraction) => {
|
execute: async (client: Client, interaction: CommandInteraction) => {
|
||||||
const content = 'Pong';
|
/**
|
||||||
|
* Create the content for the message and calculate the latency
|
||||||
|
*/
|
||||||
|
const content = `Client Latency is: **${Date.now() - interaction.createdTimestamp}ms**\nAPI Latency is: **${Date.now() - interaction.createdTimestamp}ms**`;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a message to the channel
|
* Send a message to the channel
|
||||||
*/
|
*/
|
||||||
await interaction.followUp({
|
await interaction.followUp({
|
||||||
ephemeral: true,
|
ephemeral: true,
|
||||||
content,
|
embeds: [
|
||||||
|
{
|
||||||
|
color: Colors.Aqua,
|
||||||
|
title: 'Pong',
|
||||||
|
description: content,
|
||||||
|
timestamp: new Date().toISOString(), // Set the timestamp to the current time
|
||||||
|
footer: {
|
||||||
|
text: 'embed-ping', // Mark the message as a ping message
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user