From f4aacf5b64f68e08fd0c8ad253500aadfda95969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=8F=B6?= <1936472877@qq.com> Date: Wed, 18 Dec 2024 11:29:01 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=B0=86schinese=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=88=B0=E6=89=80=E6=9C=89=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 45 ++++++++++++++++++------------- apps/index.js | 6 ++--- lib/logger.js | 1 + models/api/IPlayerService.js | 4 +-- models/api/ISteamUserStats.js | 3 +-- models/api/IStoreBrowseService.js | 1 - models/api/store.js | 16 +++-------- models/bind/index.js | 6 ++--- models/utils/request.js | 3 +++ 9 files changed, 41 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index f18abc2..c8f8700 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ ## **注意** -一定要填**Steam Web API Key**,否则无法使用绝大部分功能,通常会返回 401 或 403 错误,请前往[Steam API](https://steamcommunity.com/dev/apikey)申请API Key +1. 一定要填**Steam Web API Key**,否则无法使用绝大部分功能,通常会返回 401 或 403 错误,请前往[Steam API](https://steamcommunity.com/dev/apikey)申请API Key 相关链接: @@ -30,6 +30,8 @@ - [申请API Key](https://steamcommunity.com/dev/apikey) - [Steam API 条款](https://steamcommunity.com/dev/apiterms) +2. Steam 是国外网站, 所以通常需要配置代理或反代链接, 否则可能会出现连接超时, 通常会返回: `timeout of 5000ms exceeded` + ## 介绍 这是一个基于 [Miao-Yunzai](https://github.com/yoimiya-kokomi/Miao-Yunzai)&[Trss-Yunzai](https://github.com/TimeRainStarSky/Yunzai)&[Karin](https://github.com/KarinJS/Karin)的扩展插件, 提供 steam 群友状态播报, steam 库存, steam 愿望单 等功能 @@ -39,11 +41,13 @@ ### Yunzai使用 #### 使用github + ```bash git clone --depth=1 https://github.com/XasYer/steam-plugin.git ./plugins/steam-plugin ``` #### 使用gitee + ```bash git clone --depth=1 https://gitee.com/xiaoye12123/steam-plugin.git ./plugins/steam-plugin ``` @@ -51,16 +55,19 @@ git clone --depth=1 https://gitee.com/xiaoye12123/steam-plugin.git ./plugins/ste ### Karin使用 #### 使用github + ```bash git clone --depth=1 https://github.com/XasYer/steam-plugin.git ./plugins/karin-plugin-steam ``` #### 使用gitee + ```bash git clone --depth=1 https://gitee.com/xiaoye12123/steam-plugin.git ./plugins/karin-plugin-steam ``` ### 安装依赖 + ```bash pnpm install --filter=steam-plugin ``` @@ -82,7 +89,7 @@ pnpm install --filter=steam-plugin - [x] steam统计 - [x] 群友上下线通知 - [ ] steam喜加一 -- [x] 开启/关闭推送 +- [x] 开启/关闭推送 - [x] steam特惠 - [x] 推送黑/白群名单 - [x] steam绑定渲染成图片 @@ -111,22 +118,22 @@ pnpm install --filter=steam-plugin 2. 打开[Workers 和 Pages](https://dash.cloudflare.com/1e36e2833bb5f40af76d604e0894cb93/workers-and-pages), 点击`创建`, 然后点击`创建 Worker` 3. 名字随意, 可参考`steam` 然后点击`部署` 再点击`编辑代码` 4. 复制以下代码到编辑器, `覆盖`原内容, 然后点击`部署`, 出现`版本已保存`即可 - ```js - export default { - async fetch(request) { - const url = new URL(request.url) - const path = decodeURIComponent(url.pathname.replace('/','')) - if (!path || !path.startsWith('http')) { - return new Response('Ciallo~(∠・ω< )⌒☆'); - } - const target = new URL(path) - url.hostname = path.replace(/https?:\/\//,'') - url.protocol = target.protocol - url.pathname = target.pathname - return await fetch(new Request(url, request)) - } - } - ``` + ```js + export default { + async fetch(request) { + const url = new URL(request.url); + const path = decodeURIComponent(url.pathname.replace("/", "")); + if (!path || !path.startsWith("http")) { + return new Response("Ciallo~(∠・ω< )⌒☆"); + } + const target = new URL(path); + url.hostname = path.replace(/https?:\/\//, ""); + url.protocol = target.protocol; + url.pathname = target.pathname; + return await fetch(new Request(url, request)); + }, + }; + ``` 5. 依次点击`左上角第3步填写的名字`, `设置`, `域和路由`右边的`添加`, `自定义域`, 然后填入你想设置的二级或多级域名, 比如`steam.example.com`, 然后点`添加域` 6. 测试(可选): 浏览器访问`https://steam.example.com/https://api.steampowered.com/ISteamWebAPIUtil/GetServerInfo/v1/`, `steam.example.com`替换成第5步设置的域名, 如果能看到`servertime`字段, 说明配置成功 7. 对你的Bot发送`#steam设置通用反代https://steam.example.com/{{url}}`, 域名替换成第5步设置的域名 @@ -148,4 +155,4 @@ pnpm install --filter=steam-plugin ## 其他 -如果觉得此插件对你有帮助的话,可以点一个 star,你的支持就是不断更新的动力~ \ No newline at end of file +如果觉得此插件对你有帮助的话,可以点一个 star,你的支持就是不断更新的动力~ diff --git a/apps/index.js b/apps/index.js index 3212536..df825d1 100644 --- a/apps/index.js +++ b/apps/index.js @@ -30,6 +30,6 @@ for (const i of files) { export { apps } -logger.info('-----------------') -logger.info(`${Version.pluginName} v${Version.pluginVersion} 加载成功~ 耗时: ${Date.now() - startTime}ms`) -logger.info('-------^_^-------') +logger.infoLog('-----------------') +logger.infoLog(`${Version.pluginName} v${Version.pluginVersion} 加载成功~ 耗时: ${Date.now() - startTime}ms`) +logger.infoLog('-------^_^-------') diff --git a/lib/logger.js b/lib/logger.js index 28e038c..fe8df58 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -17,6 +17,7 @@ const getRandomHexColor = () => { export default { ...logger, + infoLog: (...logs) => logger.info(chalk.hex(getRandomHexColor())(`[${Version.pluginName}]`, ...logs)), info: (...logs) => Config.other.log ? logger.info(chalk.hex(getRandomHexColor())(`[${Version.pluginName}]`, ...logs)) : null, diff --git a/models/api/IPlayerService.js b/models/api/IPlayerService.js index 975e7d4..e303812 100644 --- a/models/api/IPlayerService.js +++ b/models/api/IPlayerService.js @@ -58,7 +58,6 @@ export async function GetOwnedGames (steamid) { return utils.request.get('IPlayerService/GetOwnedGames/v1', { params: { steamid, - language: 'schinese', include_appinfo: true, include_extended_appinfo: true } @@ -160,8 +159,7 @@ export async function GetGameAchievements (appid) { logger.info(`开始获取${appid}的成就完成度`) return utils.request.get('IPlayerService/GetGameAchievements/v1', { params: { - appid, - language: 'schinese' + appid } }).then(res => { const data = res.data.response diff --git a/models/api/ISteamUserStats.js b/models/api/ISteamUserStats.js index f0f4320..25ab240 100644 --- a/models/api/ISteamUserStats.js +++ b/models/api/ISteamUserStats.js @@ -75,8 +75,7 @@ export async function GetSchemaForGame (appid) { const start = Date.now() return utils.request.get('ISteamUserStats/GetSchemaForGame/v2', { params: { - appid, - l: 'schinese' + appid } }).then(res => { const data = res.data.game || {} diff --git a/models/api/IStoreBrowseService.js b/models/api/IStoreBrowseService.js index 3604bf0..39edf97 100644 --- a/models/api/IStoreBrowseService.js +++ b/models/api/IStoreBrowseService.js @@ -44,7 +44,6 @@ export async function GetItems (appids) { const data = { ids: appids.map(appid => ({ appid })), context: { - language: 'schinese', country_code: 'CN' } } diff --git a/models/api/store.js b/models/api/store.js index 98e7340..fa32aa6 100644 --- a/models/api/store.js +++ b/models/api/store.js @@ -110,9 +110,7 @@ export async function appdetails (appid) { return utils.request.get('api/appdetails', { baseURL: getBaseURL(), params: { - appids: appid, - l: 'schinese', - cc: 'CN' + appids: appid } }).then(res => { if (res.data[appid].success) { @@ -138,9 +136,7 @@ export async function search (name) { params: { term: name, f: 'games', - cc: 'CN', - realm: 1, - l: 'schinese' + realm: 1 }, responseType: 'text' }).then(res => { @@ -199,11 +195,7 @@ export async function featuredcategories () { const start = Date.now() logger.info('开始获取优惠信息') return utils.request.get('api/featuredcategories', { - baseURL: getBaseURL(), - params: { - l: 'schinese', - cc: 'CN' - } + baseURL: getBaseURL() }).then(res => { logger.info(`获取优惠信息成功,耗时${Date.now() - start}ms`) return res.data @@ -232,8 +224,6 @@ export async function appreviews (appid, count = 30, recent = false) { return utils.request.get(`appreviews/${appid}`, { baseURL: getBaseURL(), params: { - l: 'schinese', - language: 'schinese', filter: recent ? 'recent' : 'all', num_per_page: count } diff --git a/models/bind/index.js b/models/bind/index.js index dabfa26..da0dda8 100644 --- a/models/bind/index.js +++ b/models/bind/index.js @@ -39,7 +39,7 @@ export async function getBindSteamIdsImg (bid, uid, gid, userBindAll = []) { const enablePushSteamIdList = enablePush ? await db.PushTableGetAllSteamIdBySteamIdAndGroupId(uid, gid, true) : [] const allSteamIdInfo = {} try { - const res = await api.ISteamUser.GetPlayerSummaries(userBindAll.map(i => i.steamId)) + const res = await api.ISteamUser.GetPlayerSummaries(userBindAll.map(i => i.steamId)).catch(() => []) res.forEach(i => { allSteamIdInfo[i.steamid] = i }) @@ -50,8 +50,8 @@ export async function getBindSteamIdsImg (bid, uid, gid, userBindAll = []) { const info = { steamId: item.steamId, isBind: item.isBind, - name: allSteamIdInfo[item.steamId].personaname, - avatar: avatar ?? await utils.getUserAvatar(bid, uid, gid), + name: allSteamIdInfo[item.steamId].personaname || await utils.getUserName(bid, uid, gid), + avatar: avatar || await utils.getUserAvatar(bid, uid, gid), index } if (enablePushSteamIdList.includes(item.steamId)) { diff --git a/models/utils/request.js b/models/utils/request.js index fbecd40..1d7975e 100644 --- a/models/utils/request.js +++ b/models/utils/request.js @@ -29,6 +29,9 @@ export default async function request (url, options = {}) { ...options, params: { key: baseURL === steamApi ? Config.steam.apiKey : undefined, + l: 'schinese', + cc: 'CN', + language: 'schinese', ...options.params }, timeout: Config.steam.timeout * 1000