Compare commits
No commits in common. "1a024b216a1889ad0dfd283071f4a5920e2baff5" and "0106983a5f122bd488cf68df270f16fdd2d5d143" have entirely different histories.
1a024b216a
...
0106983a5f
1
.gitignore
vendored
1
.gitignore
vendored
@ -114,4 +114,3 @@ dist
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
.DS_Store
|
||||
|
@ -5,5 +5,4 @@ WORKDIR /usr/src/app
|
||||
COPY package.json ./
|
||||
RUN npm install
|
||||
COPY . .
|
||||
# CMD ["/bin/sh", "-c", "node main.js 2> /logs/nodbot.error 1> /logs/nodbot.log"]
|
||||
CMD ["/bin/sh", "-c", "node main.js 2> /logs/$(date +%Y-%m-%d_%H-%M-%S)-error.txt 1> /logs/$(date +%Y-%m-%d_%H-%M-%S)-status.txt"]
|
||||
CMD ["/bin/sh", "-c", "node main.js 2> /logs/nodbot.error 1> /logs/nodbot.log"]
|
@ -1,5 +1,4 @@
|
||||
{
|
||||
"guildId": "868542949737246730",
|
||||
"validCommands": [],
|
||||
"roaches": []
|
||||
"validCommands": []
|
||||
}
|
@ -5,33 +5,13 @@ module.exports = {
|
||||
name: 'joint',
|
||||
description: 'Send a random weed-themed phrase.',
|
||||
usage: '.joint',
|
||||
alias: ['bong', 'blunt', 'bowl', 'pipe', 'dab', 'vape', 'dabs', 'shatter', 'edible', 'edibles', 'doobie', 'spliff', 'gummy', 'gummies', 'hash', 'toke', 'big doinks'],
|
||||
alias: ['bong', 'blunt', 'bowl', 'pipe'],
|
||||
execute(message, commandData) {
|
||||
let joints = [];
|
||||
// Create a simple array of the joint texts
|
||||
for (const entry of message.client.joints.map(joint => joint.content)) {
|
||||
joints.push(entry);
|
||||
}
|
||||
// Generate a random number between 0 and the length of the joints array
|
||||
let randIndex = Math.floor(Math.random() * joints.length);
|
||||
// Grab the joint text from the array
|
||||
let joint = joints[randIndex];
|
||||
|
||||
// Check if the joint has already been smoked
|
||||
while (message.client.roaches.has(joint)) {
|
||||
// Regenerate a random number and recheck
|
||||
randIndex = Math.floor(Math.random() * joints.length);
|
||||
joint = joints[randIndex];
|
||||
}
|
||||
// Send the joint
|
||||
const randIndex = Math.floor(Math.random() * joints.length);
|
||||
message.reply(`${joints[randIndex]} ${emoji.joint}`);
|
||||
// Check how full the roach collection is
|
||||
if (message.client.roaches.size / joints.length >= 0.85) {
|
||||
// If the roach collection is 85% of the joints collection
|
||||
// Empty it out
|
||||
message.client.roaches.clear();
|
||||
}
|
||||
// Add the joint to the roach collection
|
||||
message.client.roaches.set(joint, "baked");
|
||||
}
|
||||
}
|
@ -8,9 +8,7 @@ module.exports = {
|
||||
const client = message.client;
|
||||
let pastaData;
|
||||
if (!client.pastas.has(commandData.args)) {
|
||||
pastaData = {
|
||||
content: "Sorry, I couldn't find that pasta."
|
||||
};
|
||||
commandData.content = 'Sorry I couldn\'t find that pasta.';
|
||||
} else {
|
||||
pastaData = client.pastas.get(commandData.args);
|
||||
}
|
||||
|
47
functions.js
47
functions.js
@ -22,8 +22,20 @@ const Discord = require('discord.js');
|
||||
const FuzzySearch = require('fuzzy-search');
|
||||
|
||||
// OpenAI
|
||||
const OpenAI = require("openai");
|
||||
const openai = new OpenAI();
|
||||
const { Configuration, OpenAIApi } = require("openai");
|
||||
|
||||
const configuration = new Configuration({
|
||||
apiKey: process.env.OPENAI_API_KEY,
|
||||
});
|
||||
const openai = new OpenAIApi(configuration);
|
||||
async function openAIStatus(o) {
|
||||
const response = await o.listModels();
|
||||
const models = response.data.data;
|
||||
models.forEach(e => {
|
||||
console.log(`Model ID: ${e.id}`);
|
||||
});
|
||||
};
|
||||
openAIStatus(openai);
|
||||
|
||||
// Various imports from other files
|
||||
const config = require('./config.json');
|
||||
@ -149,7 +161,7 @@ const functions = {
|
||||
if (isDev) console.log('Strains Collection Built');
|
||||
},
|
||||
medicalAdvice(rows, client) {
|
||||
if (!client.medicalAdviceColl) client.medicalAdviceColl = new Discord.Collection();
|
||||
if (!client.medicalAdviceCol) client.medicalAdviceColl = new Discord.Collection();
|
||||
client.medicalAdviceColl.clear();
|
||||
for (const row of rows) {
|
||||
const medicalAdvice = {
|
||||
@ -160,11 +172,6 @@ const functions = {
|
||||
}
|
||||
if (isDev) console.log('Medical Advice Collection Built');
|
||||
},
|
||||
roaches(client) {
|
||||
if (!client.roaches) client.roaches = new Discord.Collection();
|
||||
client.roaches.clear();
|
||||
if (isDev) console.log('Medical Advice Collection Built');
|
||||
}
|
||||
},
|
||||
dot: {
|
||||
getCommandData(message) {
|
||||
@ -267,7 +274,7 @@ const functions = {
|
||||
return { embeds: [ new Discord.MessageEmbed()
|
||||
.setAuthor({name: `${commandData.args}.${commandData.command}`})
|
||||
.setDescription(pastaData.content)
|
||||
.setThumbnail("https://assets.vfsh.dev/shednod.png")
|
||||
.setThumbnail(pastaData.iconUrl)
|
||||
.setTimestamp()
|
||||
.setFooter({text: commandData.author})]};
|
||||
},
|
||||
@ -372,9 +379,9 @@ const functions = {
|
||||
},
|
||||
gpt(prompt, response, usage) {
|
||||
const gptEmbed = new Discord.MessageEmbed()
|
||||
.setAuthor({ name: "NodBot powered by GPT-3.5", iconURL: "https://assets.vfsh.dev/openai-logos/PNGs/openai-logomark.png" })
|
||||
.setAuthor({ name: "NodBot powered by GPT-3", iconURL: "https://assets.vfsh.dev/openai-logos/PNGs/openai-logomark.png" })
|
||||
.setDescription(`**Prompt**\n${prompt}\n\n**Response**\n${response}`)
|
||||
.setFooter({ text: `This prompt used ${usage.tokens} tokens for a cost of ${usage.usdc}¢. Generated using ${strings.ai.chatModel}` })
|
||||
.setFooter({ text: `This prompt used ${usage.tokens} tokens for a cost of ${usage.usdc}¢` })
|
||||
return { embeds: [gptEmbed] };
|
||||
},
|
||||
generatingResponse() {
|
||||
@ -400,13 +407,12 @@ const functions = {
|
||||
functions.download.requests(client);
|
||||
});
|
||||
},
|
||||
async pasta(pastaData, client) {
|
||||
pasta(pastaData, client) {
|
||||
const query = `INSERT INTO pastas (name, content) VALUES (${db.escape(pastaData.name)},${db.escape(pastaData.content)}) ON DUPLICATE KEY UPDATE content=${db.escape(pastaData.content)}`;
|
||||
await db.query(query, (err, rows, fields) => {
|
||||
db.query(query, (err, rows, fields) => {
|
||||
if (err) throw err;
|
||||
functions.download.pastas(client);
|
||||
});
|
||||
return;
|
||||
},
|
||||
joint(content, client) {
|
||||
const query = `INSERT INTO joints (content) VALUES (${db.escape(content)})`;
|
||||
@ -564,17 +570,16 @@ const functions = {
|
||||
openAI: {
|
||||
chatPrompt(userPrompt) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const response = await openai.chat.completions.create({
|
||||
messages: [{
|
||||
role: 'user',
|
||||
content: userPrompt
|
||||
}],
|
||||
model: strings.ai.chatModel
|
||||
const response = await openai.createCompletion({
|
||||
model: 'text-davinci-003',
|
||||
prompt: userPrompt,
|
||||
temperature: 0.7,
|
||||
max_tokens: 250
|
||||
}).catch(e => {
|
||||
reject(e);
|
||||
return null;
|
||||
});
|
||||
resolve(response);
|
||||
resolve(response.data);
|
||||
});
|
||||
},
|
||||
imagePrompt(userPrompt, size, userId) {
|
||||
|
4
main.js
4
main.js
@ -34,7 +34,6 @@ client.once('ready', () => {
|
||||
fn.collections.slashCommands(client);
|
||||
fn.collections.dotCommands(client);
|
||||
fn.collections.setvalidCommands(client);
|
||||
fn.collections.roaches(client);
|
||||
fn.download.gifs(client);
|
||||
fn.download.pastas(client);
|
||||
fn.download.joints(client);
|
||||
@ -223,11 +222,8 @@ client.on('messageCreate', message => {
|
||||
|
||||
// Wildcard Responses, will respond if any message contains the trigger word(s), excluding self-messages
|
||||
const lowerContent = message.content.toLowerCase();
|
||||
// big + doinks
|
||||
if (lowerContent.includes('big') && lowerContent.includes('doinks')) message.reply('gang.');
|
||||
// ligma
|
||||
if (lowerContent.includes('ligma')) message.reply('ligma balls, goteem');
|
||||
// frfr, fr fr , bussin, ong
|
||||
if (lowerContent.includes('frfr') || lowerContent.includes('fr fr') || lowerContent.includes('bussin') || lowerContent.includes(' ong') || lowerContent.startsWith('ong')) {
|
||||
const randIndex = Math.floor(Math.random() * strings.capbacks.length);
|
||||
message.reply(strings.capbacks[randIndex]);
|
||||
|
@ -12,7 +12,7 @@
|
||||
"dotenv": "^10.0.0",
|
||||
"fuzzy-search": "^3.2.1",
|
||||
"mysql": "^2.18.1",
|
||||
"openai": "^4.12.0",
|
||||
"openai": "^3.2.1",
|
||||
"tenorjs": "^1.0.10"
|
||||
},
|
||||
"engines": {
|
||||
|
27
slash-commands/chat.js
Normal file
27
slash-commands/chat.js
Normal file
@ -0,0 +1,27 @@
|
||||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
const fn = require('../functions.js');
|
||||
|
||||
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].text;
|
||||
const usage = {
|
||||
tokens: response.usage.total_tokens,
|
||||
usdc: response.usage.total_tokens * ( 0.2 / 1000 ) // 0.2¢ per 1000 tokens or 0.0002¢ per token.
|
||||
};
|
||||
const gptEmbed = fn.embeds.gpt(userPrompt, responseText, usage);
|
||||
await interaction.editReply(gptEmbed);
|
||||
fn.upload.openai(interaction.user.id, userPrompt, "gpt-3.5-turbo", usage.tokens, usage.usdc);
|
||||
},
|
||||
};
|
40
slash-commands/dalle.js
Normal file
40
slash-commands/dalle.js
Normal file
@ -0,0 +1,40 @@
|
||||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
const fn = require('../functions.js');
|
||||
const strings = require("../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}`);
|
||||
}
|
||||
},
|
||||
};
|
@ -207,7 +207,7 @@ module.exports = {
|
||||
name: interaction.options.getString('pasta-name').toLowerCase(),
|
||||
content: interaction.options.getString('pasta-content'),
|
||||
};
|
||||
await fn.upload.pasta(pastaData, interaction.client);
|
||||
fn.upload.pasta(pastaData, interaction.client);
|
||||
interaction.editReply({content: `The copypasta has been saved as ${pastaData.name}.pasta`, ephemeral: true });
|
||||
break;
|
||||
// Strain
|
||||
|
@ -32,12 +32,5 @@
|
||||
"1024x1024": 2.0
|
||||
}
|
||||
},
|
||||
"ai": {
|
||||
"chatModel": "gpt-3.5-turbo",
|
||||
"chatPromptCentsPer": 0.15,
|
||||
"chatPromptUnits": 1000,
|
||||
"chatResCentsPer": 0.2,
|
||||
"chatResUnits": 1000
|
||||
},
|
||||
"temp": {}
|
||||
}
|
Loading…
Reference in New Issue
Block a user