Skip to content

Commit

Permalink
fix(common): fix feedback arg, remove deprecated blacklist
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Sep 11, 2020
1 parent 960e100 commit f3090bc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 32 deletions.
10 changes: 1 addition & 9 deletions packages/plugin-common/src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export interface HandlerOptions {
onFriend?: RequestHandler
onGroupAdd?: RequestHandler
onGroupInvite?: RequestHandler
blackList?: string[]
respondents?: Respondent[]
throttle?: ThrottleConfig | ThrottleConfig[]
welcome?: WelcomeMessage
Expand Down Expand Up @@ -50,14 +49,7 @@ export default function apply(ctx: App, options: HandlerOptions = {}) {
return result !== undefined && session.$bot.setGroupAddRequest(session.flag, session.subType, result)
})

const { blackList = [], respondents = [], welcome = defaultMessage } = options

blackList.length && ctx.prependMiddleware((session, next) => {
for (const word of blackList) {
if (session.message.includes(word)) return
}
return next()
})
const { respondents = [], welcome = defaultMessage } = options

respondents.length && ctx.middleware((session, next) => {
const message = simplify(session.message)
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-common/src/sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default function apply(ctx: Context, config: SenderConfig = {}) {

const interactions: Record<number, number> = {}

config.operator && ctx.command('feedback', '发送反馈信息给作者')
config.operator && ctx.command('feedback <message...>', '发送反馈信息给作者')
.userFields(['name', 'id'])
.action(async ({ session }, text) => {
if (!text) return '请输入要发送的文本。'
Expand Down
21 changes: 20 additions & 1 deletion packages/plugin-common/tests/handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,27 @@ import { fn } from 'jest-mock'
import { Meta } from 'koishi-core'
import { App } from 'koishi-test-utils'
import { sleep } from 'koishi-utils'
import {} from 'koishi-adapter-cqhttp'
import * as common from 'koishi-plugin-common'

const app = new App({ mockDatabase: true })
const options: common.Config = {}

const options: common.Config = {
respondents: [{
match: '挖坑一时爽',
reply: '填坑火葬场',
}, {
match: /^(.+)$/,
reply: (_, action) => `一直${action}一直爽`,
}],
}

const session = app.session(123)

app.plugin(common, options)

before(async () => {
await app.database.getUser(123, 3)
await app.database.getGroup(123, app.selfId)
})

Expand Down Expand Up @@ -125,6 +138,12 @@ describe('Common Handlers', () => {
expect(setGroupAddRequest.mock.calls).to.have.shape([['flag', 'invite', true]])
})

it('respondent', async () => {
await session.shouldReply('挖坑一时爽', '填坑火葬场')
await session.shouldReply('填坑一时爽', '一直填坑一直爽')
await session.shouldNotReply('填坑一直爽')
})

it('welcome', async () => {
sendGroupMsg.mockClear()
await receiveGroupIncrease(321, 456)
Expand Down
21 changes: 0 additions & 21 deletions packages/plugin-common/tests/respondent.spec.ts

This file was deleted.

0 comments on commit f3090bc

Please sign in to comment.