コード例 #1
0
ファイル: Program.cs プロジェクト: fengyeju/Daylily
        static void Main(string[] args)
        {
            Subscribe newPlugin = new Subscribe
            {
                //UnsubscribeMapper = "pw384",
                //SubscribeMapper = "rustbell",
                //SubscribeMapper = "UnitedWeSin",
                SubscribeMapper = "yf_bmp",
                //SubscribeMapper = "pw384",
                //List = true
            };

            newPlugin.OnInitialized(new StartupConfig(null, null, new StartupConfig.Metadata()));
            CoolQRouteMessage cm = CoolQRouteMessage.Parse(new CoolQGroupMessageApi
            {
                GroupId = 123456788,
                UserId  = 2241521134,
                Message = "SB",
            });

            Logger.Success("收到:" + newPlugin.OnMessageReceived(new CoolQ.CoolQScopeEventArgs
            {
                RouteMessage = cm
            }).Message);
            Console.ReadKey();
        }
コード例 #2
0
ファイル: PluginSwitcher.cs プロジェクト: fengyeju/Daylily
        public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope)
        {
            var routeMsg = scope.RouteMessage;

            _routeMsg = routeMsg;
            _identity = (CoolQIdentity)_routeMsg.Identity;
            _plugins  = PluginManager.Current.Plugins.OfType <MessagePlugin>()
                        .Where(k => (k.MiddlewareConfig as BackendConfig)?.CanDisabled == true)
                        .Where(k => k.TargetAuthority != Authority.Root);
            if (!DisabledList.ContainsKey(_identity))
            {
                DisabledList.Add(_identity, new List <Guid>());
            }

            _disabled = DisabledList[_identity];

            if (_routeMsg.CurrentAuthority == Authority.Public && _routeMsg.MessageType == MessageType.Group)
            {
                return(_routeMsg.ToSource(DefaultReply.AdminOnly));
            }
            if (List)
            {
                return(ShowPluginList());
            }
            if (DisabledPlugin != null)
            {
                return(EnablePlugin());
            }
            if (EnabledPlugin != null)
            {
                return(DisablePlugin());
            }

            return(_routeMsg.ToSource(DefaultReply.ParamError));
        }
コード例 #3
0
ファイル: PornDetectorApp.cs プロジェクト: fengyeju/Daylily
        private CoolQRouteMessage AddCount(CoolQRouteMessage cm)
        {
            string user = cm.UserId, group = cm.GroupId;

            try
            {
                Logger.Warn("发现好图,存了");
                if (!UserCount.ContainsKey(user))
                {
                    UserCount.Add(user, 2);
                }
                UserCount[user]--;
                if (UserCount[user] != 0)
                {
                    return(cm.ToSource("?", true));
                }
                else
                {
                    UserCount[user] = 2;
                    CoolQHttpApiClient.SetGroupBan(group, user, (int)(0.5 * 60 * 60));
                    return(cm.ToSource("?", true));
                }
            }
            finally
            {
                SaveSettings(UserCount);
            }
        }
コード例 #4
0
ファイル: Admin.cs プロジェクト: fengyeju/Daylily
        private void InitNode(out NavigatableNode memberMenu, out NavigatableNode voteMenu,
                              out NavigatableNode inputQqIdScene, out NavigatableNode handleScene)
        {
            memberMenu = new NavigatableNode(memberMenuNode, obj =>
            {
                const string memberText = "· 群员指令:\r\n" +
                                          " 1. 处死群员\r\n" +
                                          " 2. 复活群员\r\n" +
                                          " 3. 踢出群员\r\n" +
                                          " 4. 封禁群员\r\n" +
                                          " 5. 烧烤群员\r\n" +
                                          " 6. 点群员灯\r\n" +
                                          " 7. 群员更名\r\n" +
                                          " 8. 把群员变成定时炸弹\r\n" +
                                          " 9. 返回";
                SendMessage(_routeMsg.ToSource(memberText));
                CoolQRouteMessage cmPlayer = SessionCondition("1", "2", "3", "4", "5", "6", "7", "8", "9");
                switch (cmPlayer.RawMessage)
                {
                case "9":
                    return(new Action(mainNode));

                default:
                    return(new Action());
                }
            });
            voteMenu       = null;
            inputQqIdScene = null;
            handleScene    = null;
        }
