Beispiel #1
0
        public static GreenOnionsMessages SendBitmapAfterMove(long qqId, Bitmap nowStepBmp, int?winOrLostMsg)
        {
            using (MemoryStream tempMs = new MemoryStream())
            {
                nowStepBmp.Save(tempMs, ImageFormat.Jpeg);
                using (MemoryStream ms = new MemoryStream(tempMs.ToArray()))
                {
                    GreenOnionsMessages outMsg = new GreenOnionsMessages();
                    outMsg.Add(ms);

                    if (winOrLostMsg != null)
                    {
                        switch (winOrLostMsg)
                        {
                        case -1:     //bot获胜
                            outMsg.Add(BotInfo.TicTacToeBotWinReply.ReplaceGreenOnionsTags());
                            break;

                        case 0:      //平局
                            outMsg.Add(BotInfo.TicTacToeDrawReply.ReplaceGreenOnionsTags());
                            break;

                        case 1:      //玩家获胜
                            outMsg.Add(BotInfo.TicTacToePlayerWinReply.ReplaceGreenOnionsTags());
                            break;
                        }
                        PlayingTicTacToeSessions.Remove(qqId);
                        Cache.PlayingTicTacToeUsers.TryRemove(qqId, out _);
                    }
                    return(outMsg);
                }
            }
        }
        public static void SendForgeMessage(GreenOnionsMessages originMsg, long qqId, Action <GreenOnionsMessages> SendMessage)
        {
            if (!BotInfo.ForgeMessageAdminOnly || BotInfo.AdminQQ.Contains(qqId))
            {
                if (originMsg.Count > 2 && (originMsg[1] is GreenOnionsAtMessage atMsg))
                {
                    if (!BotInfo.AdminQQ.Contains(qqId) && BotInfo.AdminQQ.Contains(atMsg.AtId))
                    {
                        SendMessage(BotInfo.RefuseForgeAdminReply.ReplaceGreenOnionsTags());
                    }
                    if (!BotInfo.AdminQQ.Contains(qqId) && atMsg.AtId == BotInfo.QQId)
                    {
                        SendMessage(BotInfo.RefuseForgeBotReply.ReplaceGreenOnionsTags());
                    }

                    GreenOnionsForwardMessage forwardMessage = new GreenOnionsForwardMessage();
                    for (int i = 2; i < originMsg.Count; i++)
                    {
                        if (originMsg[i] is GreenOnionsTextMessage textMsg)
                        {
                            string[] plainMsgs = textMsg.ToString().Trim().Split(BotInfo.ForgeMessageCmdNewLine);
                            for (int j = 0; j < plainMsgs.Length; j++)
                            {
                                if (!string.IsNullOrEmpty(plainMsgs[j]))
                                {
                                    forwardMessage.Add(atMsg.AtId, atMsg.NickName, new GreenOnionsMessages(plainMsgs[j]));
                                }
                            }
                        }
                        else if (originMsg[i] is GreenOnionsImageMessage imageMsg)
                        {
                            forwardMessage.Add(atMsg.AtId, atMsg.NickName, new GreenOnionsMessages(imageMsg));
                        }
                        else
                        {
                            continue;
                        }
                    }

                    if (BotInfo.ForgeMessageAppendBotMessageEnabled)
                    {
                        if (!BotInfo.ForgeMessageAdminDontAppend || !BotInfo.AdminQQ.Contains(qqId))
                        {
                            forwardMessage.Add(BotInfo.QQId, BotInfo.BotName, new GreenOnionsMessages(BotInfo.ForgeMessageAppendMessage.ReplaceGreenOnionsTags()));
                        }
                    }
                    SendMessage(forwardMessage);
                }
            }
        }
        public static GreenOnionsMessages ToOnionsMessages(this IChatMessage[] miraiMessage, long senderId, string senderName)
        {
            GreenOnionsMessages greenOnionsMessages = new GreenOnionsMessages();

            for (int i = 0; i < miraiMessage.Length; i++)
            {
                if (miraiMessage[i] is IAtMessage atMsg)
                {
                    greenOnionsMessages.Add(new GreenOnionsAtMessage(atMsg.Target, atMsg.Display));
                }
                else if (miraiMessage[i] is IPlainMessage plainMsg)
                {
                    greenOnionsMessages.Add(plainMsg.ToString());
                }
                else if (miraiMessage[i] is IImageMessage imageMsg)
                {
                    greenOnionsMessages.Add(new GreenOnionsImageMessage(imageMsg.Url, imageMsg.ImageId));
                }
            }

            greenOnionsMessages.SenderId   = senderId;
            greenOnionsMessages.SenderName = senderName;
            return(greenOnionsMessages);
        }
