public async Task HandleMessageAsync(IMiraiHttpSession session, IFriendMessageEventArgs e)
        {
            if (!CheckPreconditions(e.Sender))
            {
                return;
            }
            LogHelper.WriteInfoLog($"收到来自{e.Sender.Id}的私聊消息");

            int  quoteId  = (e.Chain[0] as SourceMessage).Id;
            bool isHandle = await MessageHandler.HandleMesage(e.Chain.ToOnionsMessages(e.Sender.Id, e.Sender.Name), null, async outMsg =>
            {
                if (outMsg != null)
                {
                    int iRevokeTime = outMsg.RevokeTime;
                    var msg         = await outMsg.ToMiraiApiHttpMessages(session, UploadTarget.Friend);
                    _ = session.SendFriendMessageAsync(e.Sender.Id, msg, outMsg.Reply ? quoteId : null).ContinueWith(async sendedCallBack =>
                    {
                        if (iRevokeTime > 0)
                        {
                            await Task.Delay(1000 * iRevokeTime);
                            _ = session.RevokeMessageAsync(sendedCallBack.Result);
                        }
                    });
                }
            });

            e.BlockRemainingHandlers = isHandle;
        }
Beispiel #2
0
        public async Task HandleMessageAsync(IMiraiHttpSession session, IGroupMessageEventArgs e)
        {
            if (!CheckPreconditions(e.Sender))
            {
                return;
            }
            LogHelper.WriteInfoLog($"收到来自{e.Sender.Id}的群消息");

            int quoteId = (e.Chain[0] as SourceMessage).Id;

            for (int i = 0; i < e.Chain.Length; i++)
            {
                //获取@群名片
                if (e.Chain[i] is IAtMessage atMsg)
                {
                    IGroupMemberInfo[] groupMemberInfos = await session.GetGroupMemberListAsync(e.Sender.Group.Id);

                    IGroupMemberInfo targetQQ = groupMemberInfos.Where(m => m.Id == atMsg.Target).FirstOrDefault();
                    string           nickName = targetQQ?.Name;
                    e.Chain[i] = new AtMessage(atMsg.Target, nickName);
                }
            }

            bool isHandle = await MessageHandler.HandleMesage(e.Chain.ToOnionsMessages(e.Sender.Id, e.Sender.Name), e.Sender.Group.Id, async outMsg =>
            {
                if (outMsg != null)
                {
                    int iRevokeTime = outMsg.RevokeTime;
                    var msg         = await outMsg.ToMiraiApiHttpMessages(session, UploadTarget.Group);
                    _ = session.SendGroupMessageAsync(e.Sender.Group.Id, msg, outMsg.Reply ? quoteId : null).ContinueWith(async sendedCallBack =>
                    {
                        if (iRevokeTime > 0)
                        {
                            await Task.Delay(1000 * iRevokeTime);
                            _ = session.RevokeMessageAsync(sendedCallBack.Result);
                        }
                    });
                }
            });

            e.BlockRemainingHandlers = isHandle;
        }