コード例 #5
0
        /// <summary>
        /// 更改摸图偏好会话
        /// </summary>
        private bool SessionMode(out CoolQRouteMessage sessionNoMap)
        {
            SendMessage(_routeMsg
                        .ToSource("请告诉我你的摸图偏好,可多选。\r\n" +
                                  "如发送 \"013\" 即指接受std、taiko、mania的地图\r\n" +
                                  "【0】osu!standard\r\n" +
                                  "【1】osu!taiko\r\n" +
                                  "【2】osu!catch\r\n" +
                                  "【3】osu!mania")
                        .ForceToSend()
                        );

            if (SessionMultiCondition(out char[] choices, '0', '1', '2', '3'))
            {
                for (int i = 0; i < _myInfo.Preference.Length; i++)
                {
                    _myInfo.Preference[i] = false;
                }

                foreach (var item in choices)
                {
                    _myInfo.Preference[int.Parse(item.ToString())] = true;
                }

                SaveMatchList(); //apply
                SendMessage(_routeMsg
                            .ToSource($"你的摸图偏好已更新为:{_myInfo.GetPreferenceString()}")
                            .ForceToSend()
                            );
            }
コード例 #6
0
ファイル: Count.cs プロジェクト: fengyeju/Daylily
        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);
        }
コード例 #7
0
ファイル: Admin.cs プロジェクト: fengyeju/Daylily
        /// <summary>
        /// 单选会话
        /// </summary>
        private CoolQRouteMessage SessionCondition(params string[] conditions)
        {
            _session.Timeout = 30000;
            CoolQRouteMessage cmPub = (CoolQRouteMessage)_session.GetMessage();
            int retryCount          = 0;

            while (!conditions.Contains(cmPub.RawMessage) && retryCount < 3)
            {
                retryCount++;
                cmPub = (CoolQRouteMessage)_session.GetMessage();
            }

            return(cmPub);
        }
コード例 #8
0
        /// <summary>
        /// 没有地图会话
        /// </summary>
        private CoolQRouteMessage SessionNoMap()
        {
            SendMessage(_routeMsg
                        .ToSource("你还没有发布任何一张图,需要现在发布吗?\r\n" +
                                  "【1】是 【2】否")
                        .ForceToSend()
                        );
            CoolQRouteMessage cmPub = SessionCondition("1", "2");

            return(cmPub.RawMessage == "1"
                ? SessionAddMap()
                : _routeMsg
                   .ToSource("由于你没有发布地图,已退出m4m模式。")
                   .ForceToSend());
        }
コード例 #9
0
        private void DispatchMessage(CoolQMessageApi coolQMessageApi)
        {
            CoolQIdentity cqIdentity;

            switch (coolQMessageApi)
            {
            case CoolQPrivateMessageApi privateMsg:
                cqIdentity = new CoolQIdentity(privateMsg.UserId, MessageType.Private);
                RunNext <CoolQPrivateMessageApi>(cqIdentity);
                break;

            case CoolQDiscussMessageApi discussMsg:
                cqIdentity = new CoolQIdentity(discussMsg.DiscussId, MessageType.Discuss);
                RunNext <CoolQDiscussMessageApi>(cqIdentity);
                break;

            case CoolQGroupMessageApi groupMsg:
                cqIdentity = new CoolQIdentity(groupMsg.GroupId, MessageType.Group);
                RunNext <CoolQGroupMessageApi>(cqIdentity);
                break;

            default:
                throw new ArgumentException();
            }

            SessionList[cqIdentity].LockMsg = false;

            void RunNext <T>(CoolQIdentity id) where T : CoolQMessageApi
            {
                while (SessionList[id].MsgQueue.TryDequeue(out object current))
                {
                    var currentMsg = (T)current;
                    try
                    {
                        CoolQRouteMessage coolQRouteMessage = CoolQRouteMessage.Parse(currentMsg);
                        HandleMessage(new CoolQScopeEventArgs
                        {
                            DisabledApplications = new List <ApplicationPlugin>(),
                            RouteMessage         = coolQRouteMessage
                        });
                    }
                    catch (Exception ex)
                    {
                        Logger.Exception(ex);
                    }
                }
            }
        }
コード例 #10
0
ファイル: Admin.cs プロジェクト: fengyeju/Daylily
        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);
        }
コード例 #11
0
        private bool ValidateCount(string[] album, out CoolQRouteMessage response)
        {
            if (album.Length > 1)
            {
                response = _cm.ToSource($"包含多个相册:\"{string.Join(',', album)}\"");
                return(true);
            }

            if (album.Length == 0)
            {
                response = _cm.ToSource($"没有找到相册 \"{EnabledAlbumId}\"");
                return(true);
            }

            response = null;
            return(false);
        }
