在持续会话中如何通过一个方法发送不同的文字内容 #107
Answered
by
ForteScarlet
yujumpjump
asked this question in
Q&A
-
涉及的编程语言Java 涉及的组件库mirai (QQ) 疑问描述我想通过持续会话进行聊天 ,不知道这么才能每次发送不同的话,然后发送到第三句话 就自动结束会话了 |
Beta Was this translation helpful? Give feedback.
Answered by
ForteScarlet
Mar 13, 2023
Replies: 2 comments 25 replies
-
https://simbot.forte.love/docs/basic/continuous-session 持续会话 如果 |
Beta Was this translation helpful? Give feedback.
25 replies
Answer selected by
ForteScarlet
-
@Override
@Async
public void persistentSessions(MiraiGroupMessageEvent miraiGroupMessageEvent, ContinuousSessionContext sessionContext){
String[] a = new String[]{"请输入举报时间","请输入处理此事件管理员id"};
List<String> list = new ArrayList<>();
LongID id = miraiGroupMessageEvent.getGroup().getId();
LongID authorId = miraiGroupMessageEvent.getAuthor().getId();
At at = new At(authorId);
Messages elements = Messages.toMessages(at,Text.of("请输入hmd 的id, 输入 取消 可以随时取消hmd的录入!"));
miraiGroupMessageEvent.sendAsync(elements);
final MessageContent message = sessionContext.waitingForNextMessage(miraiGroupMessageEvent.Key, (context, event) -> {
if(event.getGroup().getId().equals(id)&&event.getAuthor().getId().equals(authorId)){
list.add(event.getMessageContent().getPlainText());
if(b<0){
Messages elements2 = Messages.toMessages(at,Text.of("hmd录入完成! 后其可以通过命令进行hmd修改。"));
miraiGroupMessageEvent.sendAsync(elements2);
return true;
}
if(event.getMessageContent().getPlainText().contains("取消")){
Messages elements3 = Messages.toMessages(at,Text.of("已取消hmd的录入"));
miraiGroupMessageEvent.sendAsync(elements3);
return true;
}
miraiGroupMessageEvent.sendAsync(a[b]);
--b;
// 返回false一直回话
return false;
}
miraiGroupMessageEvent.sendAsync("请不要多人同时录入hmd !");
return true;
});
System.out.println(list);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://simbot.forte.love/docs/basic/continuous-session
持续会话
ContinuousSessionContext
的本质是允许在同一个监听函数中接收多个可能连续的事件。"每次发送不同的话" 根据实际业务逻辑正常send
不同的内容就是了。如果
ContinuousSessionContext
无法满足需求,则考虑自行保存"会话状态"实现"持续会话"功能。