From f87542132ea4e4a304d089afadff5d781a44a2e9 Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Sat, 6 May 2023 02:32:10 +0200 Subject: [PATCH] Adding urban dictionary lookups --- llamabot.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/llamabot.js b/llamabot.js index dee5824..d3039a9 100644 --- a/llamabot.js +++ b/llamabot.js @@ -5,6 +5,8 @@ import { resetResponses, userResetMessages } from './assets/resetMessages.js'; import { errorMessages, busyResponses } from './assets/errorMessages.js'; import cpuStat from 'cpu-stat'; import os from 'os'; +import isNotDefined from 'is-not-defined' +import urban from 'urban' import { Client, @@ -139,6 +141,23 @@ client.on('messageCreate', async (message) => { setPresenceBusy() setBusy(message.author.id, true); + + // begin commands area + if (message.content.includes("!urban")) { + const regex = /"([^"]+)"/g; + const searchTerm = message.content.match(regex); + const search = urban(searchTerm) + search.first(function (data) { + if (!isNotDefined(data)) { + const lastMessageIndex = conversation.messages.length - 1; + conversation.messages[lastMessageIndex].content = `The definition of ${searchTerm} is: ${data.definition} comment on this exact definition in detail.`; + console.log(`Fetching urban for AI for ${searchTerm}`) + } + }); + } + + // end commands area + const response = await generateResponse(conversation, message); // Append bot message to conversation history @@ -190,6 +209,7 @@ import cheerio from 'cheerio'; async function generateResponse(conversation, message) { + // Check if message contains a URL const urlRegex = /(https?:\/\/[^\s]+)/g; const urls = message.content.match(urlRegex); @@ -235,7 +255,7 @@ async function generateResponse(conversation, message) { // Append a new line and the new content to the existing content of the last message conversation.messages[lastMessageIndex].content += "\n" + response; - + console.log("A URL was provided, response: " + response) } catch (err) { @@ -244,6 +264,9 @@ async function generateResponse(conversation, message) { } } } + + + const controller = new AbortController(); const timeout = setTimeout(() => { controller.abort();