コード例 #12
0
        public static Authority GetActualAuthority(CoolQRouteMessage routeMsg, out string fullCommand)
        {
            string message     = routeMsg.Message.RawMessage;
            var    requestAuth = GetRequestAuthority(message, out fullCommand) ?? Authority.Public;
            long   userId      = Convert.ToInt64(routeMsg.UserId);

            switch (requestAuth)
            {
            case Authority.Public:
            {
                var data = CoolQDispatcher.Current.SessionList[(CoolQIdentity)routeMsg.Identity].GetDataAsync().Result;
                if (data.GroupInfo?.Admins.Count(q => q.UserId == userId) != 0)
                {
                    requestAuth = Authority.Admin;
                }
                if (userId == 2241521134)
                {
                    requestAuth = Authority.Root;
                }
                break;
            }

            case Authority.Admin:
            {
                var data = CoolQDispatcher.Current.SessionList[(CoolQIdentity)routeMsg.Identity].GetDataAsync().Result;
                if (data.GroupInfo?.Admins.Count(q => q.UserId == userId) != 0)
                {
                    return(Authority.Admin);
                }

                break;
            }

            case Authority.Root:
                if (userId == 2241521134)
                {
                    return(Authority.Root);
                }

                break;
            }

            return(requestAuth);
        }
コード例 #13
0
        public override bool Message_Received(object sender, MessageEventArgs args)
        {
            bool          handled   = false;
            var           originObj = (CoolQMessageApi)args.ParsedObject;
            CoolQIdentity identity;

            switch (originObj)
            {
            case CoolQPrivateMessageApi privateMsg:
                identity = new CoolQIdentity(privateMsg.UserId, MessageType.Private);
                break;

            case CoolQDiscussMessageApi discussMsg:
                identity = new CoolQIdentity(discussMsg.DiscussId, MessageType.Discuss);
                break;

            case CoolQGroupMessageApi groupMsg:
                identity = new CoolQIdentity(groupMsg.GroupId, MessageType.Group);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            if (!SessionList.ContainsKey(identity))
            {
                SessionList.Add(identity, new Session(identity));
            }
            if (SessionList[identity].MsgQueue.Count < SessionList[identity].MsgLimit) // 允许缓存n条,再多的丢弃
            {
                SessionList[identity].MsgQueue.Enqueue(originObj);
            }
            else if (!SessionList[identity].LockMsg)
            {
                SessionList[identity].LockMsg = true;
                SendMessageAsync(CoolQRouteMessage.Parse(originObj).ToSource(originObj.Message));
            }

            if (!SessionList[identity].TryRun(() => DispatchMessage(originObj)))
            {
                Logger.Info("当前已有" + SessionList[identity].MsgQueue.Count + "条消息在" + identity + "排队");
            }

            return(handled);
        }
コード例 #14
0
        private void HandleCommand(CoolQScopeEventArgs scope)
        {
            CoolQRouteMessage replyObj = null;

            if (!PluginManager.ContainsPlugin(scope.RouteMessage.CommandName))
            {
                return;
            }

            Type t = PluginManager.GetPluginType(scope.RouteMessage.CommandName);

            CoolQCommandPlugin plugin = PluginManager.CreateInstance <CoolQCommandPlugin>(t);

            if (plugin != null)
            {
                Task.Run(() =>
                {
                    try
                    {
                        if (!plugin.TryInjectParameters(scope.RouteMessage, out var bindingFailedItem))
                        {
                            plugin.OnCommandBindingFailed(new BindingFailedEventArgs(scope, bindingFailedItem));
                            return;
                        }
                        replyObj = plugin.OnMessageReceived(scope);
                    }
                    catch (Exception ex)
                    {
                        plugin.OnErrorOccured(new ExceptionEventArgs(scope, ex));
                    }

                    if (replyObj == null)
                    {
                        return;
                    }
                    SendMessageAsync(replyObj);
                }
                         );
            }
            else
            {
                Logger.Error($"Cannot find plugin: {t.FullName}.");
            }
        }
コード例 #15
0
ファイル: Program.cs プロジェクト: fengyeju/Daylily
        static void Main(string[] args)
        {
            // 引用添加项目Daylily.Common
            Panda newPlugin = new Panda();

            newPlugin.OnInitialized(new Bot.StartupConfig(null, null, new Bot.StartupConfig.Metadata()));
            CoolQRouteMessage cm = CoolQRouteMessage.Parse(new CoolQGroupMessageApi
            {
                GroupId = 123456788,
                UserId  = 2241521134,
                Message = "SB",
            });

            Logger.Success("收到:" + newPlugin.OnMessageReceived(new CoolQ.CoolQScopeEventArgs
            {
                RouteMessage = cm
            }).Message);
            Console.ReadKey();
        }
コード例 #16
0
        private async Task <bool> HandleApplication(CoolQScopeEventArgs scope)
        {
            int? priority = int.MinValue;
            bool handled  = false;

            foreach (var appPlugin in PluginManager.ApplicationInstances.OrderByDescending(k =>
                                                                                           k.MiddlewareConfig?.Priority))
            {
                int?p = appPlugin.MiddlewareConfig?.Priority;
                if (p < priority && handled)
                {
                    break;
                }

                priority = appPlugin.MiddlewareConfig?.Priority;

                if (scope.DisabledApplications.Contains(appPlugin))
                {
                    continue;
                }

                CoolQRouteMessage replyObj = null;
                var task = Task.Run(() =>
                {
                    replyObj = ((CoolQApplicationPlugin)appPlugin).OnMessageReceived(scope);
                    if (replyObj != null && !replyObj.Canceled)
                    {
                        SendMessageAsync(replyObj);
                    }
                });

                if (!appPlugin.RunInMultiThreading)
                {
                    await task.ConfigureAwait(false);

                    handled = replyObj?.Handled ?? false;
                }
            }

            return(handled);
        }
コード例 #17
0
ファイル: Program.cs プロジェクト: wusir2001/Daylily
        static void Main(string[] args)
        {
            Roll newPlugin = new Roll();

            newPlugin.OnInitialized(new StartupConfig(null, null, new StartupConfig.Metadata()));
            while (true)
            {
                var msg = Console.ReadLine();
                CoolQRouteMessage cm = CoolQRouteMessage.Parse(new CoolQGroupMessageApi
                {
                    GroupId = 123456788,
                    UserId  = 2241521134,
                    Message = msg,
                });

                Logger.Raw("回复:" + newPlugin.OnMessageReceived(new Daylily.CoolQ.CoolQScopeEventArgs
                {
                    RouteMessage = cm
                }).RawMessage);
            }
        }
コード例 #18
0
        public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope)
        {
            var routeMsg = scope.RouteMessage;

            _cm = routeMsg;
            string[] fullContent = ConcurrentFile.ReadAllLines(_content);

            if (EnabledAlbumId > 0 || DisabledAlbumId > 0)
            {
                return(_cm.CurrentAuthority == Authority.Root
                    ? ModuleManageAlbum(fullContent)
                    : routeMsg.ToSource(DefaultReply.RootOnly));
            }

            if (Like > 0)
            {
                return(ModuleLike(fullContent));
            }

            if (Hot)
            {
                return(ModuleHot());
            }

            if (Top || TopNum > 0)
            {
                return(ModuleTop());
            }

            if (ClearCache)
            {
                ClearContent();
                return(_cm
                       .ToSource("已重新建立缓存")
                       .ForceToSend());
            }

            return(ModuleSearch(fullContent));
        }
