Skip to content

Commit

Permalink
perf: #steam设置随机bot开启 仅限TRSS
Browse files Browse the repository at this point in the history
  • Loading branch information
XasYer committed Dec 6, 2024
1 parent dfb18b3 commit 4c35030
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
16 changes: 13 additions & 3 deletions apps/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const app = {

export const rule = {
setting: {
reg: new RegExp(`^#steam设置\\s*(${keys.join('|')})?[\\s+]*(.*)$`),
reg: new RegExp(`^#steam设置\\s*(${keys.join('|')})?[\\s+]*(.*)$`, 'i'),
fnc: async e => {
if (!e.isMaster) {
await e.reply('只有主人才可以设置哦~')
Expand All @@ -30,7 +30,17 @@ export const rule = {
// 设置模式
let val = regRet[2] || ''

if (regRet[1] == '全部') {
const key = (() => {
if (/apikey/i.test(regRet[1])) {
return 'apiKey'
} if (/随机Bot/i.test(regRet[1])) {
return '随机Bot'
} else {
return regRet[1]
}
})()

if (key == '全部') {
val = !/关闭/.test(val)
for (const i of keys) {
if (typeof cfgSchemaMap[i].def == 'boolean') {
Expand All @@ -42,7 +52,7 @@ export const rule = {
}
}
} else {
const cfgSchema = cfgSchemaMap[regRet[1]]
const cfgSchema = cfgSchemaMap[key]
if (cfgSchema.type !== 'array') {
if (cfgSchema.input) {
val = cfgSchema.input(val)
Expand Down
1 change: 1 addition & 0 deletions components/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class Config {
* pushMode: number,
* time: number,
* defaultPush: boolean,
* randomBot: boolean,
* blackBotList: string[],
* whiteBotList: string[],
* blackGroupList: string[],
Expand Down
3 changes: 3 additions & 0 deletions config/default_config/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ time: 5
# 是否默认开启推送 即绑定steamId之后不需要发 #steam开启推送 指令
defaultPush: true

# 是否随机Bot进行推送, 有多个Bot在同一群群时随机选择一个在线的Bot推送状态 (仅限TRSS)
randomBot: false

# 推送的Bot黑名单, 不开启推送的Bot将不会被推送, 比如腾讯QQBot限制主动消息
blackBotList:
- 3889000138
Expand Down
14 changes: 12 additions & 2 deletions models/setting/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@ export const cfgSchema = {
key: '推送模式',
type: 'number',
def: 1,
min: 1,
max: 2,
component: 'RadioGroup',
options: [
{ label: '文字推送', value: 1 },
{ label: '图片推送', value: 2 }
],
input: (n) => {
if (n >= 1 && n <= 2) {
return n * 1
Expand All @@ -97,6 +100,13 @@ export const cfgSchema = {
},
desc: '推送模式 1: 文字推送 2: 图片推送'
},
randomBot: {
title: '随机推送Bot',
key: '随机Bot',
type: 'boolean',
def: false,
desc: '有多个Bot在同一群群时随机选择一个在线的Bot推送状态 (仅限TRSS)'
},
blackBotList: {
title: '推送黑名单机器人',
key: '推送bot黑名单',
Expand Down
22 changes: 13 additions & 9 deletions models/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs'
import moment from 'moment'
import { Bot, logger } from '#lib'
import { Version } from '#components'
import { Config, Version } from '#components'
import * as request from './request.js'
import { join } from 'path'

Expand Down Expand Up @@ -86,14 +86,15 @@ export async function getUserName (botId, uid, gid) {
}
} else {
uid = Number(uid) || uid
const bot = (Config.push.randomBot && Version.BotName === 'Trss-Yunzai') ? Bot : Bot[botId]
if (gid) {
gid = Number(gid) || gid
const group = Bot[botId].pickGroup(gid)
const group = bot.pickGroup(gid)
const member = await group.pickMember(uid)
const info = await member.getInfo?.() || member.info || {}
return info.card || info.nickname || info.user_id || uid
} else {
const user = Bot[botId].pickFriend(uid)
const user = bot.pickFriend(uid)
const info = await user.getInfo?.() || user.info || {}
return info.nickname || info.user_id || uid
}
Expand All @@ -118,15 +119,16 @@ export async function getUserAvatar (botId, uid, gid) {
return avatarUrl || await bot.getAvatarUrl(botId) || ''
} else {
uid = Number(uid) || uid
const bot = (Config.push.randomBot && Version.BotName === 'Trss-Yunzai') ? Bot : Bot[botId]
if (gid) {
gid = Number(gid) || gid
const group = Bot[botId].pickGroup(gid)
const group = bot.pickGroup(gid)
const avatarUrl = (await group.pickMember(uid)).getAvatarUrl()
return avatarUrl || Bot[botId].avatar
return avatarUrl || bot.avatar
} else {
const user = Bot[botId].pickUser(uid)
const user = bot.pickUser(uid)
const avatarUrl = await user.getAvatarUrl()
return avatarUrl || Bot[botId].avatar || ''
return avatarUrl || bot.avatar || ''
}
}
} catch {
Expand All @@ -147,7 +149,8 @@ export async function getGroupMemberList (botId, groupId) {
const memberList = await Bot.getBot(botId).GetGroupMemberList(groupId)
result.push(...memberList.map(i => i.uid))
} else {
const memberMap = await Bot[botId].pickGroup(groupId).getMemberMap()
const bot = (Config.push.randomBot && Version.BotName === 'Trss-Yunzai') ? Bot : Bot[botId]
const memberMap = await bot.pickGroup(groupId).getMemberMap()
result.push(...memberMap.keys())
}
} catch { }
Expand Down Expand Up @@ -187,7 +190,8 @@ export async function sendGroupMsg (botId, gid, msg) {
return await Bot.sendMsg(botId, { scene: 'group', peer: gid }, msg)
} else {
gid = Number(gid) || gid
return await Bot[botId].pickGroup(gid).sendMsg(msg)
const bot = (Config.push.randomBot && Version.BotName === 'Trss-Yunzai') ? Bot : Bot[botId]
return await bot.pickGroup(gid).sendMsg(msg)
}
}

Expand Down

0 comments on commit 4c35030

Please sign in to comment.