Skip to content

Commit

Permalink
feat: steam开启/关闭推送
Browse files Browse the repository at this point in the history
  • Loading branch information
XasYer committed Nov 21, 2024
1 parent d460d76 commit bc3fcff
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 8 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<br/>

![GitHub release (latest by date)](https://img.shields.io/github/v/release/XasYer/YePanel)
![GitHub stars](https://img.shields.io/github/stars/XasYer/steam-plugin?style=social)
![GitHub forks](https://img.shields.io/github/forks/XasYer/steam-plugin?style=social)
![GitHub license](https://img.shields.io/github/license/XasYer/steam-plugin)
Expand All @@ -17,6 +18,8 @@

</div>

![Star History Chart](https://api.star-history.com/svg?repos=XasYer/steam-plugin&type=Date)

## 介绍

这是一个基于 [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 Down Expand Up @@ -56,6 +59,7 @@ pnpm install --filter=steam-plugin

- [x] steam绑定
- [x] steam更换绑定
- [x] steam解除绑定
- [x] steam库存
- [x] steam最近游玩
- [x] steam愿望单
Expand All @@ -66,8 +70,9 @@ pnpm install --filter=steam-plugin
- [ ] steam成就统计
- [ ] 群友上下线通知
- [ ] steam喜加一
- [ ] 开启/关闭推送
- [x] 开启/关闭推送
- [x] steam特惠
- [ ] 推送黑/白群名单

## 联系方式

Expand Down
15 changes: 13 additions & 2 deletions apps/bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ export const rule = {
if (!userBindAll.length) {
await e.reply('要和SteamID或好友码一起发送哦')
} else {
await e.reply(`已绑定:\n${userBindAll.map(item => `${item.steamId} ${item.isBind ? '√' : ''}`).join('\n')}`)
const pushSteamIds = await db.PushTableGetAllSteamIdBySteamIdAndGroupId(uid, e.group_id)
await e.reply(`全部steamId(✧:是否推送 √:是否绑定):\n${userBindAll.map(item => {
const isBind = item.isBind ? '√' : ''
const isPush = pushSteamIds.includes(item.steamId) ? '✧' : ''
return `${item.steamId} ${isPush} ${isBind} `
}).join('\n')}`)
}
return true
}
Expand All @@ -37,11 +42,17 @@ export const rule = {
// TODO: config如果默认开启推送则添加到推送列表
// 群聊绑定才添加
if (e.group_id) {
await db.PushTableSetNAUserIdToRealUserIdBySteamId(uid, steamId)
await db.PushTableAddData(uid, steamId, e.self_id, e.group_id)
}
}
const userBindAll = await db.UserTableGetDataByUserId(uid)
await e.reply(`已添加steamId: ${steamId}\n已绑定:\n${userBindAll.map(item => `${item.steamId} ${item.isBind ? '√' : ''}`).join('\n')}`)
const pushSteamIds = await db.PushTableGetAllSteamIdBySteamIdAndGroupId(uid, e.group_id)
await e.reply(`已添加steamId: ${steamId}\n全部steamId(✧:是否推送 √:是否绑定):\n${userBindAll.map(item => {
const isBind = item.isBind ? '√' : ''
const isPush = pushSteamIds.includes(item.steamId) ? '✧' : ''
return `${item.steamId} ${isPush} ${isBind} `
}).join('\n')}`)
return true
}
},
Expand Down
3 changes: 0 additions & 3 deletions apps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { logger } from '#lib'
import { join } from 'node:path'
import { App, Version } from '#components'
import chalk from 'chalk'
import { task } from '#models'

const startTime = Date.now()

Expand Down Expand Up @@ -32,8 +31,6 @@ for (const i of files) {

export { apps }

task.startTimer()

const getRandomHexColor = () => {
const randomColor = Math.floor(Math.random() * 16777215).toString(16)
return `#${randomColor.padStart(6, '0')}`
Expand Down
59 changes: 59 additions & 0 deletions apps/push.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { App } from '#components'
import { segment } from '#lib'
import { db, utils, task } from '#models'

task.startTimer()

const app = {
id: 'push',
name: '推送'
}

export const rule = {
push: {
reg: /^#?steam(?:开启|关闭)推送\s*(\d+)?$/i,
fnc: async e => {
if (!e.group_id) {
return true
}
const textId = rule.push.reg.exec(e.msg)[1]
const open = e.msg.includes('开启')
// 如果附带了steamId
if (textId) {
const steamId = utils.getSteamId(textId)
const user = await db.UserTableGetDataBySteamId(steamId)
// 如果没有人绑定这个steamId则判断是否为主人,主人才能添加推送
if (((!user && e.isMaster) || (user && user.userId == e.user_id))) {
const uid = e.isMaster ? utils.getAtUid(e.at, '0') : e.user_id
if (open) {
await db.PushTableAddData(uid, steamId, e.self_id, e.group_id)
await e.reply([uid == '0' ? '' : segment.at(uid), `已开启推送: ${steamId}`])
} else {
await db.PushTableDelData(uid, steamId, e.self_id, e.group_id)
await e.reply([uid == '0' ? '' : segment.at(uid), `已关闭推送: ${steamId}`])
}
} else {
await e.reply('只能开启或关闭自己的推送哦')
}
} else {
const uid = utils.getAtUid(e.isMaster ? e.at : '', e.user_id)
// 没有附带steamId则使用绑定的steamId
const steamId = await db.UserTableGetBindSteamIdByUserId(uid)
if (steamId) {
if (open) {
await db.PushTableAddData(uid, steamId, e.self_id, e.group_id)
await e.reply([segment.at(uid), `已开启推送: ${steamId}`])
} else {
await db.PushTableDelData(uid, steamId, e.self_id, e.group_id)
await e.reply([segment.at(uid), `已关闭推送: ${steamId}`])
}
} else {
await e.reply('你还没有steamId哦')
}
}
return true
}
}
}

export const pushApp = new App(app, rule).create()
34 changes: 34 additions & 0 deletions models/db/push.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,23 @@ export async function PushTableGetDataBySteamId (steamId) {
}).then(result => result?.map(item => item?.dataValues))
}

/**
* 根据userId和groupId获取所有的steamId
* @param {string} userId
* @param {string} groupId
*/
export async function PushTableGetAllSteamIdBySteamIdAndGroupId (userId, groupId) {
if (!groupId) return []
userId = String(userId)
groupId = String(groupId)
return await PushTable.findAll({
where: {
userId,
groupId
}
}).then(result => result.map(item => item?.dataValues?.steamId))
}

/**
* 删除steamId的所有推送群组
* @param {string} steamId
Expand All @@ -127,3 +144,20 @@ export async function PushTableDelAllDataBySteamId (steamId, transaction) {
export async function PushTableGetAllData () {
return await PushTable.findAll().then(result => result?.map(item => item?.dataValues))
}

/**
* 将指定的steamId对应的所有为0的userId替换为真实的userId
* @param {string} userId
* @param {string} steamId
*/
export async function PushTableSetNAUserIdToRealUserIdBySteamId (userId, steamId) {
userId = String(userId)
return await PushTable.update({
userId
}, {
where: {
steamId,
userId: '0'
}
}).then(result => result?.[0])
}
12 changes: 11 additions & 1 deletion models/help/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const helpCfg = {
}
export const helpList = [
{
group: 'steam 信息',
group: 'steam 信息 (可在指令后添加steamId或at用户使用)',
list: [
{
icon: 9,
Expand All @@ -26,6 +26,16 @@ export const helpList = [
title: '#steam状态',
desc: '查看steam个人状态'
},
{
icon: 33,
title: '#steam开启推送',
desc: '开启steam个人状态推送'
},
{
icon: 34,
title: '#steam关闭推送',
desc: '关闭steam个人状态推送'
},
{
icon: 12,
title: '#steam库存',
Expand Down
3 changes: 2 additions & 1 deletion models/task/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export function startTimer () {
} else if (!Bot[i.botId]) {
continue
}
const nickname = await utils.getUserName(i.botId, i.userId, i.groupId)
// 0 就是没有人绑定
const nickname = i.userId == '0' ? player.personaname : await utils.getUserName(i.botId, i.userId, i.groupId)
const msg = []
iconBuffer && msg.push(segment.image(iconBuffer))
// 如果有gameid就是开始玩
Expand Down

0 comments on commit bc3fcff

Please sign in to comment.