Compare commits
No commits in common. "973952aee1d216a3e42200377cdb4fb8ccef1573" and "f87542132ea4e4a304d089afadff5d781a44a2e9" have entirely different histories.
973952aee1
...
f87542132e
23
llamabot.js
23
llamabot.js
@ -5,6 +5,8 @@ import { resetResponses, userResetMessages } from './assets/resetMessages.js';
|
|||||||
import { errorMessages, busyResponses } from './assets/errorMessages.js';
|
import { errorMessages, busyResponses } from './assets/errorMessages.js';
|
||||||
import cpuStat from 'cpu-stat';
|
import cpuStat from 'cpu-stat';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
|
import isNotDefined from 'is-not-defined'
|
||||||
|
import urban from 'urban'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Client,
|
Client,
|
||||||
@ -139,6 +141,23 @@ client.on('messageCreate', async (message) => {
|
|||||||
setPresenceBusy()
|
setPresenceBusy()
|
||||||
setBusy(message.author.id, true);
|
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);
|
const response = await generateResponse(conversation, message);
|
||||||
|
|
||||||
// Append bot message to conversation history
|
// Append bot message to conversation history
|
||||||
@ -190,6 +209,7 @@ import cheerio from 'cheerio';
|
|||||||
|
|
||||||
async function generateResponse(conversation, message) {
|
async function generateResponse(conversation, message) {
|
||||||
|
|
||||||
|
|
||||||
// Check if message contains a URL
|
// Check if message contains a URL
|
||||||
const urlRegex = /(https?:\/\/[^\s]+)/g;
|
const urlRegex = /(https?:\/\/[^\s]+)/g;
|
||||||
const urls = message.content.match(urlRegex);
|
const urls = message.content.match(urlRegex);
|
||||||
@ -244,6 +264,9 @@ async function generateResponse(conversation, message) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
const timeout = setTimeout(() => {
|
const timeout = setTimeout(() => {
|
||||||
controller.abort();
|
controller.abort();
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.0.3",
|
||||||
"node-fetch": "^3.3.1",
|
"node-fetch": "^3.3.1",
|
||||||
"os": "^0.1.2",
|
"os": "^0.1.2",
|
||||||
"cpu-stat": "^2.0.1"
|
"cpu-stat": "^2.0.1",
|
||||||
|
"is-not-defined": "^1.0.1",
|
||||||
|
"urban": "^0.3.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user