adding modal for formatted input

This commit is contained in:
Raven Scott 2023-01-04 13:58:27 -05:00
parent 16736ec18f
commit 55171efd7f
4 changed files with 254 additions and 165 deletions

91
commands/Info/general.js Normal file
View File

@ -0,0 +1,91 @@
const { EmbedBuilder } = require('discord.js');
var unirest = require('unirest');
const cmd = require('cmd-promise')
const fs = require("fs");
let lang
module.exports = {
name: "send",
private: false,
description: "send an inquiry to the AI",
options: [{
"name": "inquiry",
"description": "What you would like to send.",
"required": true,
"type": 3 // 6 is type USER
}],
run: async (client, interaction) => {
// await interaction.deferReply();
let data = interaction.options._hoistedOptions[0].value
function detectCodingLanguages(str) {
const languages = {
'javascript': 'js',
'nodejs': 'js',
'node': 'js',
'python': 'py',
'ruby': 'rb',
'c#': 'csharp',
'c++': 'cpp',
'php': 'php',
'go': 'go',
'bash': 'bash'
};
let detectedLanguages = [];
for (let language in languages) {
if (str.includes(language)) {
detectedLanguages.push(languages[language]);
}
}
return detectedLanguages;
}
console.log(detectCodingLanguages(data)[0])
if (detectCodingLanguages(data)) {
lang = detectCodingLanguages(data)[0]
} else {
lang = "js"
}
unirest
.post('https://codex-ai-v9q6.onrender.com/')
.headers({ 'Accept': 'application/json', 'Content-Type': 'application/json' })
.send({ "prompt": data })
.then((response) => {
if (response.body.bot.length > 1980) {
fs.writeFile('/tmp/paste', response.body.bot, err => {
if (err) {
console.error(err)
return
}
})
cmd("sleep 2; cat /tmp/paste | dpaste").then(pasteout => {
const mainEmbed = new EmbedBuilder()
.setColor('#0099ff')
.addFields(
{ name: 'Please check the below output log:', value: pasteout.stdout.replace("Pro tip: you can password protect your paste just by typing a username and password after your paste command.", "").replace("Paste Saved: ", "").replace("-------------------------------------------------------", "") },
).setTitle("Response too large")
.setDescription("Our AI was too Powerful!")
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
(async () => {
return await interaction.editReply({ embeds: [mainEmbed] })
})();
})
} else {
(async () => {
await interaction.editReply("```" + lang + response.body.bot + "```")
})();
}
})
},
};

129
commands/Info/modal.js Normal file
View File

@ -0,0 +1,129 @@
const { ActionRowBuilder, ModalBuilder, TextInputBuilder, TextInputStyle } = require('discord.js');
var unirest = require('unirest');
module.exports = {
name: "advanced",
description: "Formatted submit",
run: async (client, interaction) => {
// await interaction.deferReply();
let rand = Math.floor(Math.random() * 99999).toString();
if (!interaction.isChatInputCommand()) return;
const modal = new ModalBuilder()
.setCustomId(rand)
.setTitle('Submit to the AI');
// TODO: Add components to modal...
const promptInput = new TextInputBuilder()
.setCustomId('sendInput')
// The label is the prompt the user sees for this input
.setLabel("Please Provide a Prompt")
// Short means only a single line of text
.setStyle(TextInputStyle.Paragraph);
// An action row only holds one text input,
// so you need one action row per text input.
const firstActionRow = new ActionRowBuilder().addComponents([promptInput]);
// Add inputs to the modal
modal.addComponents([firstActionRow]);
await interaction.showModal(modal);
client.on('interactionCreate', interaction => {
if (interaction.type !== 5){
} else {
if (interaction.customId === rand) {
(async () => {
await interaction.reply("Please wait while I think about this...")
})()
// Get the data entered by the user
const data = interaction.fields.getTextInputValue('sendInput');
function detectCodingLanguages(str) {
const languages = {
'javascript': 'js',
'nodejs': 'js',
'node': 'js',
'python': 'py',
'ruby': 'rb',
'c#': 'csharp',
'c++': 'cpp',
'php': 'php',
'go': 'go',
'bash': 'bash'
};
let detectedLanguages = [];
for (let language in languages) {
if (str.includes(language)) {
detectedLanguages.push(languages[language]);
}
}
return detectedLanguages;
}
console.log(detectCodingLanguages(data)[0])
if (detectCodingLanguages(data)) {
lang = detectCodingLanguages(data)[0]
} else {
lang = "js"
}
unirest
.post('https://codex-ai-v9q6.onrender.com/')
.headers({ 'Accept': 'application/json', 'Content-Type': 'application/json' })
.send({ "prompt": data })
.then((response) => {
if (response.body.bot.length > 1980) {
fs.writeFile('/tmp/paste', response.body.bot, err => {
if (err) {
console.error(err)
return
}
})
cmd("sleep 2; cat /tmp/paste | dpaste").then(pasteout => {
const mainEmbed = new EmbedBuilder()
.setColor('#0099ff')
.addFields(
{ name: 'Please check the below output log:', value: pasteout.stdout.replace("Pro tip: you can password protect your paste just by typing a username and password after your paste command.", "").replace("Paste Saved: ", "").replace("-------------------------------------------------------", "") },
).setTitle("Response too large")
.setDescription("Our AI was too Powerful!")
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
(async () => {
return await interaction.editReply({ embeds: [mainEmbed] })
})();
})
} else {
(async () => {
await interaction.editReply("```" + lang + response.body.bot + "```")
})();
}
})
}
}
});
}
};

