Skip to main content

V2.0.0-rc.81

· 2 min read
Co-creator of yunzaijs 1
ProjectStatusDescription
alemonjsalemonjs-s机器人模块
  • useState

声明res/mw的状态,可用于管理是否启用

apps/**/*/res.ts
export name = 'login'
export const regular = /^(#|\/)?login$/
export default OnResponse((event, next) => {
// login code ...
}, 'message.create')
apps/**/*/res.ts
import { Text, useSend, useState } from 'alemonjs'
export const regular = /^(#|\/)?close:/
export default OnResponse((event, next) => {
// /close:login
const name = event.MessageText.replace(regular, '')
const [state, setState] = useState(name)
if (state) {
next()
return
}
setState(false)
const Send = useSend(event)
Send(Text('关闭成功'))
return
}, 'message.create')

可以在任意地方订阅状态的更改。

apps/**/*/res.ts
import { eventState, unEventState } from 'alemonjs'

const login = state => {}

eventState('login', login)
unEventState('login', login)
  • 分组

复用逻辑,共用一个next

const Res = OnResponse((event, next) => {
console.log('text', event.MessageText)
// 允许在同组响应中,继续后续的函数
return true
}, 'message.create')

export default OnResponse(
[
// add
Res.current,
(event, next) => {
console.log('完成')
}
],
'message.create'
)