diff --git a/README.md b/README.md index 5a3b46b..e345cc9 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@
+![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) @@ -17,6 +18,8 @@ +![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 愿望单 等功能 @@ -56,6 +59,7 @@ pnpm install --filter=steam-plugin - [x] steam绑定 - [x] steam更换绑定 +- [x] steam解除绑定 - [x] steam库存 - [x] steam最近游玩 - [x] steam愿望单 @@ -66,8 +70,9 @@ pnpm install --filter=steam-plugin - [ ] steam成就统计 - [ ] 群友上下线通知 - [ ] steam喜加一 -- [ ] 开启/关闭推送 +- [x] 开启/关闭推送 - [x] steam特惠 +- [ ] 推送黑/白群名单 ## 联系方式 diff --git a/apps/bind.js b/apps/bind.js index 0249951..2e3ee60 100644 --- a/apps/bind.js +++ b/apps/bind.js @@ -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 } @@ -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 } }, diff --git a/apps/index.js b/apps/index.js index b5fcda6..1360686 100644 --- a/apps/index.js +++ b/apps/index.js @@ -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() @@ -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')}` diff --git a/apps/push.js b/apps/push.js new file mode 100644 index 0000000..986fff9 --- /dev/null +++ b/apps/push.js @@ -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() diff --git a/models/db/push.js b/models/db/push.js index 4f6c03a..eb2e190 100644 --- a/models/db/push.js +++ b/models/db/push.js @@ -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 @@ -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]) +} diff --git a/models/help/help.js b/models/help/help.js index 0ce7d89..a244e71 100644 --- a/models/help/help.js +++ b/models/help/help.js @@ -9,7 +9,7 @@ export const helpCfg = { } export const helpList = [ { - group: 'steam 信息', + group: 'steam 信息 (可在指令后添加steamId或at用户使用)', list: [ { icon: 9, @@ -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库存', diff --git a/models/task/index.js b/models/task/index.js index 529e841..3b4b5f8 100644 --- a/models/task/index.js +++ b/models/task/index.js @@ -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就是开始玩