From 38b512a273391d6f21a538c0a2b8a5ae983b3285 Mon Sep 17 00:00:00 2001 From: Kreee Date: Thu, 8 Feb 2024 19:49:07 +0800 Subject: [PATCH] Chore: delete osu-query-online function --- README.md | 2 +- botconfig.example.ts | 2 +- package-lock.json | 4 +- package.json | 2 +- src/app.ts | 4 +- src/handler.ts | 187 ++++++++++++++++++++++--------------------- src/mp.ts | 12 +-- 7 files changed, 107 insertions(+), 106 deletions(-) diff --git a/README.md b/README.md index b5372fd..b17e86a 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ const config :botconf = { cqhttpUrl: "ws://localhost:1234", cqhttpToken: "this_is_a_very_long_token_for_cqhttp", adminQQ: [123456789, 987654321], - description: "实用化,固定的命令与简单的触发关键字符。", + description: "无维护/继续开发计划,等待重构。", gokapiUrl: "https://gokapi.example.site/api/", gokapiToken: "this_is_a_very_long_token_for_gokapi", osuIrcUsername: "Kreee", diff --git a/botconfig.example.ts b/botconfig.example.ts index 666c9f4..8b37df1 100644 --- a/botconfig.example.ts +++ b/botconfig.example.ts @@ -4,7 +4,7 @@ const config :botconf = { cqhttpUrl: "ws://localhost:1234", cqhttpToken: "this_is_a_very_long_token_for_cqhttp", adminQQ: [123456789, 987654321], - description: "实用化,固定的命令与简单的触发关键字符。", + description: "无维护/继续开发计划,等待重构。", gokapiUrl: "https://gokapi.example.site/api/", gokapiToken: "this_is_a_very_long_token_for_gokapi", osuIrcUsername: "Kreee", diff --git a/package-lock.json b/package-lock.json index 19d10dd..32b4263 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "kbot-qq", - "version": "2.9.3", + "version": "2.10.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "kbot-qq", - "version": "2.9.3", + "version": "2.10.0", "license": "MIT", "dependencies": { "axios": "^1.6.0", diff --git a/package.json b/package.json index 88d73ec..b1a5d89 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kbot-qq", - "version": "2.9.3", + "version": "2.10.0", "description": "A Kreee's QQ bot written with TypeScript.", "type": "module", "exports": "./src/app.js", diff --git a/src/app.ts b/src/app.ts index a9cbdee..fb5101e 100644 --- a/src/app.ts +++ b/src/app.ts @@ -6,7 +6,7 @@ import { WebSocket } from "ws" import { msgHandler } from "./handler.js" import { adminHandler } from "./admin.js" import { mpHandler } from "./mp.js" -import { startIRC } from "./online.js" +// import { startIRC } from "./online.js" import { log } from "./logger.js" import { pluginsLoad, pluginsUnload, pluginReceiveMsg } from "./plugin.js" @@ -50,7 +50,7 @@ process.once('SIGUSR2', () => {process.stdin.resume(); handleExit(process.exitCo */ function handleStart() :void { // 启动 online.ts 中的 slate-irc 初始化 - startIRC() + // startIRC() // 载入所有的插件 pluginsLoad() } diff --git a/src/handler.ts b/src/handler.ts index 92bc1f9..7762069 100644 --- a/src/handler.ts +++ b/src/handler.ts @@ -3,7 +3,7 @@ import config from "../botconfig.js" import { log } from "./logger.js" import db from "./db.js" import info from '../package.json' assert { type: "json" } -import { getOSUStats, updateOSUStats } from "./online.js" +// import { getOSUStats, updateOSUStats } from "./online.js" import { getOsuToken, uploadToGokapi } from "./utils.js" import { renderDefault, renderTweets, renderScore } from "./render/_middleware.js" import { randomBytes } from "crypto" @@ -39,10 +39,10 @@ export function msgHandler(msg :Array, qqid :number) :Promise /help 输出该帮助信息 /ping 康康机器人有没有在摸鱼 /关于 关于这个机器人的一切 - /在线 返回 osu! 查询列表里在线玩家 - /在线 列表 返回 osu! 在线查询列表里的所有人 - /在线 添加 添加一项至 osu! 在线查询列表 - /在线 更新 立即请求一次 osu! 在线列表的更新 + + + + /吃什么 不知道今天中午/晚上吃什么?问我! /星期四 星期四?想什么呢! /抽一张 [tag(可选)] 抽一张 Pixiv 图(docs.anosu.top) @@ -84,97 +84,98 @@ export function msgHandler(msg :Array, qqid :number) :Promise` - } - reply = reply + `(共 ${osuname.length} 项)` - renderDefault(reply) - .then((url) => { - resolve([`[CQ:image,file=${url}]`,`图片消息发送失败了>﹏<,请前往 ${url} 查看!(链接有效期 1 天)`]) - }) - .catch((error) => { - log.error(`renderDefault: ${error.toString()}`) - resolve("发生致命错误,已上报给管理员。") - }) - break + resolve(`该功能已停用。\n(如需使用该功能请使用版本 < 2.10.0 的 kbot-qq)`) + // switch (msg[1]) { + // case "列表": + // reply = "查询列表(排名不分先后)
" + // const osuname = await db.read("osu") + // for (const name of osuname) { + // reply = reply + `${name}
` + // } + // reply = reply + `(共 ${osuname.length} 项)` + // renderDefault(reply) + // .then((url) => { + // resolve([`[CQ:image,file=${url}]`,`图片消息发送失败了>﹏<,请前往 ${url} 查看!(链接有效期 1 天)`]) + // }) + // .catch((error) => { + // log.error(`renderDefault: ${error.toString()}`) + // resolve("发生致命错误,已上报给管理员。") + // }) + // break - case "更新": - // 运行 online.ts 中的 updateOSUStats() 以更新在线列表 - updateOSUStats() - .then((replytext) => { - resolve(replytext) - }) - .catch((replytext) => { - resolve(replytext.toString()) - }) - break + // case "更新": + // // 运行 online.ts 中的 updateOSUStats() 以更新在线列表 + // updateOSUStats() + // .then((replytext) => { + // resolve(replytext) + // }) + // .catch((replytext) => { + // resolve(replytext.toString()) + // }) + // break - case "添加": - let user :string = msg.slice(2).join(" ") - // 检查名字是否格式正确 - if (!user || !user.match(/^[A-Za-z0-9 \[\]_-]+$/)) { - resolve('请输入有效的用户名!') - return - } - // 在线查询用户名是否存在 - const token :string | void = await getOsuToken.get() - if (!token) { resolve("发生非致命错误,已上报给管理员。") } - axios.get(`https://osu.ppy.sh/api/v2/users/${user}`, { - headers: { - 'Authorization': `Bearer ${token}` - } - }) - .then(async (res) => { - const username :string = res.data.username - const currList = await db.read("osu") - if (username && !currList.includes(username)) { - await db.push("osu", username) - resolve(`成功添加玩家:${username}`) - } else if (currList.includes(username)) { - resolve(`查询列表中已经存在玩家:${username}`) - } else { - log.error(`add-queryer: when get user: empty username`) - resolve("发生非致命错误,已上报给管理员。") - } - }) - .catch((error) => { - if (error.response && error.response.status === 404) { - renderDefault(`未找到该玩家:${user}`) - .then((url) => { - resolve([`[CQ:image,file=${url}]`,`图片消息发送失败了>﹏<,请前往 ${url} 查看!(链接有效期 1 天)`]) - }) - .catch((error) => { - log.error(`renderDefault: ${error.toString()}`) - resolve("发生致命错误,已上报给管理员。") - }) - } else { - log.error(`add-queryer: when get user-id: ${error.toString()}`) - resolve("发生非致命错误,已上报给管理员。") - } - }) - break + // case "添加": + // let user :string = msg.slice(2).join(" ") + // // 检查名字是否格式正确 + // if (!user || !user.match(/^[A-Za-z0-9 \[\]_-]+$/)) { + // resolve('请输入有效的用户名!') + // return + // } + // // 在线查询用户名是否存在 + // const token :string | void = await getOsuToken.get() + // if (!token) { resolve("发生非致命错误,已上报给管理员。") } + // axios.get(`https://osu.ppy.sh/api/v2/users/${user}`, { + // headers: { + // 'Authorization': `Bearer ${token}` + // } + // }) + // .then(async (res) => { + // const username :string = res.data.username + // const currList = await db.read("osu") + // if (username && !currList.includes(username)) { + // await db.push("osu", username) + // resolve(`成功添加玩家:${username}`) + // } else if (currList.includes(username)) { + // resolve(`查询列表中已经存在玩家:${username}`) + // } else { + // log.error(`add-queryer: when get user: empty username`) + // resolve("发生非致命错误,已上报给管理员。") + // } + // }) + // .catch((error) => { + // if (error.response && error.response.status === 404) { + // renderDefault(`未找到该玩家:${user}`) + // .then((url) => { + // resolve([`[CQ:image,file=${url}]`,`图片消息发送失败了>﹏<,请前往 ${url} 查看!(链接有效期 1 天)`]) + // }) + // .catch((error) => { + // log.error(`renderDefault: ${error.toString()}`) + // resolve("发生致命错误,已上报给管理员。") + // }) + // } else { + // log.error(`add-queryer: when get user-id: ${error.toString()}`) + // resolve("发生非致命错误,已上报给管理员。") + // } + // }) + // break - default: - // 运行 online.ts 中的 getOSUStats() 获取回复消息内容 - getOSUStats() - .then((replytext) => { - renderDefault(replytext) - .then((url) => { - resolve([`[CQ:image,file=${url}]`,`图片消息发送失败了>﹏<,请前往 ${url} 查看!(链接有效期 1 天)`]) - }) - .catch((error) => { - log.error(`renderDefault: ${error.toString()}`) - resolve("发生致命错误,已上报给管理员。") - }) - }) - .catch((replytext) => { - resolve(replytext.toString()) - }) - } + // default: + // // 运行 online.ts 中的 getOSUStats() 获取回复消息内容 + // getOSUStats() + // .then((replytext) => { + // renderDefault(replytext) + // .then((url) => { + // resolve([`[CQ:image,file=${url}]`,`图片消息发送失败了>﹏<,请前往 ${url} 查看!(链接有效期 1 天)`]) + // }) + // .catch((error) => { + // log.error(`renderDefault: ${error.toString()}`) + // resolve("发生致命错误,已上报给管理员。") + // }) + // }) + // .catch((replytext) => { + // resolve(replytext.toString()) + // }) + // } break } diff --git a/src/mp.ts b/src/mp.ts index 70a24f5..f958d97 100644 --- a/src/mp.ts +++ b/src/mp.ts @@ -2,7 +2,7 @@ import child_process from 'child_process' import { appStatus } from "./app.js" import { renderDefault } from './render/_middleware.js' import { log } from "./logger.js" -import { stopIRC, startIRC } from "./online.js" +// import { stopIRC, startIRC } from "./online.js" import config from "../botconfig.js" const osuahr :osuahr_types[] = [] @@ -66,9 +66,9 @@ class osuahrClass implements osuahr_types { appStatus.isMP = false this.roomName = "" this.isWaitClose = false - setTimeout(async () => { - await startIRC() - }, 3000) + // setTimeout(async () => { + // await startIRC() + // }, 3000) osuahr.splice(0, osuahr.length) } @@ -165,7 +165,7 @@ class osuahrClass implements osuahr_types { return } appStatus.isMP = true - await stopIRC() + // await stopIRC() osuahr.push(new osuahrClass(room)) renderDefault(`注意:主持多人游戏期间查询在线功能将暂停!
5s 后开始创建房间并主持:${osuahr[0].roomName}`) .then((url) => { @@ -242,7 +242,7 @@ class osuahrClass implements osuahr_types { if (config.debug) { if (msg[1] === "start") { appStatus.isMP = true - await stopIRC() + // await stopIRC() log.debug("osu-ahr: stop online-query IRC") osuahr.push(new osuahrClass("*以 Debug 方式启动*")) setTimeout(() => {