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 bc3fcff commit 06efe48
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 13 deletions.
13 changes: 6 additions & 7 deletions apps/bind.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { utils, db } from '#models'
import { App } from '#components'
import { App, Config } from '#components'

const app = {
id: 'bind',
Expand All @@ -19,9 +19,9 @@ export const rule = {
await e.reply('要和SteamID或好友码一起发送哦')
} else {
const pushSteamIds = await db.PushTableGetAllSteamIdBySteamIdAndGroupId(uid, e.group_id)
await e.reply(`全部steamId(✧:是否推送 √:是否绑定):\n${userBindAll.map(item => {
await e.reply(`全部steamId(${Config.push.enable ? '✧:是否推送 ' : ''}√:是否绑定):\n${userBindAll.map(item => {
const isBind = item.isBind ? '√' : ''
const isPush = pushSteamIds.includes(item.steamId) ? '✧' : ''
const isPush = (Config.push.enable && pushSteamIds.includes(item.steamId)) ? '✧' : ''
return `${item.steamId} ${isPush} ${isBind} `
}).join('\n')}`)
}
Expand All @@ -39,18 +39,17 @@ export const rule = {
return true
} else {
await db.UserTableAddSteamIdByUserId(uid, steamId)
// TODO: config如果默认开启推送则添加到推送列表
// 群聊绑定才添加
if (e.group_id) {
if (Config.push.defaultPush && 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)
const pushSteamIds = await db.PushTableGetAllSteamIdBySteamIdAndGroupId(uid, e.group_id)
await e.reply(`已添加steamId: ${steamId}\n全部steamId(✧:是否推送 √:是否绑定):\n${userBindAll.map(item => {
await e.reply(`已添加steamId: ${steamId}\n全部steamId(${Config.push.enable ? '✧:是否推送 ' : ''}√:是否绑定):\n${userBindAll.map(item => {
const isBind = item.isBind ? '√' : ''
const isPush = pushSteamIds.includes(item.steamId) ? '✧' : ''
const isPush = (Config.push.enable && pushSteamIds.includes(item.steamId)) ? '✧' : ''
return `${item.steamId} ${isPush} ${isBind} `
}).join('\n')}`)
return true
Expand Down
14 changes: 13 additions & 1 deletion apps/push.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { App } from '#components'
import { App, Config } from '#components'
import { segment } from '#lib'
import { db, utils, task } from '#models'

Expand All @@ -16,6 +16,18 @@ export const rule = {
if (!e.group_id) {
return true
}
if (!Config.push.enable) {
await e.reply('主人没有开启推送功能哦')
return true
}
if (Config.push.whiteGroupList.length && !Config.push.whiteGroupList.some(id => id == e.group_id)) {
await e.reply('本群没有在推送白名单中, 请联系主人添加~')
return true
}
if (Config.push.blackGroupList.length && Config.push.blackGroupList.some(id => id == e.group_id)) {
await e.reply('本群在推送黑名单中, 请联系主人解除~')
return true
}
const textId = rule.push.reg.exec(e.msg)[1]
const open = e.msg.includes('开启')
// 如果附带了steamId
Expand Down
32 changes: 32 additions & 0 deletions apps/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,38 @@ export const rule = {
}
return true
}
},
push: {
reg: /^#steam(添加|删除)?推送(黑|白)名单(列表)?\s*(.*)?$/,
fnc: async e => {
if (!e.isMaster) {
await e.reply('只有主人才可以设置哦~')
return true
}
const regRet = rule.push.reg.exec(e.msg)
const target = regRet[2] === '黑' ? 'blackGroupList' : 'whiteGroupList'
const data = Config.push[target]
if (regRet[3] || !regRet[1]) {
await e.reply(`${regRet[2]}名单列表:\n ${data.join(', ') || '空'}`)
return true
}
const type = regRet[1] === '添加' ? 'add' : 'del'
const id = regRet[3] || String(e.group_id)
if (!id) {
await e.reply('请输入群号或在指定群中使用~')
return true
}
if (type === 'add') {
if (data.some(i => i.id == id)) {
await e.reply(`${id}已经在${regRet[2]}名单中了~`)
} else {
data.push(id)
await e.reply(`已将${id}${regRet[1]}${regRet[2]}名单了~现在的${regRet[2]}名单是:\n ${data.join(', ') || '空'}`)
Config.modify('push', target, data)
}
}
return true
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion components/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ class Config {
* 获取推送配置
* @returns {{
* enable: boolean,
* time: number
* time: number,
* defaultPush: boolean,
* blackGroupList: string[],
* whiteGroupList: string[]
* }}
*/
get push () {
Expand Down
12 changes: 11 additions & 1 deletion config/default_config/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,14 @@ enable: true
# https://steamcommunity.com/dev/apiterms
# 其中说明: 每天对 Steam Web API 的调用次数限制为十万 (100,000) 次
# 多少分钟检查一次
time: 5
time: 5

# 是否默认开启推送 即绑定steamId之后不需要发 #steam开启推送 指令
defaultPush: true

# 推送黑名单群
blackGroupList:
- 123456

# 推送白名单群
whiteGroupList: []
22 changes: 19 additions & 3 deletions models/db/push.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { sequelize, DataTypes } from './base.js'
import { Config } from '#components'
import { sequelize, DataTypes, Op } from './base.js'

/**
* @typedef {Object} PushColumns
Expand Down Expand Up @@ -139,10 +140,25 @@ export async function PushTableDelAllDataBySteamId (steamId, transaction) {

/**
* 获取所有推送群组
* @param {boolean} [filter=true] 是否使用黑白名单查找 默认开启
* @returns {Promise<PushColumns[]>}
*/
export async function PushTableGetAllData () {
return await PushTable.findAll().then(result => result?.map(item => item?.dataValues))
export async function PushTableGetAllData (filter = true) {
const where = {}
if (filter) {
if (Config.push.whiteGroupList.length) {
where.groupId = {
[Op.in]: Config.push.whiteGroupList.map(i => String(i))
}
} else if (Config.push.blackGroupList.length) {
where.groupId = {
[Op.notIn]: Config.push.blackGroupList.map(i => String(i))
}
}
}
return await PushTable.findAll({
where
}).then(result => result?.map(item => item?.dataValues))
}

/**
Expand Down
21 changes: 21 additions & 0 deletions models/help/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,26 @@ export const helpList = [
desc: '查看steam热销游戏'
}
]
},
{
group: '主人功能',
auth: 'master',
list: [
{
icon: 36,
title: '#steam添加推送(黑|白)名单',
desc: '添加指定群到推送(黑|白)名单'
},
{
icon: 37,
title: '#steam删除推送(黑|白)名单',
desc: '删除指定群的推送(黑|白)名单'
},
{
icon: 42,
title: '#steam推送(黑|白)名单列表',
desc: '查看推送(黑|白)名单列表'
}
]
}
]

0 comments on commit 06efe48

Please sign in to comment.