Exemple #1
0
 public async Task <bool> FriendMessage(MiraiHttpSession session, IFriendMessageEventArgs e)
 {
     try
     {
         if (e.Chain.Length > 1)
         {
             bool            isReply = false, isAtSource = false;
             IMessageBuilder builder = new MessageBuilder();
             ReplyMessage(e.Chain, builder, e.Sender.Id, ref isReply);
             if (isReply)        //是否回复消息
             {
                 if (isAtSource) //是否@消息源
                 {
                     await session.SendFriendMessageAsync(e.Sender.Id, builder, Convert.ToInt32(e.Chain[0].ToString()));
                 }
                 else
                 {
                     await session.SendFriendMessageAsync(e.Sender.Id, builder);
                 }
             }
         }
     }
     catch
     {
     }
     return(false);
 }
Exemple #2
0
 public static bool AddAccount(User user)
 {
     if (queue == null)
     {
         queue = new Dictionary <long, User>();
     }
     lock (queue)
     {
         if (queue.ContainsKey(user.qq))
         {
             session.SendFriendMessageAsync(user.qq,
                                            new PlainMessage("⚠一个QQ只能绑定一个学号,您已经有登录过的自动签到任务了。\n" +
                                                             "如有疑问请联系QQ:1250542735"));
             return(false);
         }
         user.cli = new NJITSignHelper.SignMsgLib.Client(new NJITSignHelper.SignMsgLib.Client.ClientInfo()
         {
             SystemName    = "Android",
             SystemVersion = "10",
             AppVersion    = "8.2.17",
             DeviceModel   = "Peach X",
             DeviceId      = Guid.NewGuid(),//生成新的硬件ID
         }, user.account)
         {
             //lastUpdate = Now()
         };
         queue.Add(user.qq, user);
         Save();
         return(true);
     }
 }
