Merge pull request #476 from uukelele-scratch/patch

added search wiki command
This commit is contained in:
Max Robinson 2025-03-13 16:01:10 -05:00 committed by GitHub
commit 4ccbbe0f6c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 0 deletions

View file

@ -6,6 +6,7 @@
"@huggingface/inference": "^2.8.1",
"@mistralai/mistralai": "^1.1.0",
"canvas": "^3.1.0",
"cheerio": "^1.0.0",
"express": "^4.18.2",
"google-translate-api-x": "^10.7.1",
"groq-sdk": "^0.15.0",

View file

@ -2,6 +2,7 @@ import * as world from '../library/world.js';
import * as mc from '../../utils/mcdata.js';
import { getCommandDocs } from './index.js';
import convoManager from '../conversation.js';
import { load } from 'cheerio';
const pad = (str) => {
return '\n' + str + '\n';
@ -214,6 +215,35 @@ export const queryList = [
return pad(craftingPlan);
},
},
{
name: '!searchWiki',
description: 'Search the Minecraft Wiki for the given query.',
params: {
'query': { type: 'string', description: 'The query to search for.' }
},
perform: async function (agent, query) {
const url = `https://minecraft.wiki/w/${query}`
try {
const response = await fetch(url);
if (response.status === 404) {
return `${query} was not found on the Minecraft Wiki. Try adjusting your search term.`;
}
const html = await response.text();
const $ = load(html);
const parserOutput = $("div.mw-parser-output");
parserOutput.find("table.navbox").remove();
const divContent = parserOutput.text();
return divContent.trim();
} catch (error) {
console.error("Error fetching or parsing HTML:", error);
return `The following error occured: ${error}`
}
}
},
{
name: '!help',
description: 'Lists all available commands and their descriptions.',