mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-09-10 12:02:59 +02:00
Merge pull request #476 from uukelele-scratch/patch
added search wiki command
This commit is contained in:
commit
4ccbbe0f6c
2 changed files with 31 additions and 0 deletions
|
@ -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",
|
||||
|
|
|
@ -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.',
|
||||
|
|
Loading…
Add table
Reference in a new issue