-
-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(common): enhance repeater config
- Loading branch information
Showing
4 changed files
with
59 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,55 @@ | ||
import { App } from 'koishi-test-utils' | ||
import repeater from '../src/repeater' | ||
import * as common from 'koishi-plugin-common' | ||
|
||
it.only('repeat', async () => { | ||
const app = new App() | ||
const session1 = app.session(123, 123) | ||
const app = new App() | ||
const session1 = app.session('123', '123') | ||
const session2 = app.session('456', '123') | ||
const session3 = app.session('789', '123') | ||
|
||
app.plugin(repeater, { | ||
onRepeat: ({ repeated, times }, message) => !repeated && times >= 2 ? message : '', | ||
}) | ||
const options: common.Config = {} | ||
app.plugin(common, options) | ||
|
||
await session1.shouldNotReply('foo') | ||
await session1.shouldReply('foo', 'foo') | ||
await session1.shouldNotReply('foo') | ||
await session1.shouldNotReply('foo') | ||
}) | ||
describe('Repeater', () => { | ||
beforeEach(async () => { | ||
options.onRepeat = null | ||
options.onInterrupt = null | ||
await session1.shouldNotReply('clear') | ||
}) | ||
|
||
it('interrupt', async () => { | ||
const app = new App() | ||
const session1 = app.session(123, 123) | ||
it('repeat (basic config)', async () => { | ||
options.onRepeat = { minTimes: 2 } | ||
|
||
app.plugin(repeater, { | ||
repeat: (_, times) => times >= 2, | ||
interrupt: (_, times) => times >= 4, | ||
repeatCheck: false, | ||
interruptCheck: false, | ||
await session1.shouldNotReply('foo') | ||
await session1.shouldReply('foo', 'foo') | ||
await session1.shouldNotReply('foo') | ||
await session1.shouldNotReply('foo') | ||
}) | ||
|
||
await session1.shouldNotReply('foo') | ||
await session1.shouldReply('foo', 'foo') | ||
await session1.shouldReply('foo', '打断复读!') | ||
}) | ||
|
||
it('repeat check', async () => { | ||
const app = new App() | ||
const session1 = app.session(123, 123) | ||
const session2 = app.session(456, 123) | ||
it('repeat check', async () => { | ||
options.onRepeat = ({ users }, { userId }) => users[userId] > 2 ? '在?为什么重复复读?' : '' | ||
|
||
app.plugin(repeater, { | ||
repeat: (_, times) => times >= 2, | ||
interrupt: false, | ||
repeatCheck: (_, times) => times >= 2, | ||
interruptCheck: false, | ||
await session1.shouldNotReply('foo') | ||
await session2.shouldNotReply('foo') | ||
await session3.shouldNotReply('foo') | ||
await session1.shouldNotReply('foo') | ||
await session1.shouldReply('foo', '在?为什么重复复读?') | ||
}) | ||
|
||
await session1.shouldNotReply('foo') | ||
await session1.shouldReply('foo', 'foo') | ||
await session2.shouldReply('foo', 'foo') | ||
await session2.shouldReply('foo', `[CQ:at,qq=${session2.userId}] 在?为什么重复复读?`) | ||
}) | ||
|
||
it('interrupt check', async () => { | ||
const app = new App() | ||
const session1 = app.session(123, 123) | ||
it('interrupt', async () => { | ||
options.onRepeat = ({ times }) => times >= 3 ? '打断复读!' : '' | ||
|
||
app.plugin(repeater, { | ||
repeat: (_, times) => times >= 2, | ||
interrupt: false, | ||
repeatCheck: false, | ||
interruptCheck: (_, times) => times >= 2, | ||
await session1.shouldNotReply('foo') | ||
await session2.shouldNotReply('foo') | ||
await session3.shouldReply('foo', '打断复读!') | ||
}) | ||
|
||
await session1.shouldNotReply('foo') | ||
await session1.shouldNotReply('bar') | ||
await session1.shouldReply('bar', 'bar') | ||
await session1.shouldReply('foo', `[CQ:at,qq=${session1.userId}] 在?为什么打断复读?`) | ||
it('interrupt check', async () => { | ||
options.onInterrupt = ({ times }) => times >= 2 ? '在?为什么打断复读?' : '' | ||
|
||
await session1.shouldNotReply('foo') | ||
await session2.shouldNotReply('bar') | ||
await session1.shouldNotReply('foo') | ||
await session2.shouldNotReply('foo') | ||
await session3.shouldReply('bar', '在?为什么打断复读?') | ||
}) | ||
}) |