diff --git a/README.md b/README.md index 2ecca8b..a8214b5 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,6 @@ pnpm install --filter=steam-plugin - steam喜加一 - steam游戏详情 -- steam用户统计 ## 联系方式 @@ -129,7 +128,7 @@ pnpm install --filter=steam-plugin > 🌟 星光闪烁,你们的智慧如同璀璨的夜空。感谢所有为 **steam-plugin** 做出贡献的人! - + ![Alt](https://repobeats.axiom.co/api/embed/aafe6a6a7a72df285ae3965974546314c467db8d.svg "Repobeats analytics image") diff --git a/apps/push.js b/apps/push.js index 7b8c03e..7356eee 100644 --- a/apps/push.js +++ b/apps/push.js @@ -14,7 +14,9 @@ const rule = { push: { reg: App.getReg('(?:开启|关闭)推送\\s*(\\d*)'), fnc: async e => { - if (!await checkGroup(e)) { + const g = utils.bot.checkGroup(e.group_id) + if (!g.success) { + await e.reply(g.message) return true } const textId = rule.push.reg.exec(e.msg)[1] @@ -63,7 +65,9 @@ const rule = { list: { reg: App.getReg('(本群)?推送列表'), fnc: async e => { - if (!await checkGroup(e)) { + const g = utils.bot.checkGroup(e.group_id) + if (!g.success) { + await e.reply(g.message) return true } const list = await db.PushTableGetDataByGroupId(e.group_id, true) @@ -156,7 +160,7 @@ const rule = { desc: utils.steam.getPersonaState(i.personastate), image: await utils.bot.getUserAvatar(userInfo.botId, userInfo.userId, userInfo.groupId) || (Config.other.steamAvatar ? i.avatarfull : `https://q.qlogo.cn/g?b=qq&s=100&nk=${userInfo.userId}`), isAvatar: true, - descBgColor: getColor(i.personastate) + descBgColor: utils.steam.getStateColor(i.personastate) }) } } @@ -180,33 +184,3 @@ const rule = { } export const app = new App(appInfo, rule).create() - -async function checkGroup (e) { - if (!e.group_id) { - return false - } - if (!Config.push.enable) { - await e.reply('主人没有开启推送功能哦') - return false - } - if (Config.push.whiteGroupList.length && !Config.push.whiteGroupList.some(id => id == e.group_id)) { - await e.reply('本群没有在推送白名单中, 请联系主人添加~') - return false - } - if (Config.push.blackGroupList.length && Config.push.blackGroupList.some(id => id == e.group_id)) { - await e.reply('本群在推送黑名单中, 请联系主人解除~') - return false - } - return true -} - -function getColor (state) { - switch (Number(state)) { - case 1: - return '#beee11' - case 0: - return '#999999' - default: - return '#8fbc8b' - } -} diff --git a/apps/stats.js b/apps/stats.js index 81b063c..f35a10e 100644 --- a/apps/stats.js +++ b/apps/stats.js @@ -16,7 +16,9 @@ const rule = { tips: true }, fnc: async e => { - if (!checkGroup(e.group_id)) { + const g = utils.bot.checkGroup(e.group_id) + if (!g.success) { + await e.reply(g.message) return true } const limit = Math.max(1, Number(Config.other.statsCount) || 10) @@ -159,23 +161,4 @@ const rule = { } } -async function checkGroup (e) { - if (!e.group_id) { - return false - } - if (!Config.push.enable) { - await e.reply('主人没有开启推送功能哦') - return false - } - if (Config.push.whiteGroupList.length && !Config.push.whiteGroupList.some(id => id == e.group_id)) { - await e.reply('本群没有在推送白名单中, 请联系主人添加~') - return false - } - if (Config.push.blackGroupList.length && Config.push.blackGroupList.some(id => id == e.group_id)) { - await e.reply('本群在推送黑名单中, 请联系主人解除~') - return false - } - return true -} - export const app = new App(appInfo, rule).create() diff --git a/components/Config.js b/components/Config.js index f5f66bf..f507366 100644 --- a/components/Config.js +++ b/components/Config.js @@ -125,6 +125,7 @@ class Config { * time: number, * defaultPush: boolean, * randomBot: boolean, + * statusFilterGroup: boolean, * blackBotList: string[], * whiteBotList: string[], * blackGroupList: string[], @@ -181,6 +182,11 @@ class Config { * inventoryEmptyTips: string, * recentPlayEmptyTips: string, * wishListEmptyTips: string, + * privateUseTips: string, + * pushDisabledTips: string, + * blackGroupTips: string, + * noWhiteGroupTips: string, + * makeImageFailedTips: string, * }} */ get tips () { diff --git a/components/Render.js b/components/Render.js index 2394043..fa4cde6 100644 --- a/components/Render.js +++ b/components/Render.js @@ -66,7 +66,7 @@ const Render = { if (img) { return img } else { - return '制作图片出错辣!再试一次吧' + return Config.tips.makeImageFailedTips } }, async simpleRender (path, params) { diff --git a/config/default_config/push.yaml b/config/default_config/push.yaml index fea55fd..a554866 100644 --- a/config/default_config/push.yaml +++ b/config/default_config/push.yaml @@ -56,6 +56,10 @@ defaultPush: true # 是否随机Bot进行推送, 有多个Bot在同一群群时随机选择一个在线的Bot推送状态 (仅限TRSS) randomBot: false +# 群统计是否过滤掉黑名单群和白名单群 +# 如果关闭则每次会获取忽略黑白名单的所有群 但是不会推送 仅统计 +statusFilterGroup: true + # 推送的Bot黑名单, 不开启推送的Bot将不会被推送, 比如腾讯QQBot限制主动消息 blackBotList: - 3889000138 @@ -65,7 +69,7 @@ whiteBotList: [] # 推送黑名单群 blackGroupList: - - 123456 + - 741577559 # 推送白名单群 whiteGroupList: [] diff --git a/config/default_config/tips.yaml b/config/default_config/tips.yaml index e932e38..1585df4 100644 --- a/config/default_config/tips.yaml +++ b/config/default_config/tips.yaml @@ -20,3 +20,18 @@ recentPlayEmptyTips: "最近电子阳痿了" # 愿望单为空或未公开时的提示语 wishListEmptyTips: "愿望当场就实现了, 羡慕" + +# 在私聊中使用群聊限定的指令时的提示语 +privateUseTips: "请在群聊中使用此功能~" + +# 没有开启推送功能时的提示语 +pushDisabledTips: "主人没有开启推送功能哦" + +# 在推送黑名单中的提示语 +blackGroupTips: "本群在推送黑名单中, 请联系主人解除~" + +# 不在推送白名单中的提示语 +noWhiteGroupTips: "本群没有在推送白名单中, 请联系主人添加~" + +# 制作图片失败时的提示语 +makeImageFailedTips: "制作图片出错辣!再试一次吧" diff --git a/models/db/user.js b/models/db/user.js index b50fb8d..2dd5989 100644 --- a/models/db/user.js +++ b/models/db/user.js @@ -49,7 +49,6 @@ export async function UserTableAddSteamIdByUserId (userId, steamId) { }).then(result => result?.dataValues) // 更换绑定为新的steamId await UserTableBindSteamIdByUserId(userId, steamId, true) - // TODO: 是否默认开启推送 添加到推送表 return res } diff --git a/models/setting/index.js b/models/setting/index.js index 5494156..699d01b 100644 --- a/models/setting/index.js +++ b/models/setting/index.js @@ -110,6 +110,21 @@ export const cfgSchema = { def: true, desc: '是否推送下线' }, + time: { + title: '推送间隔', + key: '推送间隔', + def: 5, + min: 1, + type: 'number', + input: (n) => { + if (n >= 0) { + return n * 1 + } else { + return 5 + } + }, + desc: '间隔多少分钟推送一次' + }, pushApi: { title: '推送请求api', key: '推送api', @@ -160,6 +175,13 @@ export const cfgSchema = { def: false, desc: '有多个Bot在同一群群时随机选择一个在线的Bot推送状态 (仅限TRSS)' }, + statusFilterGroup: { + title: '统计过滤黑白名单', + key: '统计过滤群', + type: 'boolean', + def: true, + desc: '群统计是否过滤掉黑名单群和白名单群 关闭则每次都会获取所有群的状态' + }, blackBotList: { title: '推送黑名单机器人', key: '推送bot黑名单', @@ -189,21 +211,6 @@ export const cfgSchema = { type: 'array', def: [], desc: '只推送白名单群的状态' - }, - time: { - title: '推送间隔', - key: '推送间隔', - def: 5, - min: 1, - type: 'number', - input: (n) => { - if (n >= 0) { - return n * 1 - } else { - return 5 - } - }, - desc: '间隔多少分钟推送一次' } } }, diff --git a/models/task/index.js b/models/task/index.js index dc9efc1..549d20f 100644 --- a/models/task/index.js +++ b/models/task/index.js @@ -5,7 +5,6 @@ import _ from 'lodash' let timer = null -// TODO: 改成sqlite? const redisKey = 'steam-plugin:user-play:' export function startTimer () { @@ -22,7 +21,7 @@ export function startTimer () { // 获取现在的时间 const now = Math.floor(Date.now() / 1000) // 从推送表中获取所有数据 - const PushData = await db.PushTableGetAllData(true) + const PushData = await db.PushTableGetAllData(Config.push.statusFilterGroup) // 所有的steamId const steamIds = _.uniq(PushData.map(i => i.steamId)) // 获取所有steamId现在的状态 @@ -113,7 +112,7 @@ export function startTimer () { desc: `已${utils.steam.getPersonaState(player.personastate)}`, image: avatar || (Config.other.steamAvatar ? i.avatarfull : ''), isAvatar: true, - descBgColor: getColor(player.personastate) + descBgColor: utils.steam.getStateColor(player.personastate) }) } } @@ -165,11 +164,11 @@ export function startTimer () { const path = Config.push.pushMode === 2 ? 'inventory/index' : 'game/game' const img = await Render.render(path, { data }) if (typeof img !== 'string') { - await utils.bot.sendGroupMsg(botId, gid, img) + await sendGroupMsg(botId, gid, img) } } else { for (const msg of data) { - await utils.bot.sendGroupMsg(botId, gid, msg) + await sendGroupMsg(botId, gid, msg) } } } @@ -180,14 +179,12 @@ export function startTimer () { }, 1000 * 60 * Config.push.time) } -// TODO: -function getColor (state) { - switch (Number(state)) { - case 1: - return '#beee11' - case 0: - return '#999999' - default: - return '#8fbc8b' +async function sendGroupMsg (bid, gid, msg) { + if (typeof msg === 'string') { + return + } + if (!Config.push.statusFilterGroup && !utils.bot.checkGroup(gid).success) { + return } + await utils.bot.sendGroupMsg(bid, gid, msg) } diff --git a/models/utils/bot.js b/models/utils/bot.js index f45cf8c..2f5556b 100644 --- a/models/utils/bot.js +++ b/models/utils/bot.js @@ -152,3 +152,38 @@ export async function makeForwardMsg (e, msg) { return '' } } + +/** + * 检查黑白名单 返回ture表示通过 + * @param {string} gid + * @returns {{success: boolean, message?: string}} + */ +export function checkGroup (gid) { + if (!gid) { + return { + success: false, + message: Config.tips.privateUseTips + } + } + if (!Config.push.enable) { + return { + success: false, + message: Config.tips.pushDisabledTips + } + } + if (Config.push.whiteGroupList.length && !Config.push.whiteGroupList.some(id => id == gid)) { + return { + success: false, + message: Config.tips.noWhiteGroupTips + } + } + if (Config.push.blackGroupList.length && Config.push.blackGroupList.some(id => id == gid)) { + return { + success: false, + message: Config.tips.blackGroupTips + } + } + return { + success: true + } +} diff --git a/models/utils/request.js b/models/utils/request.js index 18788ae..4280273 100644 --- a/models/utils/request.js +++ b/models/utils/request.js @@ -47,7 +47,9 @@ export default async function request (url, options = {}, retry = { count: 0, ke let { retKeys, retKey } = await getKey(retry.keys) key = retKey keys = retKeys - logger.info(`获取请求的key: ${key.slice(0, 5)}...${key.slice(-5)}`) + if (retKeys.length > 1) { + logger.info(`获取请求的key: ${key.slice(0, 5)}...${key.slice(-5)}`) + } } return await axios.request({ url, diff --git a/models/utils/steam.js b/models/utils/steam.js index 822461c..88df979 100644 --- a/models/utils/steam.js +++ b/models/utils/steam.js @@ -233,3 +233,19 @@ export async function getUserSummaries (steamIds) { }) }) } + +/** + * 获取状态对应的颜色 + * @param {number} state + * @returns {string} + */ +export function getStateColor (state) { + switch (Number(state)) { + case 1: + return '#beee11' + case 0: + return '#999999' + default: + return '#8fbc8b' + } +} diff --git a/resources/setting/index.css b/resources/setting/index.css index 77a4b5d..feb77d0 100644 --- a/resources/setting/index.css +++ b/resources/setting/index.css @@ -7,9 +7,6 @@ body { background-size: 700px auto; width: 660px; } -.head-box { - margin: 0 0 80px 0; -} .cfg-box { border-radius: 15px; margin-top: 20px;