Exemple #3
0
        internal static async Task <int> CommonSendMessage(long id, bool isGroup, IMessageBase[] chain, int?quote)
        {
            if (!MiddlewareCore.OnSend(ref id, ref isGroup, ref chain, ref quote))
            {
                return(0);
            }

            if (isGroup)
            {
                return(await session.SendGroupMessageAsync(id, chain, quote));
            }
            else
            {
                if (BotInfo.HasFriend(id))
                {
                    return(await session.SendFriendMessageAsync(id, chain, quote));
                }
                int    msgid    = 0;
                long[] tempPath = BotInfo.GetTempPath(id);
                foreach (var t in tempPath)
                {
                    try
                    {
                        msgid = await session.SendTempMessageAsync(id, t, chain, quote);

                        break;
                    }
                    catch { }
                }
                return(msgid);
            }
        }
        public async void DoHandleAsync(MiraiHttpSession session, IMessageBase[] chain, IBaseInfo info, bool isGroupMessage = true)
        {
            ChineseLunisolarCalendar calendar = new ChineseLunisolarCalendar();
            var now          = DateTime.Now;
            var year         = calendar.GetYear(now);
            var month        = calendar.GetMonth(now);
            var day          = calendar.GetDayOfMonth(now);
            var hasLeapMonth = calendar.GetLeapMonth(year) > 0;

            if (hasLeapMonth)
            {
                if (month < 13 && day < 23)
                {
                    if (month > 1 && day > 15)
                    {
                        return;
                    }
                }
            }
            else
            {
                if (month < 12 && day < 23)
                {
                    if (month > 1 && day > 15)
                    {
                        return;
                    }
                }
            }
            List <IMessageBase> result = new List <IMessageBase>();
            IMessageBase        img    = null;

            switch (chain.First(m => m.Type == "Plain").ToString())
            {
            case "新年快乐":
                img = await session.UploadPictureAsync(UploadTarget.Group, "Resources\\NewYear\\NewYearStick.png");

                result.Add(img);
                break;

            case "新年抽签":
                string[] lotterise = Directory.GetFiles("Resources\\Lottery");
                img = await session.UploadPictureAsync(UploadTarget.Group, lotterise[randomer.Next(0, lotterise.Length - 1)]);

                result.Add(img);
                break;

            default:
                break;
            }
            if (isGroupMessage)
            {
                await session.SendGroupMessageAsync(((IGroupMemberInfo)info).Group.Id, result.ToArray());
            }
            else
            {
                await session.SendFriendMessageAsync(info.Id, result.ToArray());
            }
        }
        public async Task <bool> FriendMessage2(MiraiHttpSession session, IFriendMessageEventArgs e) // 法2: 使用 params IMessageBase[]
        {
            IMessageBase plain1 = new PlainMessage($"收到了来自{e.Sender.Name}({e.Sender.Remark})[{e.Sender.Id}]的私聊消息:{string.Join(null, (IEnumerable<IMessageBase>)e.Chain)}");
            //                                                /   好友昵称  /  /    好友备注    /  /  好友QQ号  /                                                        / 消息链 /
            IMessageBase plain2 = new PlainMessage("嘤嘤嘤");                                      // 在下边的 SendFriendMessageAsync, 你可以串起n个 IMessageBase
            await session.SendFriendMessageAsync(e.Sender.Id, plain1 /*, plain2, /* etc... */); // 向消息来源好友异步发送由以上chain表示的消息

            return(false);                                                                      // 不阻断消息传递。如需阻断请返回true
        }
        public async Task <bool> FriendMessage(MiraiHttpSession session, IFriendMessageEventArgs e)
        {
            IMessageBase[] chain = new IMessageBase[]
            {
                new PlainMessage($"收到了来自{e.Sender.Name}({e.Sender.Remark})[{e.Sender.Id}]的私聊消息:{string.Join(null, (IEnumerable<IMessageBase>)e.Chain)}")
                //                          /   好友昵称  /  /    好友备注    /  /  好友QQ号  /                                                        / 消息链 /
            };
            await session.SendFriendMessageAsync(e.Sender.Id, chain); // 向消息来源好友异步发送由以上chain表示的消息

            return(false);                                            // 不阻断消息传递。如需阻断请返回true
        }
        public async Task <bool> FriendMessage3(MiraiHttpSession session, IFriendMessageEventArgs e) // 法3: 使用 params IMessageBase[]
        {
            IMessageBuilder builder = new MessageBuilder();

            builder.AddPlainMessage($"收到了来自{e.Sender.Name}({e.Sender.Remark})[{e.Sender.Id}]的私聊消息:{string.Join(null, (IEnumerable<IMessageBase>)e.Chain)}");
            //                                 /   好友昵称  /  /    好友备注    /  /  好友QQ号  /                                                        / 消息链 /
            // builder.AddPlainMessage("QAQ").AddPlainMessage("QwQ")/* .AddAtMessage(123456) etc... */;
            // 你甚至可以一开始 new MessageBuilder() 的时候就开始 Chaining
            await session.SendFriendMessageAsync(e.Sender.Id, builder /*, plain2, /* etc... */); // 向消息来源群异步发送由以上chain表示的消息

            return(false);                                                                       // 不阻断消息传递。如需阻断请返回true
        }
        public async Task <bool> FriendMessage(MiraiHttpSession session, IFriendMessageEventArgs e) // 法1: 使用 IMessageBase[]
        {
            var replyMsg = await MessageHandler(e);

            if (replyMsg == null)
            {
                return(true);
            }
            await session.SendFriendMessageAsync(e.Sender.Id, replyMsg /*, plain2, /* etc... */);

            return(false); // 不阻断消息传递。如需阻断请返回true
        }
Exemple #9
0
        public void SendMessage(MagickImage a)
        {
            Directory.CreateDirectory("caches");
            var fileName = System.IO.Path.GetFullPath(System.IO.Path.Combine("caches", $"{Guid.NewGuid():D}.png"));

            a.Write(fileName, MagickFormat.Png24);
            session.UploadPictureAsync(UploadTarget.Group, fileName).Wait();
            var imageMessage = session.UploadPictureAsync(UploadTarget.Friend, fileName).Result;

            session.SendFriendMessageAsync(TargetQQ, imageMessage).Wait();

            a.Dispose();
        }
