fix(example): 修复 Reply 判断条件不充分的问题.

由于条件判断不充分, 导致运行时可能会出现 NPE 的问题.
This commit is contained in:
LamGC 2022-04-20 16:35:02 +08:00
parent 8131f41313
commit 3e99d7d033
Signed by: LamGC
GPG Key ID: 6C5AE2A913941E1D

View File

@ -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()