View File

@ -1,86 +0,0 @@
const { EmbedBuilder } = require('discord.js');
var unirest = require('unirest');
const cmd = require('cmd-promise')
const fs = require("fs");
let lang
module.exports = {
name: "send",
private: false,
description: "send an inquiry to the AI",
options: [{
"name": "inquiry",
"description": "What you would like to send.",
"required": true,
"type": 3 // 6 is type USER
}],
run: async (client, interaction) => {
let data = interaction.options._hoistedOptions[0].value
function detectCodingLanguages(str) {
const languages = {
'javascript': 'js',
'nodejs': 'js',
'node': 'js',
'python': 'py',
'ruby': 'rb',
'c#': 'csharp',
'c++': 'cpp',
'php': 'php',
'go': 'go',
'bash': 'bash'
};
let detectedLanguages = [];
for (let language in languages) {
if (str.includes(language)) {
detectedLanguages.push(languages[language]);
}
}
return detectedLanguages;
}
console.log(detectCodingLanguages(data)[0])
if (detectCodingLanguages(data)){
lang = detectCodingLanguages(data)[0]
} else {
lang = "js"
}
unirest
.post('https://codex-ai-v9q6.onrender.com/')
.headers({'Accept': 'application/json', 'Content-Type': 'application/json'})
.send({ "prompt": data })
.then((response) => {
if (response.body.bot.length > 1980){
fs.writeFile('/tmp/paste', response.body.bot, err => {
if (err) {
console.error(err)
return
}
})
cmd("sleep 2; cat /tmp/paste | dpaste").then(pasteout => {
const mainEmbed = new EmbedBuilder()
.setColor('#0099ff')
.addFields(
{ name: 'Please check the below output log:', value: pasteout.stdout.replace("Pro tip: you can password protect your paste just by typing a username and password after your paste command.", "").replace("Paste Saved: ", "").replace("-------------------------------------------------------", "") },
).setTitle("Response too large")
.setDescription("Our AI was too Powerful!")
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
(async () => {
return await interaction.editReply({ embeds: [mainEmbed] })
})();
})
} else {
interaction.editReply("```" + lang + response.body.bot + "```")
}
})
},
};

View File

@ -1,93 +1,48 @@
const client = require("../raven_ai");
require("dotenv").config();
const { glob } = require("glob");
const { promisify } = require("util");
const globPromise = promisify(glob);
const fs = require('fs')
const jsonfile = require('jsonfile')
client.on("interactionCreate", async (interaction) => {
// Slash Commands
const slashCommands = await globPromise(`${process.cwd()}/commands/*/*.js`);
const arrayOfSlashCommands = [];
// Map the slash commands into data to be processed
slashCommands.map((value) => {
const file = require(value);
const splitted = value.split("/");
const directory = splitted[splitted.length - 2];
if (!file?.name) return;
const properties = {
directory,
...file
};
client.slashCommands.set(file.name, properties);
if (["MESSAGE", "USER"].includes(file.type)) delete file.description;
// Push the data
arrayOfSlashCommands.push(file);
});
// Slash Command Handling
if (interaction.isChatInputCommand()) {
// Grabbing Command Data for this interaction
let commandData = []
// If we have a modal, lets make sure to skip the deferal.
if (interaction.commandName === 'advanced'){
console.log("Modal detected, skipping...")
} else {
// If not, defer and wait for edits - Max 15 Minutes!
// Send defer depending on what the user has their privacy set to
await interaction.deferReply({ ephemeral: false }).catch(() => { });
}
// Get command info
const cmd = client.slashCommands.get(interaction.commandName);
if (!cmd)
return interaction.followUp({ content: "An error has occurred " });
// Args, Options and Subdommands handling from module.exports.
const args = [];
for (let option of interaction.options.data) {
if (option.type === "SUB_COMMAND") {
if (option.name) args.push(option.name);
option.options?.forEach((x) => {
if (x.value) args.push(x.value);
});
} else if (option.value) args.push(option.value);
}
// Set GUILD member
interaction.member = interaction.guild.members.cache.get(interaction.user.id);
// We use ForEach here to filter our array into the single commands info.
await arrayOfSlashCommands.forEach(command => {
if (command.name == interaction.commandName) {
commandData.push(command)
}
});
// Process and Parse Data
let dataToProcess = JSON.stringify(commandData[0])
let parsedData = JSON.parse(dataToProcess)
// If the command is private, set ephemeral true else, set false
if (parsedData.private == true) {
await interaction.deferReply({
ephemeral: true
}).catch(() => {});
} else {
await interaction.deferReply({
ephemeral: false
}).catch(() => {});
}
const cmd = client.slashCommands.get(interaction.commandName);
if (!cmd)
return interaction.followUp({
content: "An error has occurred "
});
const args = [];
for (let option of interaction.options.data) {
if (option.type === "SUB_COMMAND") {
if (option.name) args.push(option.name);
option.options?.forEach((x) => {
if (x.value) args.push(x.value);
});
} else if (option.value) args.push(option.value);
}
interaction.member = interaction.guild.members.cache.get(interaction.user.id);
cmd.run(client, interaction, args);
// Run Command
cmd.run(client, interaction, args);
}
// Context Menu Handling
if (interaction.isContextMenuCommand()) {
await interaction.deferReply({
ephemeral: false
});
const command = client.slashCommands.get(interaction.commandName);
if (command) command.run(client, interaction);
await interaction.deferReply({ ephemeral: false });
const command = client.slashCommands.get(interaction.commandName);
if (command) command.run(client, interaction);
}
});