コード例 #19
0
ファイル: Test.cs プロジェクト: fengyeju/Daylily
        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);
                }
            }
        }
コード例 #20
0
        public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope)
        {
            var routeMsg = scope.RouteMessage;

            _routeMsg = routeMsg;
            if (List)
            {
                if (_routeMsg.CurrentAuthority == Authority.Root)
                {
                    BllUserRole   bllUserRole = new BllUserRole();
                    List <string> strs        = new List <string>();
                    foreach (var matchInfo in _matchList)
                    {
                        var    userInfo = bllUserRole.GetUserRoleByQq(long.Parse(matchInfo.Qq))[0];
                        string osuName  = userInfo.CurrentUname;
                        long?  id       = matchInfo.SetId;
                        string status;

                        if (matchInfo.TargetQq == null)
                        {
                            status = "等待匹配";
                        }
                        else
                        {
                            var    info = bllUserRole.GetUserRoleByQq(long.Parse(matchInfo.TargetQq))[0];
                            string name = info.CurrentUname;
                            status = $"已经和{name}匹配";
                        }

                        if (id == null)
                        {
                            strs.Add(osuName + ": 闲置中。");
                        }
                        else
                        {
                            strs.Add($"{osuName}  地图号: s/{id} {status}");
                        }
                    }

                    return(_routeMsg
                           .ToSource(string.Join("\r\n", strs))
                           .ForceToSend());
                }
                else
                {
                    return(_routeMsg.ToSource(DefaultReply.RootOnly));
                }
            }

            if (_routeMsg.MessageType != MessageType.Private)
            {
                return(_routeMsg.ToSource(DefaultReply.PrivateOnly));
            }

            try
            {
                using (_session = new Session(DefaultTimeout, _routeMsg.Identity, _routeMsg.UserId))
                {
                    BllUserRole          bllUserRole = new BllUserRole();
                    List <TableUserRole> userInfo    = bllUserRole.GetUserRoleByQq(long.Parse(routeMsg.UserId));
                    if (userInfo.Count == 0)
                    {
                        return(_routeMsg.ToSource("这个功能是需要绑定osu id的,请使用/setid完成绑定", true));
                    }

                    _osuId = userInfo[0].UserId.ToString();

                    try
                    {
                        // Init
                        if (!_matchList.Select(q => q.Qq).Contains(_routeMsg.UserId))
                        {
                            const string intro = @"这是一个利用我进行自动化管理的M4M平台,只需将图的链接给我,你无需自己各处求摸。
我会地合理地从库中挑选,并与你和另一人互相推荐,以达成自动匹配M4M的目的。
每个人只能给我一张图,第二张图会覆盖第一张图,所以有什么图需摸要记得更新哦!
最重要的一点:这仅仅是一个平台,真正的交流还需面对面进行。";
                            SendMessage(_routeMsg.ToSource(intro));

                            _matchList.Add(new MatchInfo(_routeMsg.UserId));
                            SaveMatchList(); //apply

                            Thread.Sleep(8000);
                        }

                        // Load
                        _myInfo             = _matchList.FirstOrDefault(q => q.Qq == _routeMsg.UserId);
                        _myInfo.IsOperating = true;
                        _myInfo.LastUse     = DateTime.Now;
                        var plugin = DaylilyCore.Current.PluginManager.GetPlugin <M4MMatchNoticeApp>();
                        if (plugin != null)
                        {
                            if (M4MMatchNoticeApp.Tipped.ContainsKey(_myInfo.Qq))
                            {
                                M4MMatchNoticeApp.Tipped[_myInfo.Qq] = DateTime.Now;
                            }
                            else
                            {
                                M4MMatchNoticeApp.Tipped.TryAdd(_myInfo.Qq, DateTime.Now);
                            }
                            plugin.SaveSettings();
                        }
                        // Confirm
                        if (Confirm)
                        {
                            if (_myInfo.TargetQq == null)
                            {
                                return(_routeMsg
                                       .ToSource("你尚且还没有正在进行的匹配。")
                                       .ForceToSend());
                            }

                            var oInfo = _matchList.FirstOrDefault(q => q.Qq == _myInfo.TargetQq);
                            if (DateTime.Now - oInfo.LastConfirmedTime < new TimeSpan(3, 0, 0))
                            {
                                return(_routeMsg
                                       .ToSource("你已在三小时之内发出过核对确认,请稍后再试。")
                                       .ForceToSend());
                            }
                            oInfo.RequestBeConfirmed();
                            SaveMatchList(); //apply

                            string nick = CoolQHttpApiClient.GetStrangerInfo(oInfo.Qq).Data?.Nickname ?? "玩家";
                            SendMessage(_routeMsg
                                        .ToSource($"你已经确认了{nick}({oInfo.Qq})的摸,请及时完成自己的摸!")
                                        .ForceToSend()
                                        );

                            string nick2 = CoolQHttpApiClient.GetStrangerInfo(_myInfo.Qq).Data?.Nickname ?? "玩家";
                            SendMessage(new CoolQRouteMessage($"{nick2}({_myInfo.Qq})已经确认查收了你的摸。",
                                                              new CoolQIdentity(oInfo.Qq, MessageType.Private)));

                            if (oInfo.LastConfirmedTime == null || _myInfo.LastConfirmedTime == null)
                            {
                                return(null);
                            }
                            Thread.Sleep(2000);
                            oInfo.FinishedSet.Add(_myInfo.SetId);
                            _myInfo.FinishedSet.Add(oInfo.SetId);
                            oInfo.Finish();
                            _myInfo.Finish();
                            SendMessage(new CoolQRouteMessage(
                                            $"你与{nick}({oInfo.Qq})的M4M ({oInfo.SetUrl}) 已完成,合作愉快!",
                                            new CoolQIdentity(_myInfo.Qq, MessageType.Private)));
                            SendMessage(new CoolQRouteMessage(
                                            $"你与{nick2}({_myInfo.Qq})的M4M ({_myInfo.SetUrl}) 已完成,合作愉快!",
                                            new CoolQIdentity(oInfo.Qq, MessageType.Private)));
                            SaveMatchList(); //apply
                            return(null);
                        }
                        // Finish
                        else if (Finish)
                        {
                            if (_myInfo.TargetQq == null)
                            {
                                return(_routeMsg
                                       .ToSource("你尚且还没有正在进行的匹配。")
                                       .ForceToSend());
                            }

                            var oInfo = _matchList.FirstOrDefault(q => q.Qq == _myInfo.TargetQq);
                            if (DateTime.Now - _myInfo.LastNoticeTime < new TimeSpan(3, 0, 0))
                            {
                                return(_routeMsg
                                       .ToSource("你已在三小时之内发出过完成提醒,请稍后再试。")
                                       .ForceToSend());
                            }
                            _myInfo.RequestFinishMatch();
                            SaveMatchList(); //apply

                            string nick2 = CoolQHttpApiClient.GetStrangerInfo(_myInfo.Qq).Data?.Nickname ?? "玩家";
                            SendMessage(new CoolQRouteMessage(
                                            $"{nick2}({_myInfo.Qq})已经摸完了你的图:\r\n" +
                                            $"{oInfo.SetUrl}\r\n" +
                                            $"正在等待你的摸。\r\n" +
                                            $"请检查他的modding情况,回复 \"/m4m -确认\" 查收。\r\n" +
                                            $"若对方没有摸完,请不要查收。若有疑问请相互交流。",
                                            new CoolQIdentity(oInfo.Qq, MessageType.Private)));
                            return(_routeMsg
                                   .ToSource("已发送完成请求。")
                                   .ForceToSend());
                        }
                        // Cancel
                        else if (Cancel)
                        {
                            if (_myInfo.TargetQq == null)
                            {
                                return(_routeMsg
                                       .ToSource("你尚且还没有正在进行的匹配。")
                                       .ForceToSend());
                            }

                            var oInfo = _matchList.FirstOrDefault(q => q.Qq == _myInfo.TargetQq);

                            if (oInfo.MatchTime == null)
                            {
                                oInfo.MatchTime = DateTime.Now; // 临时补救
                            }
                            if (DateTime.Now - oInfo.MatchTime < new TimeSpan(7, 0, 0, 0))
                            {
                                return(_routeMsg
                                       .ToSource("取消失败,仅匹配持续一周以上才可取消。")
                                       .ForceToSend());
                            }

                            string nick  = CoolQHttpApiClient.GetStrangerInfo(oInfo.Qq).Data?.Nickname ?? "玩家";
                            string nick2 = CoolQHttpApiClient.GetStrangerInfo(_myInfo.Qq).Data?.Nickname ?? "玩家";

                            oInfo.FinishedSet.Add(_myInfo.SetId);
                            _myInfo.FinishedSet.Add(oInfo.SetId);
                            oInfo.Finish();
                            _myInfo.Finish();
                            SendMessage(new CoolQRouteMessage(
                                            $"你与{nick}({oInfo.Qq})的M4M ({oInfo.SetUrl}) 已强制取消。",
                                            new CoolQIdentity(_myInfo.Qq, MessageType.Private)));
                            SendMessage(new CoolQRouteMessage(
                                            $"你与{nick2}({_myInfo.Qq})的M4M ({_myInfo.SetUrl}) 已强制取消。",
                                            new CoolQIdentity(oInfo.Qq, MessageType.Private)));
                            SaveMatchList(); //apply
                            return(null);
                        }

                        // No set after load
                        if (_myInfo.Set == null)
                        {
                            return(SessionNoMap());
                        }

                        // Matched Main
                        string info;
                        if (_myInfo.TargetQq != null)
                        {
                            var    oInfo = _matchList.FirstOrDefault(q => q.Qq == _myInfo.TargetQq);
                            string nick  = CoolQHttpApiClient.GetStrangerInfo(oInfo.Qq).Data?.Nickname ?? "玩家";
                            info = $"你已经成功和{nick}({oInfo.Qq})匹配\r\n" +
                                   $"· 你的信息:\r\n" +
                                   $"    地图地址:{_myInfo.SetUrl}\r\n" +
                                   $"    备注:{_myInfo.Mark}\r\n" +
                                   $"· 他的信息:\r\n" +
                                   $"    地图地址:{oInfo.SetUrl} \r\n" +
                                   $"    备注:{oInfo.Mark}\r\n" +
                                   $"当你摸图完成时,请使用 \"/m4m -完成\" 提醒对方审阅。\r\n" +
                                   $"当对方向你提出审阅请求后,请使用 \"/m4m -确认\" 完成审阅。\r\n" +
                                   $"若匹配持续超过一周,可使用  \"/m4m -取消\" 强制取消,且下次不会匹配到此图。";
                            return(_routeMsg
                                   .ToSource(info)
                                   .ForceToSend());
                        }

                        // Main
                        info = $"· 你的信息:\r\n" +
                               $"    地图地址:{_myInfo.SetUrl} \r\n" +
                               $"    备注:{_myInfo.Mark}\r\n" +
                               $"· 从下面的选项中选择一个你想进行的操作:\r\n" +
                               $">【1】删除已发布的地图。\r\n" +
                               $">【2】管理摸图偏好(当前:{_myInfo.GetPreferenceString()})。\r\n" +
                               $">【3】开始进行m4m匹配。";

                        SendMessage(_routeMsg
                                    .ToSource(info)
                                    .ForceToSend()
                                    );
                        CoolQRouteMessage cmMain = SessionCondition("1", "2", "3");
                        switch (cmMain.RawMessage)
                        {
                        case "1":
                            SendMessage(_routeMsg
                                        .ToSource("删除现有地图,确认吗?\r\n" +
                                                  "【1】是 【2】否")
                                        .ForceToSend());
                            CoolQRouteMessage cmPub = SessionCondition("1", "2");
                            if (cmPub.RawMessage == "1")
                            {
                                _myInfo.RemoveSet();
                                SaveMatchList();     //apply
                                return(_routeMsg
                                       .ToSource("删除成功。使用/m4m重新发布地图。")
                                       .ForceToSend());
                            }
                            else
                            {
                                return(_routeMsg
                                       .ToSource("你已取消操作。")
                                       .ForceToSend());
                            }

                        case "2":
                            if (SessionMode(out var sessionNoMap))
                            {
                                return(sessionNoMap);
                            }
                            return(null);

                        case "3":     // core
                            MatchInfo[] fullList = _matchList.Where(i =>
                                                                    i.Qq != _myInfo.Qq && i.TargetQq == null && i.Set != null && !i.IsOperating &&
                                                                    DateTime.Now - i.LastUse < new TimeSpan(7, 0, 0, 0)).ToArray();
                            if (fullList.Length == 0)
                            {
                                return(_routeMsg
                                       .ToSource("目前没有可匹配的用户,也有可能是可匹配的用户同时在浏览m4m菜单。请等待他人匹配或稍后重试。")
                                       .ForceToSend());
                            }

                            MatchInfo[] canModList = fullList.Where(i =>
                                                                    i.Preference.Have(_myInfo.Modes) == 1 &&
                                                                    _myInfo.Preference.Have(i.Modes) == 1 &&
                                                                    !i.FinishedSet.Contains(_myInfo.SetId) &&
                                                                    !_myInfo.FinishedSet.Contains(i.SetId)).ToArray();
                            if (canModList.Length == 0)
                            {
                                return(_routeMsg
                                       .ToSource("目前没有与你情况相符合的用户,请等待他人匹配或稍后重试。")
                                       .ForceToSend());
                            }

                            MatchInfo[] bestList = new MatchInfo[0];
                            int         count    = 0;
                            while (bestList.Length == 0 && count < 120)
                            {
                                bestList = canModList.Where(i =>
                                                            Math.Abs(_myInfo.GetPreferanceTotalLength(i) -
                                                                     i.GetPreferanceTotalLength(_myInfo)) < count).ToArray();
                                count += 10;
                                Thread.Sleep(1);
                            }

                            MatchInfo matchInfo;

                            if (bestList.Length < 1)
                            {
                                SendMessage(_routeMsg
                                            .ToSource("目前没有最佳的匹配,继续尝试不佳的匹配吗?\r\n" +
                                                      "【1】是 【2】否")
                                            .ForceToSend()
                                            );
                                CoolQRouteMessage cmContinue = SessionCondition("1", "2");
                                if (cmContinue.RawMessage == "1")
                                {
                                    MatchInfo[] notBestList = new MatchInfo[0];
                                    int         c           = count;
                                    while (notBestList.Length == 0 && c < 10000)
                                    {
                                        notBestList = canModList.Where(i =>
                                                                       Math.Abs(_myInfo.GetPreferanceTotalLength(i) -
                                                                                i.GetPreferanceTotalLength(_myInfo)) < c).ToArray();
                                        c += 50;
                                        Thread.Sleep(1);
                                    }

                                    matchInfo = notBestList[StaticRandom.Next(notBestList.Length)];
                                }
                                else
                                {
                                    return(_routeMsg
                                           .ToSource("你已取消操作。请等待他人匹配或稍后重试。")
                                           .ForceToSend());
                                }
                            }
                            else
                            {
                                matchInfo = bestList[StaticRandom.Next(bestList.Length)];
                            }

                            var    data1 = CoolQHttpApiClient.GetStrangerInfo(matchInfo.Qq).Data;
                            var    data2 = CoolQHttpApiClient.GetStrangerInfo(_myInfo.Qq).Data;
                            string sub1 = "Ta", sub2 = "Ta";
                            string nick1 = "玩家", nick2 = "玩家";
                            if (data1 != null)
                            {
                                if (data1.Sex == "male")
                                {
                                    sub1 = "他";
                                }
                                else if (data1.Sex == "female")
                                {
                                    sub1 = "她";
                                }
                                nick1 = data1.Nickname;
                            }

                            if (data2 != null)
                            {
                                if (data2.Sex == "male")
                                {
                                    sub2 = "他";
                                }
                                else if (data2.Sex == "female")
                                {
                                    sub2 = "她";
                                }
                                nick2 = data2.Nickname;
                            }

                            _myInfo.Start(matchInfo.Qq);
                            matchInfo.Start(_myInfo.Qq);
                            SaveMatchList();     //apply

                            const string tip = "当你选择完成摸图时,对方会收到一条消息确认你的mod,反之亦然。" +
                                               "当双方互批完成时,M4M成功结束!\r\n" +
                                               "若有疑问,请与对方互相协商。详细情况请使用 \"/m4m\"。";

                            SendMessage(new CoolQRouteMessage($"{nick2}({_myInfo.Qq}) 与你成功匹配\r\n" +
                                                              $"{sub2}的地图:{_myInfo.SetUrl}\r\n" +
                                                              $"{sub2}的备注:{_myInfo.Mark}\r\n" + tip,
                                                              new CoolQIdentity(matchInfo.Qq, MessageType.Private)));

                            return(_routeMsg
                                   .ToSource($"你与{nick1}({matchInfo.Qq}) 成功匹配\r\n" +
                                             $"{sub1}的地图:{matchInfo.SetUrl}\r\n" +
                                             $"{sub1}的备注:{matchInfo.Mark}\r\n" + tip)
                                   .ForceToSend());

                        default:
                            return(_routeMsg
                                   .ToSource("你开始了?走了.jpg")
                                   .ForceToSend());
                        }
                    }
                    catch (TimeoutException)
                    {
                        return(_routeMsg
                               .ToSource("由于长时间未操作,已经自动取消m4m状态。")
                               .ForceToSend());
                    }
                }
            }
            catch (NotSupportedException)
            {
                return(_routeMsg
                       .ToSource("你已在进行m4m状态中。", true)
                       .ForceToSend());
            }
            finally
            {
                if (_myInfo != null)
                {
                    _myInfo.IsOperating = false;
                    SaveMatchList(); //apply
                }
            }
        }
