@@ -58,7 +58,7 @@ fun emitSpringShowcases(
5858 resources.file(" application.yml" , genSpringApplicationConfig())
5959}
6060
61- fun genSpringMainFile (
61+ fun genKotlinSpringMainFile (
6262 name : String ,
6363 projectPackage : String
6464): KotlinFile {
@@ -82,43 +82,24 @@ fun genSpringMainFile(
8282 }
8383 }
8484
85- // val mainFile = fileSpec(projectPackage, name) {
86- // // Main Application class
87- // addClass(name) {
88- // val simbotAno = ClassName("love.forte.simbot.spring", "EnableSimbot")
89- // addAnnotation(simbotAno)
90- // addAnnotation(ClassName("org.springframework.boot.autoconfigure", "SpringBootApplication"))
91- // addKdoc("Spring程序的入口注解类。添加 [%T] 注解来标记启用 simbot 相关的功能。", simbotAno)
92- // }
93- //
94- // // Main function
95- // addFunction("main") {
96- // addParameter("args", ARRAY.parameterizedBy(STRING))
97- // val ram = MemberName("org.springframework.boot", "runApplication")
98- // addStatement("%M<%L>(*args)", ram, name)
99- // }
100- //
101- // }
102-
10385 return mainFile
10486}
10587
10688fun emitSpringMainFile (
10789 projectPackage : String ,
10890 sourceSets : JSZip
10991) {
110- val file = genSpringMainFile(projectPackage, " MainApplication" )
92+ val file = genKotlinSpringMainFile( " MainApplication" , projectPackage )
11193 sourceSets.file(file.toRelativePath(), file.writeToKotlinString())
11294}
11395
114- fun genSpringListenerShowcases (
96+ fun genKotlinSpringListenerShowcases (
11597 projectPackage : String ,
11698 components : Collection <SimbotComponent >
11799): KotlinFile {
118100 var showcaseCount = 1
119101 val handlePackage = " $projectPackage .handle"
120102
121- // TODO
122103 val myHandleFile = KotlinFile (handlePackage) {
123104 // Text + Message
124105 addStaticImport(" love.forte.simbot.message.plus" )
@@ -186,10 +167,10 @@ fun genSpringListenerShowcases(
186167
187168 addParameter(" event" , SimbotNames .contactMsgEventClassName)
188169 addComment(" 基于事件回复一句\" 你好\" " )
189- addStatement(" event.reply(%S )" , CodePart .string(" 你好" ))
170+ addStatement(" event.reply(%V )" , CodePart .string(" 你好" ))
190171 addStatement(" " )
191172 addComment(" 或直接根据 content 发送一句\" 你又好\" " )
192- addStatement(" event.content().send(%S )" , CodePart .string(" 你又好" ))
173+ addStatement(" event.content().send(%V )" , CodePart .string(" 你又好" ))
193174 addStatement(" " )
194175 addComment(" 可以发送文本(字符串)、消息元素/消息链和事件中的消息正文。" )
195176 addStatement(" " )
@@ -200,8 +181,8 @@ fun genSpringListenerShowcases(
200181 addComment(" 更多有关消息链和可用的消息元素,请参考文档:" )
201182 addComment(" https://simbot.forte.love/basic-messages.html" )
202183 addStatement(
203- " val messages = %M { %S } + " +
204- " %M(%S ).%M ()"
184+ " val messages = %V { %V } + " +
185+ " %V(%V ).%V ()"
205186 ) {
206187 emitType(MemberName (" love.forte.simbot.message" , " Text" ))
207188 emitString(" 图片: " )
@@ -214,95 +195,6 @@ fun genSpringListenerShowcases(
214195 }
215196 }
216197
217- // val myHandleFile = fileSpec(handlePackage, "MyEventHandles") {
218- // addClass("MyEventHandles") {
219- // // addAnnotation(componentAno)
220- // // addKdoc("一个用于承载监听函数的事件处理器类。\n\n")
221- // // addKdoc("将它标记为 [%T] 以交由Spring进行管理,\n", componentAno)
222- // // addKdoc("simbot-spring 会解析其中标记了 [%T] 的函数们。", listenerAno)
223- // //
224- // // // 1, 监听所有事件,然后控制台输出
225- // // addFunction("handleAllAndPrint") {
226- // // addAnnotation(listenerAno)
227- // // addModifiers(KModifier.SUSPEND)
228- // // addKdoc("示例${showcaseCount++}: 监听所有的事件,然后将它们输出到控制台。\n\n")
229- // // addKdoc("@param event 你要监听的事件的类型。\n")
230- // // addKdoc("必须是一个 [%T] 类型的子类", eventClassName)
231- // //
232- // // addParameter("event", eventClassName)
233- // // addStatement("println(%P)", "收到事件: \$event")
234- // // }
235- // //
236- // // // 2, 过滤消息事件
237- // // addFunction("handleMessageEvent") {
238- // // addAnnotation(listenerAno)
239- // // addAnnotation(AnnotationSpec.builder(filterAno).apply {
240- // // addMember("%S", "你好.*")
241- // // }.build())
242- // // addAnnotation(contentTrimAno)
243- // // addModifiers(KModifier.SUSPEND)
244- // // addKdoc("示例${showcaseCount++}: 监听所有 **文本内容** 开头为 `\"你好\"` 的消息事件,\n")
245- // // addKdoc("然后在控制台输出它的消息链内容。\n\n")
246- // // addKdoc("这里通过 [%T] 来以注解的风格便捷的匹配消息内容并过滤, \n", filterAno)
247- // // addKdoc("并配合使用 [%T] 在匹配前优先处理掉匹配文本的前后空字符,避免匹配失效。\n", contentTrimAno)
248- // //
249- // // addParameter("event", msgEventClassName)
250- // // addStatement("println(%P)", "收到消息事件: \$event")
251- // // addStatement("")
252- // //
253- // // addCode(CodeBlock.builder().apply {
254- // // inControlFlow("for·((index,·element)·in·event.messageContent.messages.withIndex())") {
255- // // addStatement("println(%P)", "\\t消息元素[\$index]: \$element")
256- // // }
257- // // }.build())
258- // // }
259- // //
260- // // // 3, 组件专属
261- // // // 挑其中一个组件
262- // // val oneOfComponent = components.firstOrNull()
263- // // if (oneOfComponent != null) {
264- // // addFunction(componentShowcase(showcaseCount++, oneOfComponent))
265- // // }
266- //
267- // // 4, 回复消息
268- // addFunction("handleAndReply") {
269- // addAnnotation(listenerAno)
270- // addModifiers(KModifier.SUSPEND)
271- //
272- // addKdoc("示例${showcaseCount++}: 监听所有 **文本内容** 开头为 `\"你好\"` 的消息事件,\n")
273- //
274- // addParameter("event", contactMsgEventClassName)
275- // addComment("基于事件回复一句\"你好\"")
276- // addStatement("event.reply(%S)", "你好")
277- // addStatement("")
278- // addComment("或直接根据 content 发送一句\"你好\"")
279- // addStatement("event.content().send(%S)", "你好")
280- // addStatement("")
281- // addComment("可以发送文本(字符串)、消息元素/消息链和事件中的消息正文。")
282- // addStatement("")
283- //
284- // addComment("下面的示例是发送一个消息链,其中包括一个文字消息和一个图片, ")
285- // addComment("它们二者直接使用 + 拼接。")
286- // addComment("你也可以使用 buildMessages { ... } 来构建消息链。")
287- // addComment("更多有关消息链和可用的消息元素,请参考文档:")
288- // addComment("https://simbot.forte.love/basic-messages.html")
289- // addStatement(
290- // "val messages = %M { %S } + " +
291- // "%M(%S).%M()",
292- // MemberName("love.forte.simbot.message", "Text"),
293- // "图片: ",
294- // MemberName("kotlin.io.path", "Path"),
295- // "image.png",
296- // MemberName("love.forte.simbot.message.OfflinePathImage.Companion", "toOfflineImage")
297- // )
298- // addStatement("event.reply(messages)")
299- // }
300- //
301- // // Text + Image 消息拼接的操作符
302- // addImport("love.forte.simbot.message", "plus")
303- // }
304- // }
305-
306198 return myHandleFile
307199}
308200
@@ -364,7 +256,7 @@ fun emitSpringListenerShowcases(
364256 components : Collection <SimbotComponent >,
365257 sourceSets : JSZip
366258) {
367- val file = genSpringListenerShowcases (projectPackage, components)
259+ val file = genKotlinSpringListenerShowcases (projectPackage, components)
368260 sourceSets.file(file.toRelativePath(), file.writeToKotlinString())
369261}
370262
0 commit comments