Exemple #1
0
        public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope)
        {
            var routeMsg = scope.RouteMessage;

            if (!routeMsg.RawMessage.Contains("数咩羊"))
            {
                return(null);
            }

            using (Session session = new Session(8000, routeMsg.Identity, routeMsg.UserId))
            {
                SendMessage(routeMsg.ToSource("睡不着那就一起数咩羊吧。来,我先开始,1!"));
                int count = 1;
                try
                {
                    CoolQRouteMessage obj = (CoolQRouteMessage)session.GetMessage();
                    do
                    {
                        System.Threading.Thread.Sleep(1000);

                        if (int.TryParse(obj.RawMessage, out var res))
                        {
                            if (res == count + 1)
                            {
                                count += 2;
                                SendMessage(routeMsg.ToSource(count.ToString()));
                            }
                            else
                            {
                                SendMessage(routeMsg.ToSource($"你数错啦,是不是困了?现在是{count},到你了"));
                            }
                        }
                        else
                        {
                            SendMessage(routeMsg.ToSource($"不对!要好好数数哦!现在是{count},到你了"));
                        }

                        System.Threading.Thread.Sleep(1000);

                        if (count > 15)
                        {
                            SendMessage(routeMsg.ToSource("不数羊了,人家都困了,聊点别的吧!"));
                            break;
                        }
                        obj = (CoolQRouteMessage)session.GetMessage();
                    } while (obj != null);
                }
                catch (TimeoutException)
                {
                    SendMessage(routeMsg.ToSource("数不动了吗,那就好好睡觉咯,晚安!"));
                }
            }

            return(null);
        }
Exemple #2
0
        public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope)
        {
            var routeMsg = scope.RouteMessage;

            _routeMsg = routeMsg;
            try
            {
                using (_session = new Session(1000 * (60 * 2), _routeMsg.Identity, _routeMsg.UserId))
                {
                    try
                    {
                        NavigatableNode memberMenu, voteMenu, inputQqIdScene, handleScene;
                        InitNode(out memberMenu, out voteMenu, out inputQqIdScene, out handleScene);
                        var program = new NavigatableTree(mainNode, obj =>
                        {
                            const string mainText = "· 管理员菜单:\r\n" +
                                                    " 1. 群员指令\r\n" +
                                                    " 2. 投票指令";
                            SendMessage(routeMsg.ToSource(mainText));
                            CoolQRouteMessage cmMain = SessionCondition("1", "2");
                            switch (cmMain.RawMessage)
                            {
                            case "1":
                                return(new Action(memberMenuNode));

                            default:
                                return(new Action());
                            }
                        });

                        program.Root.AddChild(memberMenu);
                        program.Root.AddChild(voteMenu);
                        memberMenu.AddChild(inputQqIdScene);
                        inputQqIdScene.AddChild(handleScene);
                        program.Run();
                    }
                    catch (TimeoutException e)
                    {
                    }
                }
            }
            catch (NotSupportedException)
            {
            }

            return(null);
        }
Exemple #3
0
        public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope)
        {
            var routeMsg = scope.RouteMessage;

            if (!routeMsg.RawMessage.Equals("/转"))
            {
                return(null);
            }
            using (Session session = new Session(1000 * 60, routeMsg.Identity, routeMsg.UserId))
            {
                SendMessage(routeMsg.ToSource("请发送图片,5张以内,1分钟内有效。", true));
                try
                {
                    CoolQRouteMessage routeMessage = (CoolQRouteMessage)session.GetMessage();
                    var infoList = CoolQCode.GetImageInfo(routeMessage.RawMessage);
                    if (infoList == null)
                    {
                        return(routeMessage.ToSource("你发送的消息没有包含图片。"));
                    }
                    if (infoList.Length > 5)
                    {
                        return(routeMessage.ToSource("你发送的图片过多。"));
                    }

                    List <Image> imgList = infoList.Select(imgInfo => HttpClient.GetImageFromUrl(imgInfo.Url))
                                           .ToList();

                    var sendList = HandleImage(imgList);

                    return(routeMessage.ToSource(string.Join("\r\n", sendList)));
                }
                catch (TimeoutException)
                {
                    return(null);
                }
            }
        }