コード例 #21
0
ファイル: Konachan.cs プロジェクト: fengyeju/Daylily
        private string GetWebsite(CoolQRouteMessage routeMsg)
        {
            var name = routeMsg.CommandName.ToUpperInvariant();

            return(Websites.GetValueOrDefault(name));
        }
コード例 #22
0
ファイル: Help.cs プロジェクト: fengyeju/Daylily
        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());
        }
コード例 #23
0
ファイル: CabbageCommon.cs プロジェクト: fengyeju/Daylily
        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
        }
コード例 #24
0
 private CoolQRouteMessage SaveAndReply(CoolQRouteMessage routeMsg)
 {
     SaveUserDictionary();
     return(routeMsg.ToSource("操作已成功完成"));
 }
コード例 #25
0
        public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope)
        {
            var routeMsg = scope.RouteMessage;
            var msg      = routeMsg.RawMessage;

            if (!Detect(msg, out var tuples))
            {
                return(null);
            }

            CoolQRouteMessage message = null;

            foreach ((string origin, string mine) in tuples)
            {
                if (Filter.Any(k => mine.Contains(k)))
                {
                    continue;
                }
                if (!UserDictionary.ContainsKey(origin))
                {
                    UserDictionary.TryAdd(origin, new List <UserExpression>());
                }
                var o = UserDictionary[origin].FirstOrDefault(k => k.Expression == mine);
                if (o == null)
                {
                    UserDictionary[origin].Add(new UserExpression(mine));
                }
                else
                {
                    o.Times++;
                }
            }

            SaveSettings(UserDictionary);
            if (Count >= 30)
            {
                var sayRate = StaticRandom.NextDouble();
                var mark    = StaticRandom.NextDouble() <= 0.5 ? "?" : "";
                if (sayRate <= 0.5)
                {
                    var keys = UserDictionary.Keys.ToList();
                    var key  = keys[StaticRandom.Next(keys.Count)];
                    var list = UserDictionary[key];

                    if (key != Templates[0])
                    {
                        var nextRate = StaticRandom.NextDouble();
                        if (nextRate <= 0.5 && keys.Contains(Templates[0]))
                        {
                            var list2 = UserDictionary[Templates[0]];
                            message = routeMsg.ToSource(list[StaticRandom.Next(list.Count)].Expression + ", " +
                                                        list2[StaticRandom.Next(list2.Count)].Expression + mark);
                        }
                        else
                        {
                            message = routeMsg.ToSource(list[StaticRandom.Next(list.Count)].Expression + mark);
                        }
                    }
                    else
                    {
                        message = routeMsg.ToSource(list[StaticRandom.Next(list.Count)].Expression + mark);
                    }
                }
            }

            if (message == null)
            {
                return(null);
            }
            Thread.Sleep(StaticRandom.Next(0, 7000));
            return(message);
        }