From f995d9a6432bef913cb408d7fb6ed8b1837141df Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Wed, 18 Oct 2023 17:33:03 -0400 Subject: [PATCH 1/9] Upgrade to gpt-3.5-turbo --- functions.js | 33 +++++++++++---------------------- package.json | 2 +- slash-commands/chat.js | 8 +++++--- strings.json | 7 +++++++ 4 files changed, 24 insertions(+), 26 deletions(-) diff --git a/functions.js b/functions.js index 6b53169..7cce43d 100644 --- a/functions.js +++ b/functions.js @@ -22,20 +22,8 @@ const Discord = require('discord.js'); const FuzzySearch = require('fuzzy-search'); // 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); +const OpenAI = require("openai"); +const openai = new OpenAI(); // Various imports from other files const config = require('./config.json'); @@ -379,9 +367,9 @@ const functions = { }, gpt(prompt, response, usage) { const gptEmbed = new Discord.MessageEmbed() - .setAuthor({ name: "NodBot powered by GPT-3", iconURL: "https://assets.vfsh.dev/openai-logos/PNGs/openai-logomark.png" }) + .setAuthor({ name: "NodBot powered by GPT-3.5", 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}¢` }) + .setFooter({ text: `This prompt used ${usage.tokens} tokens for a cost of ${usage.usdc}¢. Generated using ${strings.ai.chatModel}` }) return { embeds: [gptEmbed] }; }, generatingResponse() { @@ -570,16 +558,17 @@ const functions = { openAI: { chatPrompt(userPrompt) { return new Promise(async (resolve, reject) => { - const response = await openai.createCompletion({ - model: 'text-davinci-003', - prompt: userPrompt, - temperature: 0.7, - max_tokens: 250 + const response = await openai.chat.completions.create({ + messages: [{ + role: 'user', + content: userPrompt + }], + model: strings.ai.chatModel }).catch(e => { reject(e); return null; }); - resolve(response.data); + resolve(response); }); }, imagePrompt(userPrompt, size, userId) { diff --git a/package.json b/package.json index 55b30c9..3ec6382 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "dotenv": "^10.0.0", "fuzzy-search": "^3.2.1", "mysql": "^2.18.1", - "openai": "^3.2.1", + "openai": "^4.12.0", "tenorjs": "^1.0.10" }, "engines": { diff --git a/slash-commands/chat.js b/slash-commands/chat.js index efeaad7..2c9ba34 100644 --- a/slash-commands/chat.js +++ b/slash-commands/chat.js @@ -1,5 +1,6 @@ const { SlashCommandBuilder } = require('@discordjs/builders'); const fn = require('../functions.js'); +const strings = require('../strings.json'); module.exports = { data: new SlashCommandBuilder() @@ -15,13 +16,14 @@ module.exports = { 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 responseText = response.choices[0].message.content; 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. + 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, "gpt-3.5-turbo", usage.tokens, usage.usdc); + fn.upload.openai(interaction.user.id, userPrompt, strings.ai.chatModel, usage.tokens, usage.usdc); }, }; \ No newline at end of file diff --git a/strings.json b/strings.json index b82b6db..94ee7cf 100644 --- a/strings.json +++ b/strings.json @@ -32,5 +32,12 @@ "1024x1024": 2.0 } }, + "ai": { + "chatModel": "gpt-3.5-turbo", + "chatPromptCentsPer": 0.15, + "chatPromptUnits": 1000, + "chatResCentsPer": 0.2, + "chatResUnits": 1000 + }, "temp": {} } \ No newline at end of file -- 2.45.2 From 82f65a800ca5da4c9da9a731d523595535520a47 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Wed, 13 Dec 2023 16:49:48 -0500 Subject: [PATCH 2/9] bugfixes --- dot-commands/pasta.js | 4 +++- functions.js | 7 ++++--- slash-commands/save.js | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/dot-commands/pasta.js b/dot-commands/pasta.js index 357f8ac..da202ef 100644 --- a/dot-commands/pasta.js +++ b/dot-commands/pasta.js @@ -8,7 +8,9 @@ module.exports = { const client = message.client; let pastaData; if (!client.pastas.has(commandData.args)) { - commandData.content = 'Sorry I couldn\'t find that pasta.'; + pastaData = { + content: "Sorry, I couldn't find that pasta." + }; } else { pastaData = client.pastas.get(commandData.args); } diff --git a/functions.js b/functions.js index 7cce43d..101b86e 100644 --- a/functions.js +++ b/functions.js @@ -262,7 +262,7 @@ const functions = { return { embeds: [ new Discord.MessageEmbed() .setAuthor({name: `${commandData.args}.${commandData.command}`}) .setDescription(pastaData.content) - .setThumbnail(pastaData.iconUrl) + .setThumbnail("https://assets.vfsh.dev/shednod.png") .setTimestamp() .setFooter({text: commandData.author})]}; }, @@ -395,12 +395,13 @@ const functions = { functions.download.requests(client); }); }, - pasta(pastaData, client) { + async 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)}`; - db.query(query, (err, rows, fields) => { + await 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)})`; diff --git a/slash-commands/save.js b/slash-commands/save.js index 6390e8b..b47b05d 100644 --- a/slash-commands/save.js +++ b/slash-commands/save.js @@ -207,7 +207,7 @@ module.exports = { name: interaction.options.getString('pasta-name').toLowerCase(), content: interaction.options.getString('pasta-content'), }; - fn.upload.pasta(pastaData, interaction.client); + await fn.upload.pasta(pastaData, interaction.client); interaction.editReply({content: `The copypasta has been saved as ${pastaData.name}.pasta`, ephemeral: true }); break; // Strain -- 2.45.2 From 97b4136b6465d7e45f42896c27a50a7b9377ade3 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Thu, 14 Dec 2023 10:43:40 -0500 Subject: [PATCH 3/9] Fix joint randomization and add more aliases --- config.json | 3 ++- dot-commands/joint.js | 20 ++++++++++++++++++-- functions.js | 7 ++++++- main.js | 4 ++++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/config.json b/config.json index b9087cf..467e255 100644 --- a/config.json +++ b/config.json @@ -1,4 +1,5 @@ { "guildId": "868542949737246730", - "validCommands": [] + "validCommands": [], + "roaches": [] } \ No newline at end of file diff --git a/dot-commands/joint.js b/dot-commands/joint.js index 2ce3202..939a5e1 100644 --- a/dot-commands/joint.js +++ b/dot-commands/joint.js @@ -5,13 +5,29 @@ module.exports = { name: 'joint', description: 'Send a random weed-themed phrase.', usage: '.joint', - alias: ['bong', 'blunt', 'bowl', 'pipe'], + alias: ['bong', 'blunt', 'bowl', 'pipe', 'dab', 'vape', 'dabs', 'shatter', 'edible', 'edibles', 'doobie', 'spliff', 'gummy', 'gummies', 'hash', 'toke', 'big doinks'], execute(message, commandData) { let joints = []; for (const entry of message.client.joints.map(joint => joint.content)) { joints.push(entry); } - const randIndex = Math.floor(Math.random() * joints.length); + let randIndex = Math.floor(Math.random() * joints.length); + let joint = joints[randIndex]; + + // Check if the joint has already been smoked + while (message.client.roaches.has(joint)) { + randIndex = Math.floor(Math.random() * joints.length); + joint = joints[randIndex]; + } + // Send the joint 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"); } } \ No newline at end of file diff --git a/functions.js b/functions.js index 101b86e..870c942 100644 --- a/functions.js +++ b/functions.js @@ -149,7 +149,7 @@ const functions = { if (isDev) console.log('Strains Collection Built'); }, medicalAdvice(rows, client) { - if (!client.medicalAdviceCol) client.medicalAdviceColl = new Discord.Collection(); + if (!client.medicalAdviceColl) client.medicalAdviceColl = new Discord.Collection(); client.medicalAdviceColl.clear(); for (const row of rows) { const medicalAdvice = { @@ -160,6 +160,11 @@ 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) { diff --git a/main.js b/main.js index ed084ef..584a89c 100644 --- a/main.js +++ b/main.js @@ -34,6 +34,7 @@ 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); @@ -222,8 +223,11 @@ 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]); -- 2.45.2 From 15d39e33816462ceb7e9b183a661b69b355afc1a Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Thu, 14 Dec 2023 10:54:05 -0500 Subject: [PATCH 4/9] commmenting --- dot-commands/joint.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dot-commands/joint.js b/dot-commands/joint.js index 939a5e1..9abc9d1 100644 --- a/dot-commands/joint.js +++ b/dot-commands/joint.js @@ -8,14 +8,18 @@ module.exports = { alias: ['bong', 'blunt', 'bowl', 'pipe', 'dab', 'vape', 'dabs', 'shatter', 'edible', 'edibles', 'doobie', 'spliff', 'gummy', 'gummies', 'hash', 'toke', 'big doinks'], 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]; } -- 2.45.2 From d61ffbaaf750d98922a220a751c99a32cb02e694 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Mon, 1 Jan 2024 15:42:17 -0500 Subject: [PATCH 5/9] Remove chat and dalle commands --- slash-commands/chat.js | 29 ----------------------------- slash-commands/dalle.js | 40 ---------------------------------------- 2 files changed, 69 deletions(-) delete mode 100644 slash-commands/chat.js delete mode 100644 slash-commands/dalle.js diff --git a/slash-commands/chat.js b/slash-commands/chat.js deleted file mode 100644 index 2c9ba34..0000000 --- a/slash-commands/chat.js +++ /dev/null @@ -1,29 +0,0 @@ -const { SlashCommandBuilder } = require('@discordjs/builders'); -const fn = require('../functions.js'); -const strings = require('../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); - }, -}; \ No newline at end of file diff --git a/slash-commands/dalle.js b/slash-commands/dalle.js deleted file mode 100644 index 029b066..0000000 --- a/slash-commands/dalle.js +++ /dev/null @@ -1,40 +0,0 @@ -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}`); - } - }, -}; \ No newline at end of file -- 2.45.2 From 545756b76217ef83ab30c4dc2ab8bfcf5ff5a7b3 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Mon, 1 Jan 2024 15:44:55 -0500 Subject: [PATCH 6/9] Fix log overwriting error --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e7e0027..51b2ca5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,4 +5,5 @@ 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"] \ No newline at end of file +# CMD ["/bin/sh", "-c", "node main.js 2> /logs/nodbot.error 1> /logs/nodbot.log"] +CMD ["/bin/sh", "-c", "node src/main.js 2> /logs/$(date +%Y-%m-%d_%H-%M-%S)-error.txt 1> /logs/$(date +%Y-%m-%d_%H-%M-%S)-status.txt"] \ No newline at end of file -- 2.45.2 From 3f5cc0a9ffa69eae1faf7ad3bc90f792e79d4171 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Mon, 1 Jan 2024 15:47:14 -0500 Subject: [PATCH 7/9] Fix exec dir --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 51b2ca5..b10bc75 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,4 +6,4 @@ 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 src/main.js 2> /logs/$(date +%Y-%m-%d_%H-%M-%S)-error.txt 1> /logs/$(date +%Y-%m-%d_%H-%M-%S)-status.txt"] \ No newline at end of file +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"] \ No newline at end of file -- 2.45.2 From 2ea94092db5b42cdbdfe0631586f93c444be68e0 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Fri, 14 Jun 2024 14:43:06 -0400 Subject: [PATCH 8/9] Ignore Mac BS --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 138619b..fcfa662 100644 --- a/.gitignore +++ b/.gitignore @@ -114,3 +114,4 @@ dist # TernJS port file .tern-port +.DS_Store -- 2.45.2 From ae9ce308b2a4ac7b750e42dbd8a328ceed661040 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Fri, 14 Jun 2024 14:43:23 -0400 Subject: [PATCH 9/9] Ignore Mac BS --- .DS_Store | Bin 6148 -> 6148 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/.DS_Store b/.DS_Store index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..f388235cbc75a06861b27741a6e6016b0f7ddc09 100644 GIT binary patch literal 6148 zcmeHKO;5r=5S`VkfFI#tqR0LLO-MYO3gzg*5bp{YG-)jfka+CLpCNz37!M}iyy(%t zW8$0Lg?6bFE~q3s$?jWbXLes-+8vgNM0L=v5S59jfX3*Q(EVUM&n;ss+OrE3yhhNe zG+I&E%|u#B>}314CO`BncYzMYu!?cDk9 zb?R(bM<&t6XkWUf0X2=?Y3(T+k>+rA_fXRuCe{g~gvs^6w)dB zHhu?mMLm;Sk@@FDr+FUVk9p>1B%J5VF!}TOOPh+f59v$f96#(eKEe&H?i-0aWfS$%!Av`dlQh_Q} z=qrX$>F~Qc&eIqxROuw-&R9q9Ec6XU$lc+0WjHP8$*j2B-YT$21y7A>G%Id zQm|`V1*`&ptblO*hF=8*j1|HI PvwsAn47Rfh{Hg-qJd?!^ delta 65 zcmZoMXfc=|#>AjHF;Q%yo+1YW5HK<@2y7PQ5M$X`FpGIJI|n}pP#!4ooq009h$187 SWK$94$^JYXn`1;)FarR`U=BS1 -- 2.45.2