Exemple #4
0
        public static void Query()
        {
            while (MessageQueue.Count != 0)
            {
                if (!MessageQueue.TryDequeue(out var routeMsg))
                    continue;
                var cmd = routeMsg.CommandName;

                const long cabbageId = 1335734629;
                string uname;
                if (cmd == "statme" || cmd == "bpme" || cmd == "mybp" || cmd == "costme" || cmd == "mycost")
                {
                    BllUserRole bllUserRole = new BllUserRole();
                    List<TableUserRole> userInfo = bllUserRole.GetUserRoleByQq(long.Parse(routeMsg.UserId));
                    if (userInfo.Count == 0)
                        DaylilyCore.Current.MessageDispatcher?.SendMessageAsync(routeMsg.ToSource(DefaultReply.IdNotBound, true));

                    uname = userInfo[0].CurrentUname;
                }
                else
                    uname = routeMsg.ArgString;

                using (Session session = new Session(25000, new CoolQIdentity(cabbageId, MessageType.Private), cabbageId))
                {
                    DaylilyCore.Current.MessageDispatcher?.SendMessageAsync(
                        new CoolQRouteMessage($"!{cmd.Replace("my", "").Replace("me", "")} {uname}",
                            new CoolQIdentity(cabbageId, MessageType.Private)));
                    try
                    {
                        CoolQRouteMessage result = (CoolQRouteMessage)session.GetMessage();
                        session.Timeout = 600;
                        CoolQRouteMessage result2 = null;
                        try
                        {
                            result2 = (CoolQRouteMessage)session.GetMessage();
                        }
                        catch
                        {
                            // ignored
                        }

                        ImageInfo[] imgList =
                            CoolQCode.GetImageInfo(result.RawMessage) ?? CoolQCode.GetImageInfo(result2?.RawMessage);

                        if (imgList == null)
                        {
                            DaylilyCore.Current.MessageDispatcher?.SendMessageAsync(routeMsg.ToSource(result.RawMessage));
                            if (result2 != null)
                                DaylilyCore.Current.MessageDispatcher?.SendMessageAsync(routeMsg.ToSource(result2.RawMessage));
                            continue;
                        }
                        //throw new IndexOutOfRangeException("查询失败:" + result.Message);
                        var message = CoolQCode.DecodeToString(result.RawMessage);
                        foreach (var item in imgList)
                        {
                            var str = new FileImage(new Uri(item.Url));
                            StringFinder sf = new StringFinder(message);
                            sf.FindNext("[图片]");
                            string str1 = sf.Cut();
                            if (sf.FindNext("[图片]", false) > message.Length - 1)
                            {
                                message = str1 + str;
                                continue;
                            }

                            sf.FindToLast();
                            string str2 = sf.Cut();
                            message = str1 + str + str2;
                        }

                        DaylilyCore.Current.MessageDispatcher?.SendMessageAsync(
                            routeMsg.ToSource(message + "\r\n(查询由白菜支持)"));
                    }
                    catch (IndexOutOfRangeException e)
                    {
                        string msg = e.Message;
                        DaylilyCore.Current.MessageDispatcher?.SendMessageAsync(routeMsg.ToSource(msg, true));
                    }
                    catch (TimeoutException)
                    {
                        string msg = "查询失败,白菜没有搭理人家..";
                        DaylilyCore.Current.MessageDispatcher?.SendMessageAsync(routeMsg.ToSource(msg, true));
                    }
                    catch (Exception ex)
                    {
                        string msg = "查询失败,未知错误。";
                        Logger.Exception(ex);
                        DaylilyCore.Current.MessageDispatcher?.SendMessageAsync(routeMsg.ToSource(msg, true));
                    } // catch
                } // using
            } // while
        }
Exemple #5
0
        public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope)
        {
            var routeMsg = scope.RouteMessage;

            _routeMsg = routeMsg;
            if (UseList)
            {
                return(routeMsg
                       .ToSource(ShowList())
                       .ForceToSend());
            }
            if (CommandName == null)
            {
                using (Session session = new Session(20000, _routeMsg.Identity, _routeMsg.UserId))
                {
                    Dictionary <string, string> dic = new Dictionary <string, string>
                    {
                        { "你是谁", "你是谁。" },
                        { "基础帮助", "查看通用的基础使用方法。" },
                        { "查列表", "查看所有可用的命令和应用列表。(/help -list)" }
                    };

                    string[] sb = dic.Select(k => $"【{k.Key}】 {k.Value}").ToArray();

                    string msg = "被召唤啦!请选择你要查看的帮助类型:\r\n" + string.Join("\r\n", sb);
                    SendMessage(routeMsg
                                .ToSource(msg)
                                .ForceToSend()
                                );
                    try
                    {
                        var keys = dic.Select(k => k.Key).ToArray();

                        CoolQRouteMessage cm;
                        do
                        {
                            cm = (CoolQRouteMessage)session.GetMessage();
                            if (cm.RawMessage.Contains("你是谁"))
                            {
                                return(routeMsg
                                       .ToSource(new FileImage(Path.Combine(StaticDir, "help.jpg")).ToString())
                                       .ForceToSend());
                            }
                            if (cm.Message.RawMessage.Contains("基础帮助"))
                            {
                                if (cm.MessageType == MessageType.Private)
                                {
                                    return(routeMsg
                                           .ToSource(ConcurrentFile.ReadAllText(Path.Combine(StaticDir, "common.txt")))
                                           .ForceToSend());
                                }

                                SendMessage(routeMsg
                                            .ToSource("已发送至私聊,请查看。", true)
                                            .ForceToSend()
                                            );
                                var helpStr = ConcurrentFile.ReadAllText(Path.Combine(StaticDir, "common.txt"));
                                SendMessage(new CoolQRouteMessage(helpStr, new CoolQIdentity(_routeMsg.UserId, MessageType.Private))
                                            .ForceToSend()
                                            );
                                return(null);
                            }

                            if (cm.RawMessage.Contains("查列表"))
                            {
                                return(routeMsg
                                       .ToSource(ShowList())
                                       .ForceToSend());
                            }

                            SendMessage(routeMsg.ToSource("请回复大括号内的文字。"));
                        } while (!keys.Contains(cm.RawMessage));

                        return(routeMsg
                               .ToSource(ShowList())
                               .ForceToSend());
                    }
                    catch (TimeoutException)
                    {
                        return(routeMsg
                               .ToSource("没人鸟我,走了.jpg")
                               .ForceToSend());
                    }
                }
            }

            return(routeMsg
                   .ToSource(ShowDetail())
                   .ForceToSend());
        }