forked from Walkersifolia/mc-wiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mcwiki.js
42 lines (40 loc) · 1.63 KB
/
mcwiki.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import plugin from '../../lib/plugins/plugin.js';
import puppeteer from '../../lib/puppeteer/puppeteer.js';
import { segment } from 'icqq';
import common from "../../lib/common/common.js";
export class QueryHandler extends plugin {
constructor(query) {
let rule = {
reg: /^#mcwiki(.*)/,
fnc: 'handleWikiQuery',
}
super({
name: 'mcwiki',
dsc: 'mcwiki',
event: 'message',
priority: 5000,
rule: [rule],
})
}
async handleWikiQuery(query) {
let querywithoutwiki = (query + "").replace('#mcwiki', '')
let encodeQuery = encodeURI(querywithoutwiki)
let url = `https://zh.minecraft.wiki/w/${encodeQuery}`
//await this.reply(url)
const browser = await puppeteer.browserInit()
const page = await browser.newPage()
await page.goto(url)
const height = await page.evaluate(() => document.documentElement.scrollHeight)
if (height === 894) {
return this.reply('搜索不到此结果,请检查关键词是否准确无误')
} else
await page.setViewport({ width: 1280, height })
const buff = await page.screenshot()
await page.close()
//await this.reply(segment.image(buff))
let message = [url]
message.push(segment.image(buff))
message.push('受服务器网络波动影响,如果无法加载出正确的图片,还请您重新发送或点开上面的链接进入网页查看')
return this.reply(await common.makeForwardMsg(this.e, message))
}
}