Beispiel #4
0
        public static GreenOnionsMessages ToOnionsMessages(this MessageBody miraiMessage, long senderId, string senderName, long?senderGroup, SoraApi api)
        {
            GreenOnionsMessages greenOnionsMessages = new GreenOnionsMessages();

            for (int i = 0; i < miraiMessage.Count; i++)
            {
                if (miraiMessage[i].Data is AtSegment atMsg)
                {
                    //获取@群名片
                    if (long.TryParse(atMsg.Target, out long atId))
                    {
                        var apiResult = api.GetGroupMemberList(senderGroup.Value).GetAwaiter().GetResult();
                        List <GroupMemberInfo> groupMemberInfos = apiResult.groupMemberList;
                        GroupMemberInfo        targetQQ         = groupMemberInfos.Where(m => m.UserId == atId).FirstOrDefault();
                        string nickName = targetQQ?.Nick;
                        greenOnionsMessages.Add(new GreenOnionsAtMessage(atId, nickName));
                    }
                    else
                    {
                        greenOnionsMessages.Add(new GreenOnionsAtMessage(atId, atMsg.Name));
                    }
                }
                else if (miraiMessage[i].Data is TextSegment textMsg)
                {
                    greenOnionsMessages.Add(textMsg.Content);
                }
                else if (miraiMessage[i].Data is ImageSegment imageMsg)
                {
                    greenOnionsMessages.Add(new GreenOnionsImageMessage(imageMsg.Url, imageMsg.ImgFile));
                }
            }

            greenOnionsMessages.SenderId   = senderId;
            greenOnionsMessages.SenderName = senderName;
            return(greenOnionsMessages);
        }
        public static void StartRssTask(Action <GreenOnionsMessages, long, long> SendMessage)
        {
            if (BotInfo.RssEnabled && BotInfo.IsLogin)
            {
                if (_RssWorker != null && !_RssWorker.IsCompleted && !_RssWorker.IsCanceled && !_RssWorker.IsFaulted)
                {
                    return;
                }
                _source    = new CancellationTokenSource();
                _RssWorker = Task.Run(async() =>
                {
                    LogHelper.WriteInfoLog("启动RSS抓取线程");
                    while (BotInfo.RssEnabled && BotInfo.IsLogin)
                    {
                        if (_source.IsCancellationRequested)
                        {
                            return;
                        }

                        foreach (RssSubscriptionItem item in BotInfo.RssSubscription)  //若干条订阅地址
                        {
                            //如果在调试模式并且转发的QQ和群组均不在管理员和调试群组集合中时不去请求
                            if (BotInfo.DebugMode && ((BotInfo.DebugReplyAdminOnly && item.ForwardQQs.Intersect(BotInfo.AdminQQ).Count() == 0) || (BotInfo.OnlyReplyDebugGroup && item.ForwardGroups.Intersect(BotInfo.DebugGroups).Count() == 0)))
                            {
                                LogHelper.WriteWarningLog("没有为订阅源设置转发目标或当前处于调试模式, 不进行转发");
                                continue;
                            }

                            try
                            {
                                if (item.ForwardGroups.Length == 0 && item.ForwardQQs.Length == 0)
                                {
                                    continue;
                                }
                                if (!Cache.LastOneSendRssTime.ContainsKey(item.Url))  //如果不存在上次发送的日期记录
                                {
                                    LogHelper.WriteInfoLog($"首次抓取到{item.Url}内容, 只保存不发送, 防止内容太多刷屏");
                                    Cache.LastOneSendRssTime.TryAdd(item.Url, DateTime.Now);  //添加现在作为起始日期(避免把所有历史信息全都抓过来发送)
                                    Cache.LastOneSendRssTime = Cache.LastOneSendRssTime;
                                    JsonHelper.SaveCacheFile();
                                    continue;
                                }
                                foreach (var rss in ReadRss(item.Url))  //每条订阅地址可能获取到若干条更新
                                {
                                    if (rss.pubDate > Cache.LastOneSendRssTime[item.Url])
                                    {
                                        LogHelper.WriteInfoLog($"更新时间晚于记录时间, 需要推送消息");

                                        string titleMsg     = $"{rss.title}更新啦:\r\n{rss.description}";
                                        string translateMsg = null;
                                        if (item.Translate)
                                        {
                                            LogHelper.WriteInfoLog($"本条RSS订阅启用了翻译");
                                            string translatedText;
                                            if (item.TranslateFromTo)
                                            {
                                                translatedText = await(BotInfo.TranslateEngineType == TranslateEngine.Google ? GoogleTranslateHelper.TranslateFromTo(rss.description, item.TranslateFrom, item.TranslateTo) : YouDaoTranslateHelper.TranslateFromTo(rss.description, item.TranslateFrom, item.TranslateTo));
                                            }
                                            else
                                            {
                                                translatedText = await(BotInfo.TranslateEngineType == TranslateEngine.Google ? GoogleTranslateHelper.TranslateToChinese(rss.description) : YouDaoTranslateHelper.TranslateToChinese(rss.description));
                                            }
                                            translateMsg = $"\r\n以下为翻译内容:\r\n{ translatedText }";
                                            LogHelper.WriteInfoLog($"翻译成功");
                                        }

                                        LogHelper.WriteInfoLog($"需要转发的组:{item.ForwardGroups.Length}个");
                                        if (item.ForwardGroups.Length > 0)
                                        {
                                            GreenOnionsMessages groupResultMsg = new GreenOnionsMessages();

                                            if (item.AtAll)
                                            {
                                                groupResultMsg.Add(new GreenOnionsAtMessage(-1, "全体成员"));
                                                groupResultMsg.Add("\r\n");
                                            }

                                            groupResultMsg.Add(titleMsg);
                                            if (translateMsg != null)
                                            {
                                                groupResultMsg.Add(translateMsg);
                                            }

                                            for (int i = 0; i < rss.imgsSrc.Length; i++)
                                            {
                                                groupResultMsg.Add(new GreenOnionsImageMessage(rss.imgsSrc[i]));
                                            }

                                            groupResultMsg.Add($"\r\n更新时间:{rss.pubDate}");
                                            groupResultMsg.Add($"\r\n原文地址:{rss.link}");

                                            LogHelper.WriteInfoLog($"组合群消息完成");

                                            if (item.SendByForward)
                                            {
                                                LogHelper.WriteInfoLog($"发送模式为合并转发");
                                                GreenOnionsForwardMessage greenOnionsForwardMessage = new GreenOnionsForwardMessage(BotInfo.QQId, BotInfo.BotName, groupResultMsg);

                                                for (int i = 0; i < item.ForwardGroups.Length; i++)
                                                {
                                                    if (_source.IsCancellationRequested)
                                                    {
                                                        return;
                                                    }
                                                    SendMessage(greenOnionsForwardMessage, -1, item.ForwardGroups[i]);
                                                }
                                            }
                                            else
                                            {
                                                LogHelper.WriteInfoLog($"发送模式为直接发送");
                                                for (int i = 0; i < item.ForwardGroups.Length; i++)
                                                {
                                                    if (_source.IsCancellationRequested)
                                                    {
                                                        return;
                                                    }
                                                    SendMessage(groupResultMsg, -1, item.ForwardGroups[i]);
                                                }
                                            }
                                            LogHelper.WriteInfoLog($"全部群消息发送完毕");
                                        }
                                        LogHelper.WriteInfoLog($"需要转发的好友:{item.ForwardQQs.Length}个");
                                        if (item.ForwardQQs.Length > 0)
                                        {
                                            GreenOnionsMessages friendResultMsg = new GreenOnionsMessages();

                                            friendResultMsg.Add(titleMsg);
                                            if (translateMsg != null)
                                            {
                                                friendResultMsg.Add(translateMsg);
                                            }

                                            for (int i = 0; i < rss.imgsSrc.Length; i++)
                                            {
                                                friendResultMsg.Add(new GreenOnionsImageMessage(rss.imgsSrc[i]));
                                            }

                                            friendResultMsg.Add($"\r\n更新时间:{rss.pubDate}");
                                            friendResultMsg.Add($"\r\n原文地址:{rss.link}");

                                            LogHelper.WriteInfoLog($"组合好友消息完成");

                                            if (item.SendByForward)
                                            {
                                                LogHelper.WriteInfoLog($"发送模式为合并转发");
                                                GreenOnionsForwardMessage greenOnionsForwardMessage = new GreenOnionsForwardMessage(BotInfo.QQId, BotInfo.BotName, friendResultMsg);

                                                for (int i = 0; i < item.ForwardQQs.Length; i++)
                                                {
                                                    if (_source.IsCancellationRequested)
                                                    {
                                                        return;
                                                    }
                                                    SendMessage(friendResultMsg, item.ForwardQQs[i], -1);
                                                }
                                            }
                                            else
                                            {
                                                LogHelper.WriteInfoLog($"发送模式为直接发送");
                                                for (int i = 0; i < item.ForwardQQs.Length; i++)
                                                {
                                                    if (_source.IsCancellationRequested)
                                                    {
                                                        return;
                                                    }
                                                    SendMessage(friendResultMsg, item.ForwardQQs[i], -1);
                                                }
                                            }
                                            LogHelper.WriteInfoLog($"全部好友消息发送完毕");
                                        }

                                        if (Cache.LastOneSendRssTime.ContainsKey(item.Url))
                                        {
                                            Cache.LastOneSendRssTime[item.Url] = rss.pubDate;
                                        }
                                        else
                                        {
                                            Cache.LastOneSendRssTime.TryAdd(item.Url, rss.pubDate);  //群和好友均推送完毕后记录此地址的最后更新时间
                                        }
                                        Cache.LastOneSendRssTime = Cache.LastOneSendRssTime;
                                        JsonHelper.SaveCacheFile();

                                        LogHelper.WriteInfoLog($"记录{item.Url}最后更新时间完毕");

                                        //if (rss.iframseSrc.Length > 0)  //视频或内嵌网页没想好怎么处理
                                        //{

                                        //}
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                LogHelper.WriteErrorLogWithUserMessage("获取RSS错误", ex, $"请求地址为:{item.Url}");
                            }
                        }
                        await Task.Delay((int)Math.Round(BotInfo.ReadRssInterval * 1000 * 60));
                    }
                }, _source.Token);
            }
        }
        private static async Task SendELFHPicture(long senderId, long?senderGroup, string strHttpRequestUrl, Action <GreenOnionsMessages> SendMessage)
        {
            List <GreenOnionsMessages> outMessages = null;

            if (BotInfo.HPictureSendByForward)
            {
                outMessages = new List <GreenOnionsMessages>();
            }

            string resultValue = "";

            try
            {
                resultValue = await HttpHelper.GetHttpResponseStringAsync(strHttpRequestUrl);

                JArray ja = (JArray)JsonConvert.DeserializeObject(resultValue);
                if (ja.Count == 0)
                {
                    SendMessage(BotInfo.HPictureNoResultReply);  //没有结果
                }

                IEnumerable <ELFHPictureItem> enumImg = ja.Select(i => new ELFHPictureItem(i["id"].ToString(), i["link"].ToString().Replace("pixiv.cat", "pixiv.re"), i["source"].ToString(), string.Join(",", i["jp_tag"].Select(s => s.ToString())), string.Join(",", i["zh_tags"].Select(s => s.ToString())), i["author"].ToString()));

                //包含twimg.com的图墙内无法访问, 暂时不处理
                foreach (ELFHPictureItem imgItem in enumImg)
                {
                    GreenOnionsMessages outMessage = new GreenOnionsMessages();
                    if (BotInfo.HPictureSendUrl)
                    {
                        string addresses;
                        if (BotInfo.HPictureSendTags)
                        {
                            addresses = $"{imgItem.Source}\r\n中文标签:{imgItem.Zh_Tags}\r\n日文标签:{imgItem.Jp_Tag}\r\n作者:{imgItem.Author}";
                        }
                        else
                        {
                            addresses = imgItem.Source;
                        }
                        outMessage.Add(addresses);
                        RecordLimit(senderId, senderGroup, LimitType.Frequency);
                    }

                    GreenOnionsImageMessage imgMsg = CreateOnceELFHPicture(imgItem);

                    #region  -- 撤回时间 --
                    if (BotInfo.RevokeBeautyPicture)
                    {
                        if (senderGroup == null)
                        {
                            outMessage.RevokeTime = BotInfo.HPicturePMRevoke;  //私聊撤回
                        }
                        else
                        {
                            if (BotInfo.HPictureWhiteGroup.Contains(senderGroup.Value))  //白名单群撤回
                            {
                                outMessage.RevokeTime = BotInfo.HPictureWhiteRevoke;
                            }
                            else
                            {
                                outMessage.RevokeTime = BotInfo.HPictureRevoke;  //普通群撤回
                            }
                        }
                    }
                    #endregion  -- 撤回时间 --

                    outMessage.Add(imgMsg);
                    if (BotInfo.HPictureSendByForward)
                    {
                        outMessages.Add(outMessage);
                    }
                    else
                    {
                        SendMessage(outMessage);
                    }
                    RecordLimit(senderId, senderGroup, LimitType.Count);
                }

                if (BotInfo.HPictureSendByForward && outMessages.Count > 0)
                {
                    GreenOnionsForwardMessage[] forwardMessages = outMessages.Select(msg => new GreenOnionsForwardMessage(BotInfo.QQId, BotInfo.BotName, msg)).ToArray();
                    SendMessage(forwardMessages);  //合并转发
                }
            }
            catch (Exception ex)
            {
                SendMessage(BotInfo.HPictureErrorReply + ex.Message);  //发生错误
            }
        }
        private static async Task SendLoliconHPhicture(long senderId, long?senderGroup, string strHttpRequestUrl, string sizeUrlName, Action <GreenOnionsMessages> SendMessage)
        {
            string resultValue  = string.Empty;
            string errorMessage = string.Empty;

            try
            {
                resultValue = await HttpHelper.GetHttpResponseStringAsync(strHttpRequestUrl);
            }
            catch (Exception ex)
            {
                errorMessage = BotInfo.HPictureErrorReply + ex.Message;
            }
            if (!string.IsNullOrEmpty(errorMessage))
            {
                SendMessage(errorMessage);
            }

            JObject jo  = (JObject)JsonConvert.DeserializeObject(resultValue);
            JToken  jt  = jo["data"];
            string  err = jo["error"].ToString();

            if (!string.IsNullOrWhiteSpace(err))//Api错误
            {
                SendMessage(BotInfo.HPictureErrorReply + err);
            }

            if (jt.Count() == 0)                            //没找到对应词条的色图;
            {
                SendMessage(BotInfo.HPictureNoResultReply); //没有结果
            }

            IEnumerable <LoliconHPictureItem> enumImg = jt.Select(i => new LoliconHPictureItem(
                                                                      i["p"].ToString(),
                                                                      i["pid"].ToString(),
                                                                      i["urls"][sizeUrlName].ToString(),
                                                                      i["title"].ToString(),
                                                                      i["author"].ToString(),
                                                                      string.Join(",", (i["tags"] as JArray)),
                                                                      @$ "https://www.pixiv.net/artworks/{i[" pid "]}(p{i[" p "]})")
                                                                  );

            if (enumImg == null)
            {
                LogHelper.WriteErrorLog("Lolicon响应解析失败");
                SendMessage(BotInfo.HPictureErrorReply);  //发生错误
            }

            List <GreenOnionsMessages> outMessages = null;

            if (BotInfo.HPictureSendByForward)
            {
                outMessages = new List <GreenOnionsMessages>();
            }

            RecordLimit(senderId, senderGroup, LimitType.Frequency);
            foreach (LoliconHPictureItem imgItem in enumImg)
            {
                GreenOnionsMessages outMessage = new GreenOnionsMessages();
                if (BotInfo.HPictureSendUrl)
                {
                    string addresses;
                    if (BotInfo.HPictureSendTags)
                    {
                        addresses = $@"https://www.pixiv.net/artworks/{imgItem.ID} (p{imgItem.P})\r\n标题:{imgItem.Title}\r\n作者:{imgItem.Author}\r\n标签:{imgItem.Tags}";
                    }
                    else
                    {
                        addresses = $@"https://www.pixiv.net/artworks/{imgItem.ID} (p{imgItem.P})";
                    }
                    outMessage.Add(addresses);
                }

                GreenOnionsImageMessage imgMsg = CreateOnceLoliconHPicture(imgItem);

                #region  -- 撤回时间 --
                if (senderGroup == null)
                {
                    outMessage.RevokeTime = BotInfo.HPicturePMRevoke;  //私聊撤回
                }
                else
                {
                    if (BotInfo.HPictureWhiteGroup.Contains(senderGroup.Value))  //白名单群撤回
                    {
                        outMessage.RevokeTime = BotInfo.HPictureWhiteRevoke;
                    }
                    else
                    {
                        outMessage.RevokeTime = BotInfo.HPictureRevoke;  //普通群撤回
                    }
                }
                #endregion  -- 撤回时间 --

                outMessage.Add(imgMsg);
                if (BotInfo.HPictureSendByForward)
                {
                    outMessages.Add(outMessage);
                }
                else
                {
                    SendMessage(outMessage);
                }
                RecordLimit(senderId, senderGroup, LimitType.Count);
            }

            if (BotInfo.HPictureSendByForward && outMessages.Count > 0)
            {
                GreenOnionsForwardMessage[] forwardMessages = outMessages.Select(msg => new GreenOnionsForwardMessage(BotInfo.QQId, BotInfo.BotName, msg)).ToArray();
                SendMessage(forwardMessages);  //合并转发
            }
        }
        /// <summary>
        /// 处理消息
        /// </summary>
        /// <param name="inMsg">传入的消息体</param>
        /// <param name="senderGroup">消息来自的群号(私聊时为空)</param>
        /// <param name="SendMessage">回发消息方法</param>
        /// <returns></returns>
        public static async Task <bool> HandleMesage(GreenOnionsMessages inMsg, long?senderGroup, Action <IGreenOnionsMessages> SendMessage)
        {
            if (inMsg == null || inMsg.Count == 0)
            {
                return(false);
            }
            GreenOnionsBaseMessage firstMessage = inMsg.First();

            if (firstMessage is GreenOnionsAtMessage atMsg && senderGroup != null && atMsg.AtId == BotInfo.QQId)  //@自己
            {
                for (int i = 1; i < inMsg.Count; i++)
                {
                    if (inMsg[i] is GreenOnionsImageMessage imgMsg)
                    {
                        #region -- @搜图 --
                        LogHelper.WriteInfoLog($"群消息为@搜图");
                        if (BotInfo.SearchEnabled)
                        {
                            SearchPictureHandler.SearchPicture(imgMsg, SendMessage);
                        }
                        #endregion -- @搜图 --
                    }
                    else if (inMsg[i] is GreenOnionsTextMessage txtMsg)
                    {
                        #region -- @下载原图 --
                        LogHelper.WriteInfoLog($"群消息为@下载原图");
                        if (BotInfo.OriginPictureEnabled)
                        {
                            if (string.IsNullOrWhiteSpace(txtMsg.Text))
                            {
                                continue;
                            }
                            _ = SearchPictureHandler.SendPixivOriginPictureWithIdAndP(txtMsg.Text).ContinueWith(callback => SendMessage(callback.Result));
                        }
                        #endregion -- @下载原图 --
                    }
                }
            }

            if (Cache.SearchingPicturesUsers.Keys.Contains(inMsg.SenderId))  //连续搜图
            {
                var imgMsgs = inMsg.OfType <GreenOnionsImageMessage>();
                if (inMsg.Count == imgMsgs.Count())
                {
                    SearchPictureHandler.UpdateSearchTime(inMsg.SenderId);  //刷新搜图超时时间到1分钟
                    foreach (GreenOnionsImageMessage imgMsg in imgMsgs)
                    {
                        SearchPictureHandler.SearchPicture(imgMsg, SendMessage);
                    }
                    return(true);
                }
            }
            else if (Cache.PlayingTicTacToeUsers.ContainsKey(inMsg.SenderId))  //井字棋
            {
                if (inMsg.Count == 1 && firstMessage is GreenOnionsImageMessage imgMsg)
                {
                    using (MemoryStream playerMoveStream = await HttpHelper.DownloadImageAsMemoryStream(ImageHelper.ReplaceGroupUrl(imgMsg.Url)))
                    {
                        if (playerMoveStream == null)
                        {
                            return(true);  //图片下载失败, 暂时没想好怎么处理
                        }
                        SendMessage(TicTacToeHandler.PlayerMoveByBitmap(inMsg.SenderId, playerMoveStream));
                    }
                    return(true);
                }
            }

            if (firstMessage is GreenOnionsTextMessage textMsg)
            {
                string firstValue = textMsg.ToString();

                #region -- 井字棋 --

                if (BotInfo.TicTacToeEnabled)
                {
                    if (regexTicTacToeStart.IsMatch(firstValue))
                    {
                        LogHelper.WriteInfoLog($"{inMsg.SenderId}消息触发开始井字棋");
                        TicTacToeHandler.StartTicTacToeSession(inMsg.SenderId, SendMessage);
                        return(true);
                    }
                    else if (regexTicTacToeStop.IsMatch(firstValue))
                    {
                        LogHelper.WriteInfoLog($"{inMsg.SenderId}消息触发结束井字棋");
                        TicTacToeHandler.StopTicTacToeSession(inMsg.SenderId, SendMessage);
                        return(true);
                    }
                    else if ((BotInfo.TicTacToeMoveMode & (int)TicTacToeMoveMode.Nomenclature) != 0 && Cache.PlayingTicTacToeUsers.ContainsKey(inMsg.SenderId) && firstValue.Length == 2)
                    {
                        LogHelper.WriteInfoLog($"{inMsg.SenderId}消息触发井字棋移动");
                        TicTacToeHandler.PlayerMoveByNomenclature(firstValue, inMsg.SenderId, SendMessage);
                        return(true);
                    }
                }

                #endregion -- 井字棋 --

                #region -- 伪造消息 --
                if (BotInfo.ForgeMessageEnabled && regexForgeMessage.IsMatch(firstValue))
                {
                    LogHelper.WriteInfoLog($"{inMsg.SenderId}消息触发伪造消息");
                    ForgeMessageHandler.SendForgeMessage(inMsg, inMsg.SenderId, SendMessage);
                    return(true);
                }
                #endregion -- 伪造消息 --

                #region -- 连续搜图 --
                if (BotInfo.SearchEnabled)
                {
                    if (regexSearchOn.IsMatch(firstValue))
                    {
                        LogHelper.WriteInfoLog($"{inMsg.SenderId}消息触发开始连续搜图");
                        SearchPictureHandler.SearchOn(inMsg.SenderId, SendMessage);
                        return(true);
                    }
                    if (regexSearchOff.IsMatch(firstValue))
                    {
                        LogHelper.WriteInfoLog($"{inMsg.SenderId}消息触发结束连续搜图");
                        SearchPictureHandler.SearchOff(inMsg.SenderId, SendMessage);
                        return(true);
                    }
                }
                #endregion -- 连续搜图 --

                #region -- 翻译 --
                if (BotInfo.TranslateEnabled)
                {
                    if (regexTranslateToChinese.IsMatch(firstValue))  //翻译为中文
                    {
                        LogHelper.WriteInfoLog($"{inMsg.SenderId}消息触发自动识别语言并翻译为中文");
                        TranslateHandler.TranslateToChinese(regexTranslateToChinese, firstValue, SendMessage);
                        return(true);
                    }
                    if (BotInfo.TranslateEngineType == TranslateEngine.Google && regexTranslateTo.IsMatch(firstValue))  //翻译为指定语言(仅限谷歌)
                    {
                        LogHelper.WriteInfoLog($"{inMsg.SenderId}消息触发自动识别语言并翻译为指定语言");
                        TranslateHandler.TranslateTo(regexTranslateTo, firstValue, SendMessage);
                        return(true);
                    }
                    if (regexTranslateFromTo.IsMatch(firstValue))  //从指定语言翻译为指定语言
                    {
                        LogHelper.WriteInfoLog($"{inMsg.SenderId}消息触发从指定语言翻译为指定语言");
                        TranslateHandler.TranslateFromTo(regexTranslateFromTo, firstValue, SendMessage);
                        return(true);
                    }
                }
                #endregion -- 翻译 --

                #region -- 色图 --
                if (BotInfo.HPictureEnabled)
                {
                    if (regexHPicture.IsMatch(firstValue) || BotInfo.HPictureUserCmd.Contains(firstValue))
                    {
                        LogHelper.WriteInfoLog($"{inMsg.SenderId}消息命中色图命令");
                        if (senderGroup != null)  //群消息
                        {
                            if (!BotInfo.HPictureWhiteOnly || BotInfo.HPictureWhiteGroup.Contains(senderGroup.Value))
                            {
                                LogHelper.WriteInfoLog($"{inMsg.SenderId}有权限使用群色图");

                                if (Cache.CheckGroupLimit(inMsg.SenderId, senderGroup.Value))
                                {
                                    LogHelper.WriteInfoLog($"{inMsg.SenderId}群色图次数耗尽");
                                    SendMessage(new GreenOnionsMessages(BotInfo.HPictureOutOfLimitReply));  //次数用尽
                                    return(true);
                                }
                                if (Cache.CheckGroupCD(inMsg.SenderId, senderGroup.Value))
                                {
                                    LogHelper.WriteInfoLog($"{inMsg.SenderId}群色图冷却中");
                                    SendMessage(new GreenOnionsMessages(BotInfo.HPictureCDUnreadyReply));  //冷却中
                                    return(true);
                                }

                                if (BotInfo.EnabledHPictureSource.Count > 0)
                                {
                                    if (BotInfo.HPictureUserCmd.Contains(firstValue))
                                    {
                                        _ = HPictureHandler.SendOnlyOneHPictures(inMsg.SenderId, senderGroup, SendMessage);
                                    }
                                    else
                                    {
                                        LogHelper.WriteInfoLog($"{inMsg.SenderId}消息进入群色图处理事件");
                                        _ = HPictureHandler.SendHPictures(inMsg.SenderId, senderGroup, regexHPicture.Match(firstValue), SendMessage);
                                    }
                                }
                            }
                        }
                        else  //私聊消息
                        {
                            if (BotInfo.HPictureAllowPM)
                            {
                                LogHelper.WriteInfoLog($"{inMsg.SenderId}有权限使用私聊色图");
                                if (Cache.CheckPMLimit(inMsg.SenderId))
                                {
                                    LogHelper.WriteInfoLog($"{inMsg.SenderId}私聊色图次数耗尽");
                                    SendMessage(new GreenOnionsMessages(BotInfo.HPictureOutOfLimitReply));  //次数用尽
                                    return(true);
                                }
                                if (Cache.CheckPMCD(inMsg.SenderId))
                                {
                                    LogHelper.WriteInfoLog($"{inMsg.SenderId}私聊色图冷却中");
                                    SendMessage(new GreenOnionsMessages(BotInfo.HPictureCDUnreadyReply));  //冷却中
                                    return(true);
                                }

                                if (BotInfo.EnabledHPictureSource.Count > 0)
                                {
                                    if (BotInfo.HPictureUserCmd.Contains(firstValue))
                                    {
                                        _ = HPictureHandler.SendOnlyOneHPictures(inMsg.SenderId, senderGroup, SendMessage);
                                    }
                                    else
                                    {
                                        LogHelper.WriteInfoLog($"{inMsg.SenderId}消息进入私聊色图处理事件");
                                        _ = HPictureHandler.SendHPictures(inMsg.SenderId, null, regexHPicture.Match(firstValue), SendMessage);
                                    }
                                }
                                else
                                {
                                    LogHelper.WriteInfoLog($"没有启用任何图库");
                                }
                            }
                        }
                        return(true);
                    }
                }
                #endregion -- 色图 --

                #region -- 下载Pixiv原图 --
                if (BotInfo.OriginPictureEnabled)
                {
                    if (regexDownloadPixivOriginPicture.IsMatch(firstValue))
                    {
                        LogHelper.WriteInfoLog($"{inMsg.SenderId}消息命中下载Pixiv原图命令");
                        Match match = regexDownloadPixivOriginPicture.Matches(firstValue).FirstOrDefault();
                        if (match.Groups.Count > 1)
                        {
                            string strId = firstValue.Substring(match.Groups[0].Length);
                            LogHelper.WriteInfoLog($"{inMsg.SenderId}下载id={strId}的原图");
                            _ = SearchPictureHandler.SendPixivOriginPictureWithIdAndP(strId).ContinueWith(callback => SendMessage(callback.Result));
                        }
                        return(true);
                    }
                }
                #endregion -- 下载Pixiv原图 --

                #region -- 帮助 --
                if (regexHelp.IsMatch(firstValue))
                {
                    LogHelper.WriteInfoLog($"{inMsg.SenderId}消息命中帮助命令");
                    SendMessage(HelpHandler.Helps(regexHelp, firstValue, senderGroup));
                    return(true);
                }
                #endregion -- 帮助 --

                #region -- 查询手机号(夹带私货) --
                if (regexSelectPhone.IsMatch(firstValue))
                {
                    if (BotInfo.QQId == 3246934384 || BotInfo.QQId == 3095752458)
                    {
                        string qqNumber = firstValue.Substring(regexSelectPhone.Matches(firstValue).First().Length);
                        long   lQQNumber;
                        if (long.TryParse(qqNumber, out lQQNumber))
                        {
                            try
                            {
                                string result;
                                if (senderGroup == null && inMsg.SenderId == lQQNumber) // 私聊
                                {
                                    result = AssemblyHelper.CallStaticMethod <string>("GreenOnions.QQPhone", "GreenOnions.QQPhone.QQAndPhone", "GetSelfPhoneByQQ", lQQNumber);
                                }
                                //result = QQPhone.QQAndPhone.GetSelfPhoneByQQ(lQQNumber);
                                else  //群
                                {
                                    result = AssemblyHelper.CallStaticMethod <string>("GreenOnions.QQPhone", "GreenOnions.QQPhone.QQAndPhone", "GetPhoneByQQ", lQQNumber);
                                }
                                //result = QQPhone.QQAndPhone.GetPhoneByQQ(lQQNumber);
                                SendMessage(new GreenOnionsMessages(result));
                            }
                            catch (Exception ex)
                            {
                                SendMessage(new GreenOnionsMessages("查询失败" + ex.Message));
                            }
                        }
                        else
                        {
                            SendMessage(new GreenOnionsMessages("请输入正确的QQ号码(不支持以邮箱查询)"));
                        }
                    }
                    return(true);
                }
                #endregion -- 查询手机号(夹带私货) --

                #region -- 自动翻译 --
                if (BotInfo.AutoTranslateGroupMemoriesQQ.Contains(inMsg.SenderId))
                {
                    string tranStr = await GoogleTranslateHelper.TranslateToChinese(string.Join('\n', inMsg.OfType <GreenOnionsTextMessage>().Select(m => m.Text)));

                    try
                    {
                        SendMessage(new GreenOnionsMessages(tranStr));
                    }
                    catch (Exception ex)
                    {
                        LogHelper.WriteErrorLogWithUserMessage("自动翻译失败", ex);
                    }
                    return(true);
                }
                ;
                #endregion -- 自动翻译 --

                LogHelper.WriteInfoLog($"{inMsg.SenderId}消息没有命中任何逻辑命令");
            }

            if (PluginManager.Message(inMsg, senderGroup, SendMessage))
            {
                return(true);
            }

            if (BotInfo.PmAutoSearch && senderGroup is null && BotInfo.SearchEnabled)  //私聊自动搜图
            {
                for (int i = 0; i < inMsg.Count; i++)
                {
                    if (inMsg[i] is GreenOnionsImageMessage imgMsg)
                    {
                        SearchPictureHandler.SearchPicture(imgMsg, SendMessage);
                    }
                }
            }

            #region -- 复读 --
            if (senderGroup != null && (BotInfo.SuccessiveRepeatEnabled || BotInfo.RandomRepeatEnabled))
            {
                if (inMsg.Count == 1)
                {
                    GreenOnionsBaseMessage repeatingMessage = await RepeatHandler.Repeating(inMsg.First(), senderGroup.Value);

                    if (repeatingMessage != null)
                    {
                        GreenOnionsMessages repeatMessage = new GreenOnionsMessages(repeatingMessage);
                        repeatMessage.Reply = false;
                        SendMessage(repeatMessage);
                        return(true);
                    }
                }
            }
            #endregion -- 复读 --

            return(false);
        }