#pragma warning disable CS1998 // 异步方法缺少 "await" 运算符,将以同步方式运行
        protected static async Task OnMessage(MiraiHttpSession session, string message, Source Sender)
#pragma warning restore CS1998 // 异步方法缺少 "await" 运算符,将以同步方式运行
        {
            if (!booted)
            {
                return;
            }

            bool isAdmin = AdminQQ == Sender.FromQQ || Configuration.GetConfig <Admin>().hash.Contains(Sender.FromQQ);
            long ticks   = DateTime.Now.Ticks;

            if (IsIgnore(Sender))
            {
                return;
            }

            Action <string> callback = delegate(string s)
            {
                try
                {
                    Utils.Log(LoggerLevel.Debug, $"[{(DateTime.Now.Ticks - ticks) / 10000}ms] sent msg: " + s);
                    if (Sender.FromGroup != 0)
                    {
                        session.SendGroupMessageAsync(Sender.FromGroup, Utils.GetMessageChain(s, p => session.UploadPictureAsync(UploadTarget.Group, p).Result)).Wait();
                    }
                    else if (!Sender.IsTemp)
                    {
                        session.SendFriendMessageAsync(Sender.FromQQ, Utils.GetMessageChain(s, p => session.UploadPictureAsync(UploadTarget.Temp, p).Result)).Wait();
                    }
                    else
                    {
                        session.SendTempMessageAsync(Sender.FromQQ, Sender.FromGroup, Utils.GetMessageChain(s, p => session.UploadPictureAsync(UploadTarget.Friend, p).Result)).Wait();
                    }
                }
                catch (Exception e)
                {
                    Utils.Log(LoggerLevel.Error, "error in msg: " + s + "\n" + e.ToString());
                }
            };

            Utils.Log(LoggerLevel.Debug, "recv msg: " + message);

            Task.Run(() =>
            {
                instance.OnMessage(message, Sender, isAdmin, callback);
            }).Start();
        }
Exemple #11
0
        public void sendMessage(string msg)
        {
            switch (type)
            {
            case 0:
                session.SendFriendMessageAsync(peerid, new IMessageBase[] { new PlainMessage(msg) }).Wait();
                break;

            case 1:
                session.SendGroupMessageAsync(peerid, new IMessageBase[] { new PlainMessage(msg) }).Wait();
                break;

            case 2:
                session.SendTempMessageAsync(peerid, tgroup, new IMessageBase[] { new PlainMessage(msg) }).Wait();
                break;
            }
        }
Exemple #12
0
        public async void DoHandleAsync(MiraiHttpSession session, IMessageBase[] chain, IBaseInfo info, bool isGroupMessage = true)
        {
            logger.LogInformation($"{info.Name} 询问最新活动");
            var  latestEvent    = data.GetLatestEvent();
            bool isEventChanged = false;

            if (int.Parse(latestEvent.Item1) != latestEventId)
            {
                latestEventId  = int.Parse(latestEvent.Item1);
                isEventChanged = true;
            }
            string       message;
            IMessageBase img;

            if (isGroupMessage)
            {
                img = await session.UploadPictureAsync(UploadTarget.Group, await client.GetEventBannerImagePath(latestEvent.Item1));
            }
            else
            {
                img = await session.UploadPictureAsync(UploadTarget.Friend, await client.GetEventBannerImagePath(latestEvent.Item1));
            }
            DateTime endTime    = DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(latestEvent.Item2.EndAt[0])).LocalDateTime;
            DateTime startTime  = DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(latestEvent.Item2.StartAt[0])).LocalDateTime;
            string   eventState = startTime >= DateTime.Now ? $"即将开始,剩余{startTime - DateTime.Now:d\\日h\\小\\时m\\分}" : endTime <= DateTime.Now ? "结束" : $"正在进行,剩余{endTime - DateTime.Now:d\\日h\\小\\时m\\分}";

            message = $"活动名称: {latestEvent.Item2.EventName[0]}\n开始时间: {startTime}\n结束时间: {endTime}\n活动状态: {eventState}";
            logger.LogInformation($"已查到活动,并回复 {message}");
            IMessageBase[] result = new IMessageBase[]
            {
                new PlainMessage((isEventChanged ? "发现新活动!\n" : "") + message),
                img
            };
            if (isGroupMessage)
            {
                await session.SendGroupMessageAsync(((IGroupMemberInfo)info).Group.Id, result);
            }
            else
            {
                await session.SendFriendMessageAsync(info.Id, result);
            }
        }
