Skip to content

Commit

Permalink
perf: 将schinese添加到所有请求
Browse files Browse the repository at this point in the history
  • Loading branch information
XasYer committed Dec 18, 2024
1 parent 80b643f commit f4aacf5
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 44 deletions.
45 changes: 26 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@

## **注意**

一定要填**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

相关链接:

- [Steam Web API 说明](https://partner.steamgames.com/doc/webapi_overview/auth)
- [申请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 愿望单 等功能
Expand All @@ -39,28 +41,33 @@
### 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
```

### 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
```
Expand All @@ -82,7 +89,7 @@ pnpm install --filter=steam-plugin
- [x] steam统计
- [x] 群友上下线通知
- [ ] steam喜加一
- [x] 开启/关闭推送
- [x] 开启/关闭推送
- [x] steam特惠
- [x] 推送黑/白群名单
- [x] steam绑定渲染成图片
Expand Down Expand Up @@ -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步设置的域名
Expand All @@ -148,4 +155,4 @@ pnpm install --filter=steam-plugin

## 其他

如果觉得此插件对你有帮助的话,可以点一个 star,你的支持就是不断更新的动力~
如果觉得此插件对你有帮助的话,可以点一个 star,你的支持就是不断更新的动力~
6 changes: 3 additions & 3 deletions apps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('-------^_^-------')
1 change: 1 addition & 0 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions models/api/IPlayerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions models/api/ISteamUserStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {}
Expand Down
1 change: 0 additions & 1 deletion models/api/IStoreBrowseService.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export async function GetItems (appids) {
const data = {
ids: appids.map(appid => ({ appid })),
context: {
language: 'schinese',
country_code: 'CN'
}
}
Expand Down
16 changes: 3 additions & 13 deletions models/api/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 => {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions models/bind/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand All @@ -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)) {
Expand Down
3 changes: 3 additions & 0 deletions models/utils/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f4aacf5

Please sign in to comment.