全部 / 技术交流 / 软件交流 · 2023年1月18日 0

快捷指令:每日自动更换随机游戏壁纸

本文最后更新于 463 天前,其中的信息可能已经有所发展或改变。
阿尔宙斯

自己写的一个每日随机游戏壁纸快捷指令~

推荐配合自动化,每日8点自动更换壁纸(无感)。遇到喜欢的壁纸可以前往照片-最近删除查看

Shortcuts
www.icloud.com
指令

这个创意其实是从前段时间写的随机壁纸插件修改而来:

"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;
JavaScript