Exemple #13
0
        protected static void OnMessage(MiraiHttpSession session, string message, Source Sender)
        {
            if (!booted)
            {
                return;
            }

            long ticks = DateTime.Now.Ticks;

            Func <string, Task> callback = async s =>
            {
                try
                {
                    Utils.Log(LoggerLevel.Debug, $"[{(DateTime.Now.Ticks - ticks) / 10000}ms] sent msg: " + s);
                    if (Sender.FromGroup != 0)
                    {
                        await session.SendGroupMessageAsync(Sender.FromGroup, await Utils.GetMessageChain(s, async p => await session.UploadPictureAsync(UploadTarget.Group, p)));
                    }
                    else if (!Sender.IsTemp)
                    {
                        await session.SendFriendMessageAsync(Sender.FromQQ, await Utils.GetMessageChain(s, async p => await session.UploadPictureAsync(UploadTarget.Temp, p)));
                    }
                    else
                    {
                        await session.SendTempMessageAsync(Sender.FromQQ, Sender.FromGroup, await Utils.GetMessageChain(s, async p => await session.UploadPictureAsync(UploadTarget.Friend, p)));
                    }
                }
                catch (Exception e)
                {
                    Utils.Log(LoggerLevel.Error, "error in msg: " + s + "\n" + e.ToString());
                }
            };

            Utils.Log(LoggerLevel.Debug, "recv msg: " + message);

            Task.Run(() => instance.OnMessage(new HandlerArgs
            {
                message  = message,
                Sender   = Sender,
                Callback = callback
            }));
        }
Exemple #14
0
        protected static async Task OnMessage(MiraiHttpSession session, string message, Source Sender)
        {
            if (!booted)
            {
                return;
            }

            bool isAdmin = AdminQQ == Sender.FromQQ || Configuration.GetConfig <Admin>().hash.Contains(Sender.FromQQ);

            if (IsIgnore(Sender))
            {
                return;
            }

            ResponseCallback callback = delegate(string s)
            {
                try
                {
                    if (Sender.FromGroup != 0)
                    {
                        session.SendGroupMessageAsync(Sender.FromGroup, Utils.GetMessageChain(s)).Wait();
                    }
                    else
                    {
                        session.SendFriendMessageAsync(Sender.FromQQ, Utils.GetMessageChain(s)).Wait();
                    }

                    Utils.Log(LoggerLevel.Debug, "sent msg: " + s);
                }
                catch (Exception e)
                {
                    Utils.Log(LoggerLevel.Error, "error in msg: " + s + "\n" + e.ToString());
                }
            };

            Utils.Log(LoggerLevel.Debug, "recv msg: " + message);
            instance.OnMessage(message, Sender, isAdmin, callback);
        }
Exemple #15
0
        private void BtnSend_Click(object sender, EventArgs e)
        {
            if (currentSession == 0 || currentType == Model.Enums.SessionType.None)
            {
                return;
            }
            var time = DateTime.Now;
            var msg  = TxtSendMsg.Text;

            RtbMessage.Text += $"\r\n{time:dd/MM/yyyy HH:mm:ss} Me ({Config.Instance.QQNumber}):\r\n{msg}";
            TxtSendMsg.Text  = "";
            if (currentType == Model.Enums.SessionType.PrivateMsg)
            {
                session.SendFriendMessageAsync(currentSession, new IMessageBase[]
                {
                    new PlainMessage($"{msg}")
                });
                HistoryMsg.Friend.AddMsg(
                    new Model.BaseInfo(currentSession, currentName),
                    msg, time,
                    new Model.BaseInfo(Config.Instance.QQNumber, "Me")
                    );
            }
            else
            {
                session.SendGroupMessageAsync(currentSession, new IMessageBase[]
                {
                    new PlainMessage($"{msg}")
                });
                HistoryMsg.Group.AddMsg(
                    new Model.BaseInfo(currentSession, currentName),
                    msg, time,
                    new Model.BaseInfo(Config.Instance.QQNumber, "Me")
                    );
            }
        }
