Skip to content

Commit 3e99d7d

Browse files
committed
fix(example): 修复 Reply 判断条件不充分的问题.
由于条件判断不充分, 导致运行时可能会出现 NPE 的问题.
1 parent 8131f41 commit 3e99d7d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

scalabot-ext-example/src/main/java/net/lamgc/scalabot/simple/SayHelloExtension.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,16 @@ public Ability sayHello() {
3737
*/
3838
public Ability test() {
3939
ReplyFlow botHello = ReplyFlow.builder(bot.db())
40+
.enableStats("say_hello")
4041
.action((bot, upd) -> bot.silent().send("What is u name?", upd.getMessage().getChatId()))
41-
.onlyIf(update -> "hello".equalsIgnoreCase(update.getMessage().getText()))
42+
.onlyIf(update -> update.hasMessage()
43+
&& update.getMessage().hasText()
44+
&& "hello".equalsIgnoreCase(update.getMessage().getText()))
4245
.next(Reply.of((bot, upd) -> bot.silent()
4346
.send("OK! You name is " + upd.getMessage().getText().substring("my name is ".length()), upd.getMessage().getChatId()),
44-
upd -> upd.getMessage().getText().startsWith("my name is ")))
47+
upd -> upd.hasMessage()
48+
&& upd.getMessage().hasText()
49+
&& upd.getMessage().getText().startsWith("my name is ")))
4550
.build();
4651

4752
return Ability.builder()

0 commit comments

Comments
 (0)