Skip to content

Commit 9e861b3

Browse files
update: 链式调用
1 parent 593ce67 commit 9e861b3

5 files changed

Lines changed: 146 additions & 151 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: V2.1.20
2+
title: V2.1.21
33
description: 写法简化
44
# slug: welcome-docusaurus-v2
55
authors: ningmengchongshui

docs/alemonjsDocs/basic/data-type.md

Lines changed: 136 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -18,206 +18,195 @@ sidebar_position: 5
1818
### Text
1919

2020
```ts title="src/response/**/*/res.ts"
21-
import { Text, useMessage } from 'alemonjs'
21+
import { useMessage } from 'alemonjs'
2222
export default event => {
2323
// 创建
2424
const [message] = useMessage(event)
25-
message.send(
26-
format(Text('这个'), Text('标题', { style: 'bold' }), Text('被加粗了'))
27-
)
28-
message.send(format(Text('这个'), Text('标题'), Text('没有变化')))
29-
message.send(
30-
format(
31-
Text(`// 我的代码块 \nconst Send = useSend(event)`, {
25+
26+
// ex 1
27+
message.send({
28+
format: Format.create().addText('标题', { style: 'bold' }), Text('被加粗了'))
29+
})
30+
31+
// ex 2
32+
message.send({
33+
format: Format.create().addText('这个').addText('标题').addText('没有变化')
34+
})
35+
36+
// ex 3
37+
message.send({
38+
format: Format.create().addText(`// 我的代码块 \nconst Send = useSend(event)`, {
3239
style: 'block'
3340
})
34-
)
35-
)
36-
}
41+
})
3742
```
3843
3944
### Image
4045
4146
```ts title="src/response/**/*/res.ts"
42-
import { useMessage, Image } from 'alemonjs'
47+
import { useMessage, Format } from 'alemonjs'
4348
import jpgURL from '@src/assets/test.jpeg'
4449
import { readFileSync } from 'node:fs'
50+
4551
export default event => {
4652
const [message] = useMessage(event)
47-
const { url, file } = Image
53+
4854
// file
49-
message.send(format(file(jpgURL)))
55+
message.send({
56+
format: Format.create().addImageFile(jpgURL)
57+
})
58+
5059
// url
51-
message.send(format(url('https://xxx.com/yyy.png')))
60+
message.send({
61+
format: Format.create().addImageURL('https://xxx.com/yyy.png')
62+
})
63+
5264
// buffer
5365
const img = readFileSync(jpgURL)
54-
message.send(format(Image(img)))
66+
message.send({
67+
format: Format.create().addImage(img)
68+
})
5569
}
5670
```
5771
5872
### Mention
5973
6074
```ts title="response/**/*/res.ts"
61-
import { useMessage, Text, Mention } from 'alemonjs'
75+
import { useMessage, Text, Mention, Format } from 'alemonjs'
6276
export default event => {
6377
const [message] = useMessage(event)
6478
// 发送多种类型的消息
65-
message.send(
66-
format(
67-
Text('Hello '),
68-
Mention(event.UserId),
69-
Text(', How are things going?')
70-
)
71-
)
72-
// @ 所有人
73-
message.send(format(Mention()))
79+
80+
message.send({
81+
format: Format.create()
82+
.addText('hello ')
83+
.addMention(event.UserId)
84+
.addText(', How are things going?')
85+
})
86+
87+
// @ all
88+
message.send({
89+
format: Format.create().addMention()
90+
})
91+
7492
// @ channel
75-
message.send(
76-
format(
77-
Mention(event.ChannelId, {
78-
belong: 'channel'
79-
})
80-
)
81-
)
93+
message.send({
94+
format: Format.create().addMention(event.ChannelId, {
95+
belong: 'channel'
96+
})
97+
})
8298
}
8399
```
84100
85101
### Button
86102
87103
```ts
88-
import { BT, useMessage } from 'alemonjs'
104+
import { useMessage, Format } from 'alemonjs'
105+
89106
export default event => {
90107
const [message] = useMessage(event)
91108

92-
const { group, row } = BT
93-
94109
// 一行多个
95-
message.send(
96-
format(group(row(BT('开始', '/开始游戏'), BT('结束', '/结束游戏'))))
97-
)
110+
message.send({
111+
format: Format.create().addButtonGroup(
112+
Format.create()
113+
.createButtonGroup()
114+
.addRow()
115+
.addButton('开始', '/开始游戏')
116+
.addButton('结束', '/结束游戏')
117+
)
118+
})
98119

99120
// 多行多个
100-
message.send(
101-
format(
102-
group(
103-
row(BT('开始', '/开始游戏'), BT('结束', '/结束游戏')),
104-
row(BT('退出', '/退出游戏'), BT('注销', '/注销账户'))
105-
)
121+
message.send({
122+
format: Format.create().addButtonGroup(
123+
Format.create()
124+
.createButtonGroup()
125+
.addRow()
126+
.addButton('开始', '/开始游戏')
127+
.addButton('结束', '/结束游戏')
128+
.addRow()
129+
.addButton('退出', '/退出游戏')
130+
.addButton('注销', '/注销账户')
106131
)
107-
)
132+
})
108133

109134
// 更多类型
110-
message.send(
111-
format(
112-
group(
113-
// link
114-
row(
115-
BT('访问文档', 'https://alemonjs.com/', {
116-
type: 'link'
117-
})
118-
),
119-
row(
120-
BT('是否同意', '/同意', {
121-
type: 'call'
122-
})
123-
),
124-
// 自动发送 + 显示字频道list + 禁用提示
125-
row(
126-
BT('哈哈', '/哈哈', {
127-
autoEnter: false,
128-
showList: true,
129-
toolTip: '不支持'
130-
})
131-
)
132-
)
133-
)
135+
const format = Format.create()
136+
format.addButtonGroup(
137+
format
138+
.createButtonGroup()
139+
// link
140+
.addRow()
141+
.addButton('访问文档', 'https://alemonjs.com/', { type: 'link' })
142+
// call
143+
.addRow()
144+
.addButton('是否同意', '/同意', { type: 'call' })
145+
// 自动发送 + 显示子频道list + 禁用提示
146+
.addRow()
147+
.addButton('哈哈', '/哈哈', {
148+
autoEnter: false,
149+
showList: true,
150+
toolTip: '不支持'
151+
})
134152
)
135-
136-
const { template } = BT
137-
138-
// 使用申请好的模板(特定平台下使用)
139-
message.send(format(template('template_id')))
140-
141-
// 向申请的模板注入参数
142-
message.send(format(template('template_id')))
153+
message.send({ format })
143154
}
144155
```
145156
146157
### MarkDown
147158
148159
```ts
149-
import { MD, useMessage } from 'alemonjs'
160+
import { useMessage, Format } from 'alemonjs'
161+
150162
export default event => {
151163
const [message] = useMessage(event)
152164

153-
const {
154-
text,
155-
title,
156-
bold,
157-
italicStar,
158-
strikethrough,
159-
link,
160-
image,
161-
list,
162-
listItem,
163-
blockquote,
164-
divider,
165-
newline
166-
} = MD
167-
168-
message.send(
169-
format(
170-
MD(
171-
// 标题
172-
title('标题!!'),
173-
// 副标题
174-
subtitle('子标题'),
175-
text('普通文本'),
176-
// 加粗
177-
bold('加粗'),
178-
// 斜体
179-
italic('斜体'),
180-
// 星号斜体
181-
italicStar('星号斜体'),
182-
// 删除线
183-
strikethrough('删除线'),
184-
// 链接
185-
link('链接', 'https://www.baidu.com'),
186-
// 图片
187-
image('https://www.baidu.com/img/bd_logo1.png', {
188-
width: 100,
189-
height: 100
190-
}),
191-
// 有序列表
192-
list(
193-
listItem(1, '有序列表'),
194-
listItem(2, '有序列表'),
195-
listItem(3, '有序列表'),
196-
listItem(4, '有序列表')
197-
),
198-
// 无序列表
199-
list(
200-
listItem('无序列表'),
201-
listItem('无序列表'),
202-
listItem('无序列表'),
203-
listItem('无序列表'),
204-
listItem('无序列表')
205-
),
206-
// 块引用
207-
blockquote('块引用'),
208-
// 水平分割线
209-
divider(),
210-
// 换行
211-
newline(),
212-
// 换多行
213-
newline(true)
214-
)
165+
const format = Format.create()
166+
const md = format.createMarkdown()
167+
168+
md
169+
// 标题
170+
.addTitle('标题!!')
171+
// 副标题
172+
.addSubtitle('子标题')
173+
// 普通文本
174+
.addText('普通文本')
175+
// 加粗
176+
.addBold('加粗')
177+
// 斜体
178+
.addItalic('斜体')
179+
// 星号斜体
180+
.addItalicStar('星号斜体')
181+
// 删除线
182+
.addStrikethrough('删除线')
183+
// 链接
184+
.addLink('链接', 'https://www.baidu.com')
185+
// 图片
186+
.addImage('https://www.baidu.com/img/bd_logo1.png', {
187+
width: 100,
188+
height: 100
189+
})
190+
// 有序列表
191+
.addList(
192+
{ index: 1, text: '有序列表' },
193+
{ index: 2, text: '有序列表' },
194+
{ index: 3, text: '有序列表' },
195+
{ index: 4, text: '有序列表' }
215196
)
216-
)
217-
218-
const { template } = MD
219-
220-
// 向申请的模板注入参数
221-
message.send(format(template('template_id', { title: '你好' })))
197+
// 无序列表
198+
.addList('无序列表', '无序列表', '无序列表', '无序列表', '无序列表')
199+
// 块引用
200+
.addBlockquote('块引用')
201+
// 水平分割线
202+
.addDivider()
203+
// 换行
204+
.addNewline()
205+
// 换多行
206+
.addNewline(true)
207+
208+
format.addMarkdown(md)
209+
210+
message.send({ format })
222211
}
223212
```

docs/alemonjsDocs/basic/response.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export default (e, next) => {
3030
})
3131
// 事件不匹配。或...
3232
if (!event.selects || !event.regular || !event.prefix || !event.exact) {
33+
// 交给下一个进行处理
3334
next()
3435
return
3536
}

docs/alemonjsDocs/basic/route.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ sidebar_position: 2
77

88
## defineRouter
99

10+
- 确定优先级
11+
- 利用中间件,统一处理一类响应
12+
13+
- 更早的确认是否执行,方便懒加载
14+
1015
```ts title="src/router.ts"
1116
import { lazy, defineRouter } from 'alemonjs'
1217
export default defineRouter([

docs/start.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ start({
7373
```js title="lib/index.js"
7474
import {
7575
defineChildren,
76-
defineRoute,
76+
defineRouter,
7777
logger,
7878
useMessage,
7979
Format
@@ -89,7 +89,7 @@ const response = e => {
8989
}
9090

9191
// 设置路由规则
92-
const responseRoute = defineRoute([
92+
const responseRouter = defineRouter([
9393
{
9494
regular: /^(\/|#)?hello$/,
9595
handler: () => response
@@ -100,7 +100,7 @@ export default defineChildren({
100100
// 注册内容
101101
register() {
102102
return {
103-
responseRoute
103+
responseRouter
104104
}
105105
},
106106
// 当注册完成时

0 commit comments

Comments
 (0)