Skip to content

Commit

Permalink
Chore: delete osu-query-online function
Browse files Browse the repository at this point in the history
  • Loading branch information
ohmykreee committed Feb 8, 2024
1 parent a301f71 commit 38b512a
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 106 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion botconfig.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -50,7 +50,7 @@ process.once('SIGUSR2', () => {process.stdin.resume(); handleExit(process.exitCo
*/
function handleStart() :void {
// 启动 online.ts 中的 slate-irc 初始化
startIRC()
// startIRC()
// 载入所有的插件
pluginsLoad()
}
Expand Down
187 changes: 94 additions & 93 deletions src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -39,10 +39,10 @@ export function msgHandler(msg :Array<string>, qqid :number) :Promise<string | s
<tr> <td> /help </td> <td> 输出该帮助信息 </td> </tr>
<tr> <td> /ping </td> <td> 康康机器人有没有在摸鱼 </td> </tr>
<tr> <td> /关于 </td> <td> 关于这个机器人的一切 </td> </tr>
<tr> <td> /在线 </td> <td> 返回 osu! 查询列表里在线玩家 </td> </tr>
<tr> <td> /在线 列表 </td> <td> 返回 osu! 在线查询列表里的所有人 </td> </tr>
<tr> <td> /在线 添加 </td> <td> 添加一项至 osu! 在线查询列表 </td> </tr>
<tr> <td> /在线 更新 </td> <td> 立即请求一次 osu! 在线列表的更新 </td> </tr>
<!-- <tr> <td> /在线 </td> <td> 返回 osu! 查询列表里在线玩家 </td> </tr> -->
<!-- <tr> <td> /在线 列表 </td> <td> 返回 osu! 在线查询列表里的所有人 </td> </tr> -->
<!-- <tr> <td> /在线 添加 </td> <td> 添加一项至 osu! 在线查询列表 </td> </tr> -->
<!-- <tr> <td> /在线 更新 </td> <td> 立即请求一次 osu! 在线列表的更新 </td> </tr> -->
<tr> <td> /吃什么 </td> <td> 不知道今天中午/晚上吃什么?问我! </td> </tr>
<tr> <td> /星期四 </td> <td> 星期四?想什么呢! </td> </tr>
<tr> <td> /抽一张 [tag(可选)] </td> <td> 抽一张 Pixiv 图(docs.anosu.top) </td> </tr>
Expand Down Expand Up @@ -84,97 +84,98 @@ export function msgHandler(msg :Array<string>, qqid :number) :Promise<string | s

case "在线":
{
switch (msg[1]) {
case "列表":
reply = "查询列表(排名不分先后)<br>"
const osuname = await db.read("osu")
for (const name of osuname) {
reply = reply + `${name}<br>`
}
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 = "查询列表(排名不分先后)<br>"
// const osuname = await db.read("osu")
// for (const name of osuname) {
// reply = reply + `${name}<br>`
// }
// 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
}

Expand Down
12 changes: 6 additions & 6 deletions src/mp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = []
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -165,7 +165,7 @@ class osuahrClass implements osuahr_types {
return
}
appStatus.isMP = true
await stopIRC()
// await stopIRC()
osuahr.push(new osuahrClass(room))
renderDefault(`注意:主持多人游戏期间查询在线功能将暂停!<br>5s 后开始创建房间并主持:${osuahr[0].roomName}`)
.then((url) => {
Expand Down Expand Up @@ -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(() => {
Expand Down

0 comments on commit 38b512a

Please sign in to comment.