Initial Emmelia merge
This commit is contained in:
47
Server/commands/add.js
Normal file
47
Server/commands/add.js
Normal file
@@ -0,0 +1,47 @@
|
||||
const libCore = require("../libCore.js");
|
||||
const { SlashCommandBuilder } = require('discord.js');
|
||||
|
||||
const { DebugBuilder } = require("../utilities/debugBuilder");
|
||||
const log = new DebugBuilder("server", "add");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('add')
|
||||
.setDescription('Add RSS Source')
|
||||
.addStringOption(option =>
|
||||
option.setName('title')
|
||||
.setDescription('The title of the RSS feed')
|
||||
.setRequired(true))
|
||||
.addStringOption(option =>
|
||||
option.setName('link')
|
||||
.setDescription('The link to the RSS feed')
|
||||
.setRequired(true))
|
||||
.addStringOption(option =>
|
||||
option.setName('category')
|
||||
.setDescription('The category for the RSS feed *("ALL" by default")*')
|
||||
.setRequired(false)),
|
||||
example: "add [title] [https://domain.com/feed.xml] [category]",
|
||||
isPrivileged: false,
|
||||
async execute(interaction, args) {
|
||||
try {
|
||||
var title = interaction.options.getString('title');
|
||||
var link = interaction.options.getString('link');
|
||||
var category = interaction.options.getString('category');
|
||||
|
||||
if (!category) category = "ALL";
|
||||
|
||||
await libCore.addSource(title, link, category, interaction.guildId, interaction.channelId, (err, result) => {
|
||||
log.DEBUG("Result from adding entry", result);
|
||||
|
||||
if (result) {
|
||||
interaction.reply(`Adding ${title} to the list of RSS sources`);
|
||||
} else {
|
||||
interaction.reply(`${title} already exists in the list of RSS sources`);
|
||||
}
|
||||
});
|
||||
}catch(err){
|
||||
log.ERROR(err)
|
||||
await interaction.reply(err.toString());
|
||||
}
|
||||
}
|
||||
};
|
||||
28
Server/commands/balance.js
Normal file
28
Server/commands/balance.js
Normal file
@@ -0,0 +1,28 @@
|
||||
const { SlashCommandBuilder } = require('discord.js');
|
||||
const { DebugBuilder } = require("../utilities/debugBuilder");
|
||||
const log = new DebugBuilder("server", "balance");
|
||||
|
||||
const { checkBalance } = require("../controllers/accountController");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('balance')
|
||||
.setDescription('Check your balance of AI tokens'),
|
||||
example: "balance",
|
||||
isPrivileged: false,
|
||||
requiresTokens: false,
|
||||
defaultTokenUsage: 0,
|
||||
deferInitialReply: false,
|
||||
async execute(interaction) {
|
||||
try{
|
||||
checkBalance(interaction.member.id, async (err, balance) => {
|
||||
if (err) throw err;
|
||||
|
||||
await interaction.reply({ content: `${interaction.member.user}, you have ${balance} tokens remaining`, ephemeral: true })
|
||||
})
|
||||
}catch(err){
|
||||
log.ERROR(err)
|
||||
await interaction.reply(`Sorry ${interaction.member.user}, something went wrong`);
|
||||
}
|
||||
}
|
||||
};
|
||||
27
Server/commands/category.js
Normal file
27
Server/commands/category.js
Normal file
@@ -0,0 +1,27 @@
|
||||
var libCore = require("../libCore.js");
|
||||
const { SlashCommandBuilder } = require('discord.js');
|
||||
const { DebugBuilder } = require("../utilities/debugBuilder");
|
||||
const log = new DebugBuilder("server", "categories");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('categories')
|
||||
.setDescription('Return all categories'),
|
||||
example: "categories",
|
||||
isPrivileged: false,
|
||||
async execute(interaction) {
|
||||
await libCore.getCategories(async (err, categoryResults) => {
|
||||
if (err) throw err;
|
||||
|
||||
log.DEBUG("Returned Categories: ", categoryResults);
|
||||
var categories = [];
|
||||
for (const record of categoryResults) {
|
||||
categories.push(record.category);
|
||||
}
|
||||
|
||||
await interaction.reply(
|
||||
`Categories: [${categories}]`
|
||||
);
|
||||
});
|
||||
}
|
||||
};
|
||||
61
Server/commands/chat.js
Normal file
61
Server/commands/chat.js
Normal file
@@ -0,0 +1,61 @@
|
||||
const { submitTextPromptTransaction } = require("../controllers/openAiController");
|
||||
const { SlashCommandBuilder } = require('discord.js');
|
||||
const { DebugBuilder } = require("../utilities/debugBuilder");
|
||||
const log = new DebugBuilder("server", "chat");
|
||||
const { EmmeliaEmbedBuilder } = require('../libUtils');
|
||||
|
||||
const COST_OF_COMMAND = 100
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('chat')
|
||||
.setDescription(`Send a text prompt to ChatGPT`)
|
||||
.addStringOption(option =>
|
||||
option.setName('prompt')
|
||||
.setDescription('The prompt to be sent to ChatGPT')
|
||||
.setRequired(true))
|
||||
.addBooleanOption(option =>
|
||||
option.setName('public')
|
||||
.setDescription("Set this to false if you would like the message to only be visible to you. *defaults to public*")
|
||||
.setRequired(false))
|
||||
.addNumberOption(option =>
|
||||
option.setName('temperature')
|
||||
.setDescription('Set the temperature, 0 = repetitive, 1 = random; Defaults to 0')
|
||||
.setRequired(false))
|
||||
.addNumberOption(option =>
|
||||
option.setName('tokens')
|
||||
.setDescription(`The max amount of tokens to be spent, defaults to ${COST_OF_COMMAND}`)
|
||||
.setRequired(false)),
|
||||
example: "chat [tell me a story] [0.07] [400]", // Need to figure out the tokens
|
||||
isPrivileged: false,
|
||||
requiresTokens: true,
|
||||
defaultTokenUsage: 100,
|
||||
deferInitialReply: true,
|
||||
async execute(interaction) {
|
||||
const promptText = interaction.options.getString('prompt');
|
||||
const temperature = interaction.options.getNumber('temperature') ?? undefined;
|
||||
const maxTokens = interaction.options.getNumber('tokens') ?? undefined;
|
||||
const discordAccountId = interaction.member.id;
|
||||
try {
|
||||
submitTextPromptTransaction(promptText, temperature, maxTokens, discordAccountId, interaction, this, async (err, result) => {
|
||||
if (err) throw err;
|
||||
|
||||
const gptEmbed = new EmmeliaEmbedBuilder()
|
||||
.setColor(0x0099FF)
|
||||
.setTitle(`New GPT response`)
|
||||
.setDescription(`${interaction.member.user} sent: '${promptText}'`)
|
||||
.addFields(
|
||||
{ name: 'Generated Text', value: result.promptResult },
|
||||
)
|
||||
.addFields({ name: 'Tokens Used', value: `${result.totalTokens}`, inline: true })
|
||||
|
||||
await interaction.editReply({ embeds: [gptEmbed], ephemeral: false });
|
||||
});
|
||||
|
||||
// Needs reply code to reply to the generation
|
||||
}catch(err){
|
||||
log.ERROR(err)
|
||||
//await interaction.reply(err.toString());
|
||||
}
|
||||
}
|
||||
};
|
||||
18
Server/commands/exit.js
Normal file
18
Server/commands/exit.js
Normal file
@@ -0,0 +1,18 @@
|
||||
const libUtils = require("../libUtils.js");
|
||||
const discordAuth = require("../middleware/discordAuthorization");
|
||||
const { SlashCommandBuilder } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('exit')
|
||||
.setDescription('Exit the current application.'),
|
||||
example: "exit",
|
||||
isPrivileged: true,
|
||||
async execute(interaction) {
|
||||
// TODO - Need to add middleware for admins
|
||||
await interaction.reply(
|
||||
`Goodbye world - Disconnection imminent.`
|
||||
);
|
||||
libUtils.runAfter(process.exit, 5000);
|
||||
}
|
||||
};
|
||||
63
Server/commands/help.js
Normal file
63
Server/commands/help.js
Normal file
@@ -0,0 +1,63 @@
|
||||
const fs = require('fs');
|
||||
const path = require('node:path');
|
||||
const { SlashCommandBuilder } = require('discord.js');
|
||||
|
||||
const { DebugBuilder } = require("../utilities/debugBuilder");
|
||||
const log = new DebugBuilder("server", "help");
|
||||
|
||||
const { EmmeliaEmbedBuilder } = require("../libUtils");
|
||||
|
||||
const commandsPath = path.resolve(__dirname, '../commands'); // Resolves from either working dir or __dirname
|
||||
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('help')
|
||||
.setDescription('Display this help message'),
|
||||
example: "help",
|
||||
isPrivileged: false,
|
||||
async execute(interaction) {
|
||||
try{
|
||||
generalCommandText = "";
|
||||
paidCommandText = "";
|
||||
|
||||
for (const file of commandFiles) {
|
||||
const filePath = path.join(commandsPath, file);
|
||||
const command = require(filePath);
|
||||
|
||||
if (!command.isPrivileged){ // TODO - Need to add middleware for admins
|
||||
if (!command.requiresTokens){
|
||||
if (generalCommandText.length > 1 && generalCommandText.slice(-2) != `\n`){
|
||||
generalCommandText += `\n\n`;
|
||||
}
|
||||
|
||||
generalCommandText += `**/${command.data.name}** - *${command.data.description}*`;
|
||||
|
||||
if (command.example) generalCommandText += `\n\t\t***Usage:*** \`/${command.example}\``
|
||||
}
|
||||
else{
|
||||
if (paidCommandText.length > 1 && paidCommandText.slice(-2) != `\n`){
|
||||
paidCommandText += `\n\n`;
|
||||
}
|
||||
|
||||
paidCommandText += `**/${command.data.name}** - *${command.data.description}*`;
|
||||
|
||||
if (command.example) paidCommandText += `\n\t\t***Usage:*** \`/${command.example}\``
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const helpEmbed = new EmmeliaEmbedBuilder()
|
||||
.setColor(0x0099FF)
|
||||
.setTitle(`Help`)
|
||||
.addFields(
|
||||
{ name: 'General Commands', value: `${generalCommandText}` },
|
||||
{ name: 'Paid Commands', value: `${paidCommandText}` }
|
||||
)
|
||||
await interaction.reply({ embeds: [helpEmbed], ephemeral: true });
|
||||
}catch(err){
|
||||
log.ERROR(err)
|
||||
//await interaction.reply(err.toString());
|
||||
}
|
||||
}
|
||||
};
|
||||
81
Server/commands/imagine.js
Normal file
81
Server/commands/imagine.js
Normal file
@@ -0,0 +1,81 @@
|
||||
const { submitImagePromptTransaction, DALLE_COLOR } = require("../controllers/openAiController");
|
||||
const { SlashCommandBuilder } = require('discord.js');
|
||||
const { DebugBuilder } = require("../utilities/debugBuilder");
|
||||
const log = new DebugBuilder("server", "imagine");
|
||||
const { EmmeliaEmbedBuilder } = require('../libUtils');
|
||||
|
||||
const COST_OF_COMMAND = 800;
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('imagine')
|
||||
.setDescription(`Submit an image generation prompt to DALL-E`)
|
||||
.addStringOption(option =>
|
||||
option.setName('prompt')
|
||||
.setDescription('The prompt to be sent to DALL-E')
|
||||
.setRequired(true))
|
||||
.addBooleanOption(option =>
|
||||
option.setName('public')
|
||||
.setDescription("Set this to false if you would like the message to only be visible to you. *defaults to public*")
|
||||
.setRequired(false))
|
||||
.addNumberOption(option =>
|
||||
option.setName('images')
|
||||
.setDescription('The number of images you wish to generate [1 - 10] *(defaults to 1)*')
|
||||
.setRequired(false))
|
||||
.addStringOption(option =>
|
||||
option.setName('size')
|
||||
.setDescription('The size of the images to be generated *defaults to 256px*')
|
||||
.addChoices(
|
||||
{ name: '1024px - 1000 tokens', value: '1024x1024' },
|
||||
{ name: '512px - 900 tokens', value: '512x512' },
|
||||
{ name: '256px - 800 tokens', value: '256x256' },
|
||||
)
|
||||
.setRequired(false)),
|
||||
example: "imagine [the sinking of the titanic on acid] [4] [", // Need to figure out the tokens
|
||||
isPrivileged: false,
|
||||
requiresTokens: true,
|
||||
defaultTokenUsage: COST_OF_COMMAND,
|
||||
deferInitialReply: true,
|
||||
async execute(interaction) {
|
||||
const promptText = interaction.options.getString('prompt');
|
||||
const images = interaction.options.getNumber('images') ?? undefined;
|
||||
const size = interaction.options.getString('size') ?? undefined;
|
||||
const discordAccountId = interaction.member.id;
|
||||
try {
|
||||
submitImagePromptTransaction(promptText, discordAccountId, images, size, interaction, this, async (err, imageResults) => {
|
||||
if (err) throw err;
|
||||
|
||||
var dalleEmbeds = [];
|
||||
log.DEBUG("Image Results: ", imageResults)
|
||||
// Add the information post
|
||||
dalleEmbeds.push(new EmmeliaEmbedBuilder()
|
||||
.setColor(DALLE_COLOR)
|
||||
.setTitle(`New Image Result`)
|
||||
.setDescription(`${interaction.member.user} sent the prompt: '${promptText}'`)
|
||||
);
|
||||
// Add the images to the result
|
||||
const imagesInResult = Array(imageResults.results).length
|
||||
log.DEBUG("Images in the result: ", imagesInResult);
|
||||
if (imagesInResult >= 1) {
|
||||
for (const imageData of imageResults.results.data){
|
||||
const imageUrl = imageData.url;
|
||||
dalleEmbeds.push(new EmmeliaEmbedBuilder().setURL(imageUrl).setImage(imageUrl).setColor(DALLE_COLOR));
|
||||
}
|
||||
}
|
||||
// Add the information post
|
||||
dalleEmbeds.push(new EmmeliaEmbedBuilder()
|
||||
.setColor(DALLE_COLOR)
|
||||
.addFields({ name: 'Tokens Used', value: `${imageResults.totalTokens}`, inline: true })
|
||||
.addFields({ name: 'Images Generated', value: `${imagesInResult}`, inline: true })
|
||||
.addFields({ name: 'Image Size Requested', value: `${imagesInResult}`, inline: true })
|
||||
);
|
||||
await interaction.editReply({ embeds: dalleEmbeds, ephemeral: false });
|
||||
});
|
||||
|
||||
// Needs reply code to reply to the generation
|
||||
}catch(err){
|
||||
log.ERROR(err)
|
||||
//await interaction.reply(err.toString());
|
||||
}
|
||||
}
|
||||
};
|
||||
29
Server/commands/ping.js
Normal file
29
Server/commands/ping.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const { SlashCommandBuilder } = require('discord.js');
|
||||
const { DebugBuilder } = require("../utilities/debugBuilder");
|
||||
const log = new DebugBuilder("server", "ping");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('ping')
|
||||
.setDescription('Replies with your input!'),
|
||||
/*
|
||||
.addStringOption(option =>
|
||||
option.setName('input')
|
||||
.setDescription('The input to echo back')
|
||||
.setRequired(false)
|
||||
.addChoices()),
|
||||
*/
|
||||
example: "ping",
|
||||
isPrivileged: false,
|
||||
requiresTokens: false,
|
||||
defaultTokenUsage: 0,
|
||||
deferInitialReply: false,
|
||||
async execute(interaction) {
|
||||
try{
|
||||
await interaction.channel.send('**Pong.**'); // TODO - Add insults as the response to this command
|
||||
}catch(err){
|
||||
log.ERROR(err)
|
||||
//await interaction.reply(err.toString());
|
||||
}
|
||||
}
|
||||
};
|
||||
34
Server/commands/pricing.js
Normal file
34
Server/commands/pricing.js
Normal file
@@ -0,0 +1,34 @@
|
||||
const { SlashCommandBuilder } = require('discord.js');
|
||||
const { DebugBuilder } = require("../utilities/debugBuilder");
|
||||
const log = new DebugBuilder("server", "pricing");
|
||||
|
||||
const { EmmeliaEmbedBuilder } = require("../libUtils");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('pricing')
|
||||
.setDescription('Replies with the pricing for tokens'),
|
||||
example: "pricing",
|
||||
isPrivileged: false,
|
||||
requiresTokens: false,
|
||||
defaultTokenUsage: 0,
|
||||
deferInitialReply: false,
|
||||
async execute(interaction) {
|
||||
try{
|
||||
const pricingEmbed = new EmmeliaEmbedBuilder()
|
||||
.setColor(0x0099FF)
|
||||
.setTitle(`Emmelia's Pricing`)
|
||||
.addFields(
|
||||
{ name: 'Tokens', value: `Tokens are a shared currency that is used between all AI models. Each model is charges tokens differently however, so do keep this in mind. $1 = 45,000 tokens` },
|
||||
{ name: 'Text (ChatGPT)', value: `Tokens are used in the prompt and in the response of a generation. The max tokens will not be breached by the combined prompt and response. Keep this is mind when using text generations. Each syllable is one token. This section is 50 tokens.` },
|
||||
{ name: 'Images (DALL-E)', value: `Tokens are used for each generation, variation, and upscale. The image size also affects the amount of tokens used: 256px = 800 tokens, 512px = 900 tokens, 1024px = 1000 tokens` }
|
||||
)
|
||||
|
||||
await interaction.reply({ embeds: [pricingEmbed] });
|
||||
|
||||
}catch(err){
|
||||
log.ERROR(err)
|
||||
//await interaction.reply(err.toString());
|
||||
}
|
||||
}
|
||||
};
|
||||
36
Server/commands/remove.js
Normal file
36
Server/commands/remove.js
Normal file
@@ -0,0 +1,36 @@
|
||||
var libCore = require("../libCore.js");
|
||||
|
||||
const { SlashCommandBuilder } = require('discord.js');
|
||||
const { DebugBuilder } = require("../utilities/debugBuilder");
|
||||
const log = new DebugBuilder("server", "remove");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('remove')
|
||||
.setDescription('Remove an RSS source by it\' title')
|
||||
.addStringOption(option =>
|
||||
option.setName('title')
|
||||
.setDescription('The title of the source to remove')
|
||||
.setRequired(true)),
|
||||
example: "remove ['Leafly']",
|
||||
isPrivileged: false,
|
||||
requiresTokens: false,
|
||||
async execute(interaction) {
|
||||
try{
|
||||
var title = interaction.options.getString("title");
|
||||
|
||||
libCore.deleteSource(title, (err, result) => {
|
||||
log.DEBUG("Result from removing entry", result);
|
||||
|
||||
if (result) {
|
||||
interaction.reply(`Removing ${title} from the list of RSS sources`);
|
||||
} else {
|
||||
interaction.reply(`${title} does not exist in the list of RSS sources`);
|
||||
}
|
||||
});
|
||||
}catch(err){
|
||||
log.ERROR(err)
|
||||
interaction.reply(err.toString());
|
||||
}
|
||||
}
|
||||
};
|
||||
29
Server/commands/sources.js
Normal file
29
Server/commands/sources.js
Normal file
@@ -0,0 +1,29 @@
|
||||
var libCore = require("../libCore.js");
|
||||
|
||||
const { SlashCommandBuilder } = require('discord.js');
|
||||
const { DebugBuilder } = require("../utilities/debugBuilder");
|
||||
const log = new DebugBuilder("server", "sources");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('sources')
|
||||
.setDescription('Reply with all of the available sources'),
|
||||
example: "sources",
|
||||
isPrivileged: false,
|
||||
requiresTokens: false,
|
||||
async execute(interaction) {
|
||||
try{
|
||||
var sourceArray = libCore.getSources();
|
||||
var sourceString = "";
|
||||
|
||||
sourceArray.forEach(source => {
|
||||
sourceString +=`[${source.title}](${source.link}) \n`;
|
||||
});
|
||||
|
||||
await interaction.reply(sourceString);
|
||||
}catch(err){
|
||||
log.ERROR(err)
|
||||
//await interaction.reply(err.toString());
|
||||
}
|
||||
}
|
||||
};
|
||||
37
Server/commands/weather.js
Normal file
37
Server/commands/weather.js
Normal file
@@ -0,0 +1,37 @@
|
||||
var libCore = require("../libCore.js");
|
||||
|
||||
const { SlashCommandBuilder } = require('discord.js');
|
||||
const { DebugBuilder } = require("../utilities/debugBuilder");
|
||||
const log = new DebugBuilder("server", "alert");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('weather')
|
||||
.setDescription('Get any current weather alerts in the state specified.')
|
||||
.addStringOption(option =>
|
||||
option.setName('state')
|
||||
.setDescription('The state to get any current weather alerts from')
|
||||
.setRequired(false)
|
||||
.addChoices()),
|
||||
example: "alert [state]",
|
||||
isPrivileged: false,
|
||||
requiresTokens: false,
|
||||
async execute(interaction) {
|
||||
try{
|
||||
var question = encodeURIComponent(interaction.options.getString("state").join(" "));
|
||||
|
||||
var answerData = await libCore.weatherAlert(question);
|
||||
answerData.forEach(feature => {
|
||||
interaction.reply(`
|
||||
${feature.properties.areaDesc}
|
||||
${feature.properties.headline}
|
||||
${feature.properties.description}
|
||||
`);
|
||||
});
|
||||
|
||||
}catch(err){
|
||||
log.ERROR(err)
|
||||
//await interaction.reply(err.toString());
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user