mirror of
https://github.com/LamGC/ScalaBot.git
synced 2025-04-29 22:27:31 +00:00
fix(example): 修复 Reply 判断条件不充分的问题.
由于条件判断不充分, 导致运行时可能会出现 NPE 的问题.
This commit is contained in:
parent
8131f41313
commit
3e99d7d033
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user