UNPKG

koishi-plugin-gamewallpaper-byripple

Version:

【白嫖随机游戏壁纸、根据壁纸猜游戏名】

73 lines (63 loc) 2.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.apply = exports.Config = exports.name = void 0; const koishi_1 = require("koishi"); exports.name = 'gamewallpaper'; const axios = require('axios'); const similarity = require('string-similarity'); exports.Config = koishi_1.Schema.intersect([ koishi_1.Schema.object({ max: koishi_1.Schema.number().description('壁纸池上限,范围0~1296').default(1296), gameinfo: koishi_1.Schema.boolean().description('展开与Gameinfo插件联动?').default(false), guess:koishi_1.Schema.boolean().description('猜游戏功能?打开此项需要将max调为790').default(false), similarity: koishi_1.Schema.number().description('判断用户输入信息与游戏名的相似阈值,越高则越严格,范围0~1').default(0.3), }).description('基础设置'), ]) const axiosRetry = require('axios-retry'); // Enable axios-retry axiosRetry(axios, { retries: 3 }); function apply(ctx, config) { ctx.command("壁纸","获取游戏壁纸!") .action(async ({ session },text) => { try { const imageurl = `http://app02.vgtime.com:8080/vgtime-app/api/v3/launch/wallpaper_list?page=1&page_size=${config.max}`; const randomnumber = Math.floor(Math.random() * Math.floor(config.max)); const reponse = await axios.get(imageurl) const pictureUrl1 = decodeURIComponent(reponse.data.data[randomnumber].picture); const imageData1 = await ctx.http.get(pictureUrl1, { responseType: 'arraybuffer' }); const name = reponse.data.data[randomnumber].game.title if(config.guess){ session.send(koishi_1.segment.image(imageData1)+"请回答游戏名。"); }else{ session.send(koishi_1.segment.image(imageData1)) } let counter = 0; if (config.guess) { while (counter < 3) { const text = await session.prompt("请回答图片中游戏的名称:"); const score = similarity.compareTwoStrings(name, text); if (score > config.similarity) { if(config.gameinfo){ session.send ( `回答正确!游戏名为《${name}》,如需更多信息请发送指令“查询 ${name}` ) }else{ session.send ( `回答正确!游戏名为《${name}》` ) } break; } else { counter++; if (counter < 3) { session.send(`回答错误。请再次回答,你还有${3 - counter}次机会。`); } else { session.send(`回答错误。游戏名为《${name}》。`); return session.execute(`查询 ${name}`); } } } } } catch (error) { ctx.logger('tools').warn(error); return '请求失败。'; } }); } exports.apply = apply;