From a59e8f99aae2995cd04339f8873dd82b92f58fe9 Mon Sep 17 00:00:00 2001 From: Flummi Date: Tue, 18 Jul 2023 02:02:43 +0200 Subject: [PATCH] .konfuzius --- src/inc/trigger/useless_huan.mjs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/inc/trigger/useless_huan.mjs b/src/inc/trigger/useless_huan.mjs index 48ae603..f246bdd 100644 --- a/src/inc/trigger/useless_huan.mjs +++ b/src/inc/trigger/useless_huan.mjs @@ -2,7 +2,8 @@ import fetch from "flumm-fetch-cookies"; const apis = { launch: 'https://fdo.rocketlaunch.live/json/launches/next/1', - fml: 'https://www.fmylife.com/random' + fml: 'https://www.fmylife.com/random', + konfuzius: 'https://de.wikiquote.org/w/api.php?action=parse&format=json&pageid=155§ion=2', }; @@ -48,5 +49,24 @@ export default async bot => { } return e.reply(res.match(/\n(.*?)\n<\/a>/im)[1]); } + }, { + name: "konfuzius", + call: /^\.konfuzius/i, + set: "huan", + f: async e => { + let res; + try { + res = (await (await fetch(apis.konfuzius)).json()).parse.text['*']; + } catch(err) { + console.error(err); + } + + const quotes = res + .replace(/(.+?)<\/a>/g, '$1') + .match(/
  • \"(.*?)\" - .*?<\/ul>/gm) + .map(a => a.match(/\"(.*)\"/)[1]); + + return e.reply(`[b]Konfuzius sagt:[/b] ${quotes[~~(Math.random() * quotes.length)]}`); + } }]; };