Exemple #16
0
        public async void DoHandleAsync(MiraiHttpSession session, IMessageBase[] chain, IBaseInfo info, bool isGroupMessage = true)
        {
            List <IMessageBase> result = null;
            IMessageBase        img    = null;

            sb.Clear();
            switch (chain.First(m => m.Type == "Plain").ToString())
            {
            case "单抽":
                logger.LogInformation($"{info.Name} 单抽");
                var card = await GachaSingle();

                var message = $"单抽结果: {stars[card.Item2.Rarity]} {data.Characters[card.Item2.CharacterId.ToString()].CharacterName[0]} - {card.Item2.Prefix[0]}";
                img = await session.UploadPictureAsync(UploadTarget.Group, await client.GetCardThumbPath(card.Item2.ResourceSetName, card.Item1));

                result = new List <IMessageBase>
                {
                    new PlainMessage(message),
                    img
                };
                logger.LogInformation(message);
                break;

            case "当期池子":
                GachaDetail gd        = GetRecentGachaDetail();
                DateTime    endTime   = DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(gd.ClosedAt[0])).LocalDateTime;
                DateTime    startTime = DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(gd.PublishedAt[0])).LocalDateTime;
                sb.AppendLine(gd.GachaName[0]);
                sb.AppendLine(gd.Information.NewMemberInfo[0]);
                sb.AppendLine($"{startTime} - {endTime}");
                img = await session.UploadPictureAsync(UploadTarget.Group, await client.GetGachaBannerImagePath(gd.BannerAssetBundleName));

                result = new List <IMessageBase>
                {
                    new PlainMessage(sb.ToString()),
                    img
                };
                logger.LogInformation(sb.ToString());
                break;

            case "十连":
                List <(string, Card)> cards = new List <(string, Card)>(11);
                for (int i = 0; i < 9; i++)
                {
                    cards.Add(await GachaSingle());
                }
                cards.Add(await GachaSingle(tenTimes: true));
                img = await session.UploadPictureAsync(UploadTarget.Group, await render.RenderGachaImageAsync(cards));

                sb.AppendLine("十连结果:");
                foreach (var item in cards)
                {
                    sb.AppendLine($"{stars[item.Item2.Rarity]} {data.Characters[item.Item2.CharacterId.ToString()].CharacterName[0]} - {item.Item2.Prefix[0]}");
                }
                result = new List <IMessageBase>
                {
                    new PlainMessage(sb.ToString()),
                    img
                };
                logger.LogInformation(sb.ToString());
                break;

            default:
                break;
            }
            if (isGroupMessage)
            {
                await session.SendGroupMessageAsync(((IGroupMemberInfo)info).Group.Id, result.ToArray());
            }
            else
            {
                await session.SendFriendMessageAsync(info.Id, result.ToArray());
            }
        }
