Compare commits
2 Commits
2af6e35842
...
ac9a59a055
Author | SHA1 | Date | |
---|---|---|---|
ac9a59a055 | |||
884505d8fb |
17
.vscode/launch.json
vendored
Normal file
17
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Launch Program",
|
||||||
|
"skipFiles": [
|
||||||
|
"<node_internals>/**"
|
||||||
|
],
|
||||||
|
"program": "${workspaceFolder}/src/main.js"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -14,7 +14,7 @@ const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = Discord;
|
|||||||
// Various imports from other files
|
// Various imports from other files
|
||||||
const config = require('../data/config.json');
|
const config = require('../data/config.json');
|
||||||
const strings = require('../data/strings.json');
|
const strings = require('../data/strings.json');
|
||||||
const slashCommandFiles = fs.readdirSync('./slash-commands/').filter(file => file.endsWith('.js'));
|
const slashCommandFiles = fs.readdirSync('./src/slash-commands/').filter(file => file.endsWith('.js'));
|
||||||
|
|
||||||
const functions = {
|
const functions = {
|
||||||
// Functions for managing and creating Collections
|
// Functions for managing and creating Collections
|
1083
src/package-lock.json
generated
Normal file
1083
src/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
29
src/slash-commands/chat.js
Normal file
29
src/slash-commands/chat.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||||
|
const fn = require('../modules/functions.js');
|
||||||
|
const strings = require('../data/strings.json');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('chat')
|
||||||
|
.setDescription('Send a message to ChatGPT')
|
||||||
|
.addStringOption(o =>
|
||||||
|
o.setName("prompt")
|
||||||
|
.setDescription("Prompt to send to ChatGPT")
|
||||||
|
.setRequired(true)
|
||||||
|
),
|
||||||
|
async execute(interaction) {
|
||||||
|
await interaction.deferReply();
|
||||||
|
await interaction.editReply(fn.embeds.generatingResponse());
|
||||||
|
const userPrompt = interaction.options.getString("prompt");
|
||||||
|
const response = await fn.openAI.chatPrompt(userPrompt).catch(e => console.error(e));
|
||||||
|
const responseText = response.choices[0].message.content;
|
||||||
|
const usage = {
|
||||||
|
tokens: response.usage.total_tokens,
|
||||||
|
usdc: (response.usage.prompt_tokens * (strings.ai.chatPromptCentsPer / strings.ai.chatPromptUnits)) +
|
||||||
|
(response.usage.completion_tokens * (strings.ai.chatResCentsPer / strings.ai.chatResUnits))
|
||||||
|
};
|
||||||
|
const gptEmbed = fn.embeds.gpt(userPrompt, responseText, usage);
|
||||||
|
await interaction.editReply(gptEmbed);
|
||||||
|
fn.upload.openai(interaction.user.id, userPrompt, strings.ai.chatModel, usage.tokens, usage.usdc);
|
||||||
|
},
|
||||||
|
};
|
40
src/slash-commands/dalle.js
Normal file
40
src/slash-commands/dalle.js
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||||
|
const fn = require('../modules/functions.js');
|
||||||
|
const strings = require("../data/strings.json");
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('dalle')
|
||||||
|
.setDescription('Generate an image with DALL-e')
|
||||||
|
.addStringOption(o =>
|
||||||
|
o.setName("prompt")
|
||||||
|
.setDescription("Prompt to send to DALL-e")
|
||||||
|
.setRequired(true)
|
||||||
|
)
|
||||||
|
.addStringOption(o =>
|
||||||
|
o.setName("size")
|
||||||
|
.setDescription("1024x1024, 512x512, 256x256")
|
||||||
|
.setRequired(false)
|
||||||
|
.addChoices(
|
||||||
|
{ name: "1024x1024 (2¢)", value: "1024x1024" },
|
||||||
|
{ name: "512x512 (1.8¢)", value: "512x512" },
|
||||||
|
{ name: "256x256 (1.6¢)", value: "256x256" }
|
||||||
|
)),
|
||||||
|
async execute(interaction) {
|
||||||
|
try {
|
||||||
|
await interaction.deferReply();
|
||||||
|
await interaction.editReply(fn.embeds.generatingResponse());
|
||||||
|
const userPrompt = interaction.options.getString("prompt");
|
||||||
|
const size = interaction.options.getString("size") ? interaction.options.getString("size") : "512x512";
|
||||||
|
|
||||||
|
const imageUrl = await fn.openAI.imagePrompt(userPrompt, size);
|
||||||
|
const dalleEmbed = fn.embeds.dalle(userPrompt, imageUrl, size);
|
||||||
|
await interaction.editReply(dalleEmbed);
|
||||||
|
fn.upload.openai(interaction.user.id, userPrompt, "dalle", 0, strings.costs.dalle[size]);
|
||||||
|
} catch (err) {
|
||||||
|
const errorId = fn.generateErrorId();
|
||||||
|
console.error(`${errorId}: ${err}`);
|
||||||
|
await interaction.editReply(`An error has occured. Error ID: ${errorId}\n${err}`);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
11
src/slash-commands/ping.js
Normal file
11
src/slash-commands/ping.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||||
|
const fn = require('../modules/functions.js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('ping')
|
||||||
|
.setDescription('Check that the bot is alive and responding.'),
|
||||||
|
async execute(interaction) {
|
||||||
|
await interaction.reply({ content: 'Pong!', ephemeral: true });
|
||||||
|
},
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user