public Task HandleMessageAsync(IMiraiHttpSession session, IGroupMemberKickedEventArgs e) { if (!CheckPreconditions(e.Member) || !BotInfo.SendMemberBeKickedMessage) { return(Task.CompletedTask); } return(session.SendGroupMessageAsync(e.Member.Group.Id, ReplaceMessage(session.GetMessageChainBuilder(), BotInfo.MemberBeKickedMessage, e.Member, e.Operator))); }
private async Task SendPictureAsync2(IMiraiHttpSession session, string path) // 发图, 不同的是使用 IMessageChainBuilder 构造消息链 { IImageMessage msg = await session.UploadPictureAsync(UploadTarget.Group, path); Builders.IMessageChainBuilder builder = session.GetMessageChainBuilder(); builder.Add(msg); await session.SendGroupMessageAsync(0, builder); // 自己填群号, 一般由 IGroupMessageEventArgs 提供 }
public async Task HandleMessageAsync3(IMiraiHttpSession session, IFriendMessageEventArgs e) // 法3: 使用 params IMessageBase[] { Builders.IMessageChainBuilder builder = session.GetMessageChainBuilder(); builder.AddPlainMessage($"收到了来自{e.Sender.Name}({e.Sender.Remark})[{e.Sender.Id}]的私聊消息:{string.Join(null, (IEnumerable<IChatMessage>)e.Chain)}"); // / 好友昵称 / / 好友备注 / / 好友QQ号 / / 消息链 / // builder.AddPlainMessage("QAQ").AddPlainMessage("QwQ")/* .AddAtMessage(123456) etc... */; // 你甚至可以一开始 new MessageBuilder() 的时候就开始 Chaining await session.SendFriendMessageAsync(e.Sender.Id, builder); // 向消息来源群异步发送由以上chain表示的消息 e.BlockRemainingHandlers = false; // 不阻断消息传递。如需阻断请返回true }
public async Task HandleMessageAsync(IMiraiHttpSession session, IGroupMessageEventArgs e) // 法3: 使用 IMessageBuilder { IMessageChainBuilder builder = session.GetMessageChainBuilder(); builder.AddPlainMessage($"收到了来自{e.Sender.Name}[{e.Sender.Id}]{{{e.Sender.Permission}}}的群消息:{string.Join(null, (IEnumerable<IChatMessage>)e.Chain)}"); // / 发送者群名片 / / 发送者QQ号 / / 发送者在群内权限 / / 消息链 / // builder.AddPlainMessage("QAQ").AddPlainMessage("OvO")/* .AddAtMessage(123456) etc... */; await session.SendGroupMessageAsync(e.Sender.Group.Id, builder /*, plain2, /* etc... */); // 向消息来源群异步发送由以上chain表示的消息 // e.BlockRemainingHandlers = true; // 默认不阻断消息传递。如需阻断请删除注释 }