Skip to content

Commit

Permalink
Merge pull request #42 from Marxel-cn/develop
Browse files Browse the repository at this point in the history
discussion #41
  • Loading branch information
Marxel-cn committed Mar 11, 2023
2 parents 24e9983 + e806044 commit 55a6312
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
20 changes: 11 additions & 9 deletions src/commands/focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const storer = require('../el/data-storer')
const { validUser } = require('../el/utils');
const level = require('../el/cachedb')

const GROUP_REGEXP = new RegExp(/\d+[-]?\d+$/)

class AddFocus extends CommandExecutor {

async execute({ send, data }, args) {
Expand All @@ -23,9 +25,9 @@ class AddFocus extends CommandExecutor {
}

if (!isGroup) {
const group_id = Number.parseInt(args[1])
if (!group_id) {
await send('不是一个有效的群ID')
const group_id = String(args[1])
if (!GROUP_REGEXP.test(group_id)) {
await send(`${group_id} 不是一个有效的群ID`)
return
}
data.group_id = group_id
Expand Down Expand Up @@ -84,9 +86,9 @@ class RemoveFocus extends CommandExecutor {
}

if (!isGroup) {
const group_id = Number.parseInt(args[1])
if (!group_id) {
await send('不是一个有效的群ID')
const group_id = String(args[1])
if (!GROUP_REGEXP.test(group_id)) {
await send(`${group_id} 不是一个有效的群ID`)
return
}
data.group_id = group_id
Expand Down Expand Up @@ -129,9 +131,9 @@ class Focusing extends CommandExecutor {
const focus_users = json?.blive?.focus_users ?? {}

if (data.message_type !== 'group') {
const group_id = Number.parseInt(args[0])
if (!group_id) {
await send('不是一个有效的群ID')
const group_id = String(args[0])
if (!GROUP_REGEXP.test(group_id)) {
await send(`${group_id} 不是一个有效的群ID`)
return
}
data.group_id = group_id
Expand Down
19 changes: 16 additions & 3 deletions src/commands/highlights.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const level = require('../el/cachedb')

const KEY_GROUP = 'highlight'
const KEY_PRIVATE = 'highlight_private'
const GROUP_REGEXP = new RegExp(/\d+[-]?\d+$/)

class AddUser extends CommandExecutor {

Expand Down Expand Up @@ -32,7 +33,11 @@ class AddUser extends CommandExecutor {
}

if (!is_group && args[1]) { // 不是群聊發送,但是有輸入 [群 id]
data.group_id = Number.parseInt(args[1])
data.group_id = String(args[1])
if (!GROUP_REGEXP.test(data.group_id)) {
await send(`${data.group_id} 不是一个有效的群ID`)
return
}
}

const group_id = data.group_id
Expand Down Expand Up @@ -94,7 +99,11 @@ class RemoveUser extends CommandExecutor {
}

if (!is_group && args[1]) { // 不是群聊發送,但是有輸入 [群 id]
data.group_id = Number.parseInt(args[1])
data.group_id = String(args[1])
if (!GROUP_REGEXP.test(data.group_id)) {
await send(`${data.group_id} 不是一个有效的群ID`)
return
}
}

const group_id = data.group_id
Expand Down Expand Up @@ -154,7 +163,11 @@ class HighLighting extends CommandExecutor {
const is_group = data.message_type === 'group'

if (!is_group && args[0]) {
data.group_id = Number.parseInt(args[0])
data.group_id = String(args[0])
if (!GROUP_REGEXP.test(data.group_id)) {
await send(`${data.group_id} 不是一个有效的群ID`)
return
}
}

const json = await storer.read()
Expand Down

0 comments on commit 55a6312

Please sign in to comment.