From 3e99d7d03378c097d9002cca018cb50c5fe22b8e Mon Sep 17 00:00:00 2001 From: LamGC Date: Wed, 20 Apr 2022 16:35:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(example):=20=E4=BF=AE=E5=A4=8D=20Reply=20?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E6=9D=A1=E4=BB=B6=E4=B8=8D=E5=85=85=E5=88=86?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 由于条件判断不充分, 导致运行时可能会出现 NPE 的问题. --- .../net/lamgc/scalabot/simple/SayHelloExtension.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scalabot-ext-example/src/main/java/net/lamgc/scalabot/simple/SayHelloExtension.java b/scalabot-ext-example/src/main/java/net/lamgc/scalabot/simple/SayHelloExtension.java index 23c6375..b175f0c 100644 --- a/scalabot-ext-example/src/main/java/net/lamgc/scalabot/simple/SayHelloExtension.java +++ b/scalabot-ext-example/src/main/java/net/lamgc/scalabot/simple/SayHelloExtension.java @@ -37,11 +37,16 @@ public class SayHelloExtension implements AbilityExtension { */ public Ability test() { ReplyFlow botHello = ReplyFlow.builder(bot.db()) + .enableStats("say_hello") .action((bot, upd) -> bot.silent().send("What is u name?", upd.getMessage().getChatId())) - .onlyIf(update -> "hello".equalsIgnoreCase(update.getMessage().getText())) + .onlyIf(update -> update.hasMessage() + && update.getMessage().hasText() + && "hello".equalsIgnoreCase(update.getMessage().getText())) .next(Reply.of((bot, upd) -> bot.silent() .send("OK! You name is " + upd.getMessage().getText().substring("my name is ".length()), upd.getMessage().getChatId()), - upd -> upd.getMessage().getText().startsWith("my name is "))) + upd -> upd.hasMessage() + && upd.getMessage().hasText() + && upd.getMessage().getText().startsWith("my name is "))) .build(); return Ability.builder()