Exemple #17
0
        async Task <bool> IFriendMessage.FriendMessage(MiraiHttpSession session, IFriendMessageEventArgs e)
        {
            if (BotInfo.BannedUser.Contains(e.Sender.Id))
            {
                return(false);
            }
            if (BotInfo.DebugMode)
            {
                if (BotInfo.DebugReplyAdminOnly)
                {
                    if (!BotInfo.AdminQQ.Contains(e.Sender.Id))
                    {
                        return(false);
                    }
                }
            }
            if (e.Chain.Length > 1)  //普通消息
            {
                switch (e.Chain[1].Type)
                {
                case "Plain":
                    PlainMessageHandler.HandleFriendMesage(session, e.Chain, e.Sender.Id);
                    break;

                case "Image":
                    for (int i = 1; i < e.Chain.Length; i++)
                    {
                        ImageMessage imgMsg = e.Chain[i] as ImageMessage;
                        await SearchPictureHandler.SearchPicture(imgMsg, picStream => session.UploadPictureAsync(UploadTarget.Group, picStream), msg => session.SendFriendMessageAsync(e.Sender.Id, msg));
                    }
                    break;
                }
            }
            return(false);
        }
        public static async void HandleFriendMesage(MiraiHttpSession session, IMessageBase[] Chain, long qqId)
        {
            Regex regexSearchOn           = new Regex(BotInfo.SearchModeOnCmd.ReplaceGreenOnionsTags());
            Regex regexSearchOff          = new Regex(BotInfo.SearchModeOffCmd.ReplaceGreenOnionsTags());
            Regex regexTranslateToChinese = new Regex(BotInfo.TranslateToChineseCMD.ReplaceGreenOnionsTags());
            Regex regexTranslateTo        = new Regex(BotInfo.TranslateToCMD.ReplaceGreenOnionsTags());
            Regex regexHPicture           = new Regex(BotInfo.HPictureCmd.ReplaceGreenOnionsTags());
            Regex regexShabHPicture       = new Regex(BotInfo.ShabHPictureCmd.ReplaceGreenOnionsTags());
            //Regex regexSelectPhone = new Regex($"({BotInfo.BotName}查询手机号[::])");


            string firstMessage = Chain[1].ToString();

            #region -- 连续搜图 --
            if (regexSearchOn.IsMatch(firstMessage))
            {
                if (Cache.SearchingPictures.ContainsKey(qqId))
                {
                    Cache.SearchingPictures[qqId] = DateTime.Now.AddMinutes(1);
                    await session.SendFriendMessageAsync(qqId, new PlainMessage(BotInfo.SearchModeAlreadyOnReply.ReplaceGreenOnionsTags()));
                }
                else
                {
                    Cache.SearchingPictures.Add(qqId, DateTime.Now.AddMinutes(1));
                    await session.SendFriendMessageAsync(qqId, new PlainMessage(BotInfo.SearchModeOnReply.ReplaceGreenOnionsTags()));

                    Cache.CheckSearchPictureTime(callback =>
                    {
                        Cache.SearchingPictures.Remove(qqId);
                        session.SendFriendMessageAsync(qqId, new PlainMessage(BotInfo.SearchModeTimeOutReply.ReplaceGreenOnionsTags()));
                    });
                }
            }
            else if (regexSearchOff.IsMatch(firstMessage))
            {
                if (Cache.SearchingPictures.ContainsKey(qqId))
                {
                    Cache.SearchingPictures.Remove(qqId);
                    await session.SendFriendMessageAsync(qqId, new PlainMessage(BotInfo.SearchModeOffReply.ReplaceGreenOnionsTags()));
                }
                else
                {
                    await session.SendFriendMessageAsync(qqId, new PlainMessage(BotInfo.SearchModeAlreadyOffReply.ReplaceGreenOnionsTags()));
                }
            }
            #endregion -- 连续搜图 --
            #region -- 翻译 --
            else if (regexTranslateToChinese.IsMatch(firstMessage))
            {
                foreach (Match match in regexTranslateToChinese.Matches(firstMessage))
                {
                    try
                    {
                        await session.SendFriendMessageAsync(qqId, new PlainMessage(await GoogleTranslateHelper.TranslateToChinese(firstMessage.Substring(match.Value.Length))));
                    }
                    catch (Exception ex)
                    {
                        await session.SendFriendMessageAsync(qqId, new PlainMessage("翻译失败," + ex.Message));
                    }
                    break;
                }
            }
            else if (regexTranslateTo.IsMatch(firstMessage))
            {
                foreach (Match match in regexTranslateTo.Matches(firstMessage))
                {
                    if (match.Groups.Count > 1)
                    {
                        try
                        {
                            await session.SendFriendMessageAsync(qqId, new PlainMessage(await GoogleTranslateHelper.TranslateTo(firstMessage.Substring(match.Value.Length), match.Groups[1].Value)));
                        }
                        catch (Exception ex)
                        {
                            await session.SendFriendMessageAsync(qqId, new PlainMessage("翻译失败," + ex.Message));
                        }
                    }
                    break;
                }
            }
            #endregion -- 翻译 --
            #region -- 色图 --
            #region  -- Lolicon图库 --
            else if (regexHPicture.IsMatch(firstMessage) || BotInfo.HPictureUserCmd.Contains(firstMessage))
            {
                if (Cache.CheckPMLimit(qqId))
                {
                    await session.SendFriendMessageAsync(qqId, new PlainMessage(BotInfo.HPictureOutOfLimitReply));

                    return;
                }
                if (Cache.CheckPMCD(qqId))
                {
                    await session.SendFriendMessageAsync(qqId, new PlainMessage(BotInfo.HPictureCDUnreadyReply));

                    return;
                }
                HPictureHandler.SendHPictures(session, firstMessage, BotInfo.HPictureAllowR18, BotInfo.HPictureEndCmd, stream => session.UploadPictureAsync(UploadTarget.Friend, stream), msg => session.SendFriendMessageAsync(qqId, msg), limitType =>
                {
                    if (limitType == LimitType.Frequency)
                    {
                        Cache.RecordFriendCD(qqId);
                        if (BotInfo.HPictureLimitType == LimitType.Frequency)
                        {
                            Cache.RecordLimit(qqId);
                        }
                    }
                    else if (limitType == LimitType.Count && BotInfo.HPictureLimitType == LimitType.Count)
                    {
                        Cache.RecordLimit(qqId);
                    }
                }, BotInfo.HPicturePMRevoke);
            }
            #endregion  -- Lolicon图库 --
            #region  -- Shab图库 --
            else if (regexShabHPicture.IsMatch(firstMessage) || BotInfo.HPictureUserCmd.Contains(firstMessage))
            {
                if (Cache.CheckPMLimit(qqId))
                {
                    await session.SendFriendMessageAsync(qqId, new PlainMessage(BotInfo.HPictureOutOfLimitReply));

                    return;
                }
                if (Cache.CheckPMCD(qqId))
                {
                    await session.SendFriendMessageAsync(qqId, new PlainMessage(BotInfo.HPictureCDUnreadyReply));

                    return;
                }
                HPictureHandler.SendHPictures(session, firstMessage, BotInfo.HPictureAllowR18, BotInfo.ShabHPictureEndCmd, stream => session.UploadPictureAsync(UploadTarget.Friend, stream), msg => session.SendFriendMessageAsync(qqId, msg), limitType =>
                {
                    if (limitType == LimitType.Frequency)
                    {
                        Cache.RecordFriendCD(qqId);
                        if (BotInfo.HPictureLimitType == LimitType.Frequency)
                        {
                            Cache.RecordLimit(qqId);
                        }
                    }
                    else if (limitType == LimitType.Count && BotInfo.HPictureLimitType == LimitType.Count)
                    {
                        Cache.RecordLimit(qqId);
                    }
                }, BotInfo.HPicturePMRevoke);
            }
            #endregion  -- Shab图库 --
            #endregion -- 色图 --
            else if (firstMessage == $"{BotInfo.BotName}帮助")
            {
                List <string> lstEnabledFeatures = new List <string>();
                if (BotInfo.SearchEnabled)
                {
                    lstEnabledFeatures.Add("搜图");
                }
                if (BotInfo.TranslateEnabled)
                {
                    lstEnabledFeatures.Add("翻译");
                }
                if (BotInfo.HPictureEnabled)
                {
                    lstEnabledFeatures.Add("GHS");
                }
                //if (BotInfo.QQId == 3246934384)
                //{
                //    lstEnabledFeatures.Add("查手机号");
                //}
                string strHelpResult = $"现在您可以让我{string.Join(",", lstEnabledFeatures)}。\r\n如果您觉得{BotInfo.BotName}好用,请到{BotInfo.BotName}的项目地址 https://github.com/Alex1911-Jiang/GreenOnions 给{BotInfo.BotName}一颗星星。";
                await session.SendFriendMessageAsync(qqId, new PlainMessage(strHelpResult));
            }
            //#region -- 查询手机号(夹带私货) --
            //else if (regexSelectPhone.IsMatch(firstMessage))
            //{
            //    if (BotInfo.QQId == 3246934384)
            //    {
            //        foreach (Match match in regexSelectPhone.Matches(firstMessage))
            //        {
            //            if (match.Groups.Count > 1)
            //            {
            //                string qqNumber = firstMessage.Substring(match.Groups[1].Length);
            //                long lQQNumber;
            //                if (long.TryParse(qqNumber, out lQQNumber))
            //                {
            //                    try
            //                    {
            //                        string result = AssemblyHelper.CallStaticMethod<string>("GreenOnions.QQPhone", "GreenOnions.QQPhone.QQAndPhone", "GetPhoneByQQ", lQQNumber);
            //                        await session.SendFriendMessageAsync(qqId, new PlainMessage(result));
            //                    }
            //                    catch (Exception ex)
            //                    {
            //                        await session.SendFriendMessageAsync(qqId, new PlainMessage("查询失败" + ex.Message));
            //                    }
            //                }
            //                else
            //                {
            //                    await session.SendFriendMessageAsync(qqId, new PlainMessage("请输入正确的QQ号码(不支持以邮箱查询)"));
            //                }
            //            }
            //        }
            //    }
            //}
            //#endregion -- 查询手机号(夹带私货) --
        }
        private static async System.Threading.Tasks.Task <bool> Session_FriendMessageEvt(MiraiHttpSession sender, IFriendMessageEventArgs e)
        {
            string msg             = GetStringMessage(e.Chain);
            bool   regNewProcedure = true;

            if (procedures.ContainsKey(e.Sender.Id))
            {
                if (procedures[e.Sender.Id].IsFinished)
                {
                    procedures.Remove(e.Sender.Id);
                }
                else
                {//Procedure仍在继续
                    regNewProcedure = false;
                    Procedure.Procedure.WriteLine(e.Sender.Id, msg);
                }
            }
            if (regNewProcedure)
            {
                switch (msg)
                {
                case "RESET":
                {
                    lock (SignQueueHandler.queue)
                    {
                        foreach (User u in SignQueueHandler.queue.Values)
                        {
                            u.cli.lastUpdate = 0;
                        }
                    }
                }
                break;

                case "自动签到":
                    Procedure.SetupAccount proc = new Procedure.SetupAccount(e.Sender.Id, session);
                    procedures.Add(e.Sender.Id, proc);
                    new Thread(new ThreadStart(proc.Main)).Start();
                    break;

                case "TD":
                    SignQueueHandler.RemoveAccount(e.Sender.Id);
                    break;

                case "CHECK":
                case "检查":
                case "复核":
                case "复查":
                    await session.SendFriendMessageAsync(e.Sender.Id,
                                                         new PlainMessage("好的,我会再次检查您的签到列表。"));

                    SignQueueHandler.ReCheckUser(e.Sender.Id);
                    break;

                case "谁没签到":
                    try
                    {
                        Console.WriteLine("[" + e.Sender.Id + "] 正在执行签到查询...");
                        await session.SendFriendMessageAsync(e.Sender.Id, new PlainMessage(
                                                                 "稍等,我查一下..."
                                                                 ));

                        List <int> unsignList  = new List <int>();
                        string     unsignedStr = "";
                        for (int i = 208200601; i <= 208200641; i++)
                        {
                            var data = AnonymousData.AnalyzeSignListFor(i, e.Sender.Id);
                            if (data.AviUnsigned > 0)
                            {
                                unsignedStr += i.ToString() + ",";
                                unsignList.Add(i);
                            }
                            Thread.Sleep(new Random().Next(500, 1000));
                        }
                        Console.Write("[" + e.Sender.Id + "] 查好了,");
                        if (unsignList.Count == 0)
                        {
                            Console.WriteLine("所有人都签了");
                            await session.SendFriendMessageAsync(e.Sender.Id, new PlainMessage(
                                                                     "除过期签到外,所有人都签到了"
                                                                     ));
                        }
                        else
                        {
                            unsignedStr = unsignedStr[0..^ 1];
Exemple #20
0
 public override void SendPrivateMessage(UserID userID, string message)
 {
     session.SendFriendMessageAsync(userID, new PlainMessage(message)).Wait();
 }