コード例 #1
0
ファイル: Food.cs プロジェクト: Gtsz/Daylily
        public override CommonMessageResponse Message_Received(CommonMessage messageObj)
        {
            _cm = messageObj;
            string[] fullContent = ConcurrentFile.ReadAllLines(_content);

            if (EnabledAlbumId > 0 || DisabledAlbumId > 0)
            {
                return(_cm.PermissionLevel == PermissionLevel.Root
                    ? ModuleManageAlbum(fullContent)
                    : new CommonMessageResponse(LoliReply.RootOnly, _cm));
            }

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

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

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

            if (ClearCache)
            {
                ClearContent();
                return(new CommonMessageResponse("已重新建立缓存", _cm));
            }

            return(ModuleSearch(fullContent));
        }
コード例 #2
0
        private static string GetRandomPhoto(string dir)
        {
            string[] innerContent = ConcurrentFile.ReadAllLines(Path.Combine(dir, ".content"));
            string   innerChoice  = innerContent[StaticRandom.Next(0, innerContent.Length)];
            string   file         = Path.Combine(dir, innerChoice);

            return(file);
        }
コード例 #3
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));
        }
コード例 #4
0
        public ImageInfo(string source)
        {
            // TODO 这里还没考虑 file=base64:// 的情况
            const string file     = "file=";
            var          index    = source.IndexOf(file, StringComparison.Ordinal) + file.Length;
            var          index2   = source.IndexOf(",", index, StringComparison.Ordinal);
            string       fileName = source.Substring(index, index2 - index) + ".cqimg";
            string       fullPath = Path.Combine(CqCode.CqRoot, "data", "image", fileName);

            FileInfo = new FileInfo(fullPath);

            string[] settings;
            if (!FileInfo.Exists)
            {
                string tmp = AssistApi.GetImgFile(fileName);
                settings = tmp.Replace("\r", "").Trim('\n').Split('\n');
            }
            else
            {
                settings = ConcurrentFile.ReadAllLines(fullPath);
            }

            foreach (var line in settings)
            {
                string[] result = line.Split('=');
                if (result.Length < 2)
                {
                    continue;
                }

                var key   = result[0];
                var value = "";
                for (int i = 1; i < result.Length; i++)
                {
                    value += result[i] + "=";
                }
                value = value.Remove(value.Length - 1);
                switch (key)
                {
                case "md5":
                    Md5 = value;
                    break;

                case "width":
                    Width = int.Parse(value);
                    break;

                case "height":
                    Height = int.Parse(value);
                    break;

                case "size":
                    Size = long.Parse(value);
                    break;

                case "url":
                    Url = value;
                    break;

                case "addtime":
                    Addtime = new DateTime(1970, 1, 1).ToLocalTime().AddSeconds(int.Parse(value));
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }