示例#1
0
        private static bool LoadConfig()
        {
            var file = Domain.ConfigFile;

            if (!File.Exists(file))
            {
                AppSettings.CreateNewConfig();
            }
            else
            {
                try
                {
                    var content = ConcurrentFile.ReadAllText(file);
                    AppSettings.Load(JsonConvert.DeserializeObject <AppSettings>(content));
                }
                catch (JsonException e)
                {
                    var result = MessageBox.Show(@"载入配置文件时失败,用默认配置覆盖继续打开吗?\r\n" + e.Message,
                                                 "Osu Player", MessageBoxButton.YesNo, MessageBoxImage.Question);
                    if (result == MessageBoxResult.Yes)
                    {
                        AppSettings.CreateNewConfig();
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
示例#2
0
        protected virtual T LoadSettings <T>(string fileName = null, bool writeLog = false)
        {
            try
            {
                Type clsT = typeof(T);

                string saveName = Path.Combine(SettingsPath, (fileName ?? clsT.Name) + ".json");

                if (!Directory.Exists(SettingsPath))
                {
                    Directory.CreateDirectory(SettingsPath);
                }

                string json = ConcurrentFile.ReadAllText(saveName);
                if (writeLog)
                {
                    var fileInfo = new FileInfo(saveName);
                    Logger.Success($"Loaded settings from \"{Path.Combine("~", fileInfo.Directory?.Name, fileInfo.Name)}\".");
                }

                return(Newtonsoft.Json.JsonConvert.DeserializeObject <T>(json));
            }
            catch (FileNotFoundException)
            {
                return(default);
示例#3
0
        private static void LoadExtend()
        {
            if (!Directory.Exists(ExtendedDir))
            {
                Directory.CreateDirectory(ExtendedDir);
            }

            foreach (var dir in Directory.GetDirectories(ExtendedDir))
            {
                string metaFile = Path.Combine(dir, "metadata.json");
                if (!File.Exists(metaFile))
                {
                    Logger.Error(dir + "内未包含metadata.json");
                    continue;
                }
                Logger.Info("已发现 " + new DirectoryInfo(dir).Name);

                string     json       = ConcurrentFile.ReadAllText(metaFile);
                ExtendMeta extendMeta = JsonConvert.DeserializeObject <ExtendMeta>(json);

                ExtendPlugin extendPlugin = new ExtendPlugin()
                {
                    Program  = extendMeta.Program,
                    File     = new FileInfo(Path.Combine(dir, extendMeta.File)).FullName,
                    Name     = extendMeta.Name,
                    Author   = extendMeta.Author,
                    Major    = extendMeta.Major,
                    Minor    = extendMeta.Minor,
                    Patch    = extendMeta.Patch,
                    State    = extendMeta.State,
                    Helps    = extendMeta.Help,
                    Commands = extendMeta.Command,
                };

                if (extendPlugin.Commands.Length != 0)
                {
                    foreach (var item in extendPlugin.Commands)
                    {
                        CommandMap.TryAdd(item, extendPlugin.GetType());
                        CommandMapStatic.TryAdd(item, extendPlugin);
                    }
                    Logger.Origin($"命令 \"{extendMeta.Name}\" ({string.Join(',', extendPlugin.Commands)}) 已经加载完毕。");
                }
                else
                {
                    Logger.Warn($"\"{extendMeta.Name}\"尚未设置命令,因此无法被用户激活。");
                    Logger.Origin($"命令 \"{extendMeta.Name}\" 已经加载完毕。");
                }
            }
        }
示例#4
0
        protected T LoadSettings <T>(string fileName = null)
        {
            try
            {
                Type clsT = typeof(T);

                string saveName = Path.Combine(SettingsPath, (fileName ?? clsT.Name) + ".json");

                if (!Directory.Exists(SettingsPath))
                {
                    Directory.CreateDirectory(SettingsPath);
                }

                string json = ConcurrentFile.ReadAllText(saveName);
                return(Newtonsoft.Json.JsonConvert.DeserializeObject <T>(json));
            }
            catch (FileNotFoundException)
            {
                return(default);
示例#5
0
        public static void LoadSecret()
        {
            var    file = new FileInfo(Path.Combine(Domain.SecretPath, "secret.json"));
            string json;
            Secret secret;

            if (!file.Exists)
            {
                secret = new Secret();
                json   = Newtonsoft.Json.JsonConvert.SerializeObject(secret);
                ConcurrentFile.WriteAllText(file.FullName, json.ToJsonFormat());

                Logger.Error("请完善secret配置。");
                Console.ReadKey();
                Environment.Exit(0);
            }

            json   = ConcurrentFile.ReadAllText(file.FullName);
            secret = Newtonsoft.Json.JsonConvert.DeserializeObject <Secret>(json);

            // 读设置
            DbHelper.ConnectionString.Add("cabbage", secret.ConnectionStrings.DefaultConnection);
            DbHelper.ConnectionString.Add("daylily", secret.ConnectionStrings.MyConnection);

            OsuApiConfig.ApiKey   = secret.OsuSettings.ApiKey;
            OsuApiConfig.UserName = secret.OsuSettings.UserName;
            OsuApiConfig.Password = secret.OsuSettings.Password;

            Signature.AppId      = secret.CosSettings.AppId;
            Signature.SecretId   = secret.CosSettings.SecretId;
            Signature.SecretKey  = secret.CosSettings.SecretKey;
            Signature.BucketName = secret.CosSettings.BucketName;

            CoolQHttpApiClient.ApiUrl       = secret.BotSettings.PostUrl;
            CoolQCode.CqPath                = secret.BotSettings.CqDir;
            DaylilyCore.Current.CommandFlag = secret.BotSettings.CommandFlag;

            TuLingSecret.ApiKeys = secret.TuLingSettings.ApiKey;
        }
示例#6
0
        private static bool LoadConfig()
        {
            var file = Domain.ConfigFile;

            if (!File.Exists(file))
            {
                AppSettings.CreateNewConfig();
            }
            else
            {
                try
                {
                    var content = ConcurrentFile.ReadAllText(file);
                    AppSettings.Load(JsonConvert.DeserializeObject <AppSettings>(content,
                                                                                 new JsonSerializerSettings
                    {
                        TypeNameHandling = TypeNameHandling.Auto
                    }
                                                                                 )
                                     );
                }
                catch (JsonException ex)
                {
                    var result = MessageBox.Show("载入配置文件时失败,用默认配置覆盖继续打开吗?" + Environment.NewLine + ex.Message,
                                                 "Osu Player", MessageBoxButton.YesNo, MessageBoxImage.Question);
                    if (result == MessageBoxResult.Yes)
                    {
                        AppSettings.CreateNewConfig();
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
示例#7
0
文件: Help.cs 项目: Gtsz/Daylily
        public override CommonMessageResponse Message_Received(CommonMessage messageObj)
        {
            _cm = messageObj;
            if (UseList)
            {
                return(new CommonMessageResponse(ShowList(), _cm));
            }
            if (CommandName == null)
            {
                using (Session session = new Session(20000, _cm.Identity, _cm.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(new CommonMessageResponse(msg, _cm));
                    try
                    {
                        var a = dic.Select(k => k.Key).ToArray();

                        CommonMessage cm;
                        do
                        {
                            cm = session.GetMessage();
                            if (cm.Message.Contains("你是谁"))
                            {
                                return(new CommonMessageResponse(
                                           new FileImage(Path.Combine(StaticDir, "help.jpg")).ToString(), _cm));
                            }
                            if (cm.Message.Contains("基础帮助"))
                            {
                                if (cm.MessageType == MessageType.Private)
                                {
                                    return(new CommonMessageResponse(
                                               ConcurrentFile.ReadAllText(Path.Combine(StaticDir, "common.txt")), _cm));
                                }
                                SendMessage(new CommonMessageResponse("已发送至私聊,请查看。", _cm, true));
                                SendMessage(new CommonMessageResponse(
                                                ConcurrentFile.ReadAllText(Path.Combine(StaticDir, "common.txt")),
                                                new Identity(_cm.UserId, MessageType.Private)));
                                return(null);
                            }

                            if (cm.Message.Contains("查列表"))
                            {
                                return(new CommonMessageResponse(ShowList(), _cm));
                            }
                            SendMessage(new CommonMessageResponse("请回复大括号内的文字。", _cm));
                        } while (!a.Contains(cm.Message));

                        return(new CommonMessageResponse(ShowList(), _cm));
                    }
                    catch (TimeoutException)
                    {
                        return(new CommonMessageResponse("没人鸟我,走了.jpg", _cm));
                    }
                }
            }
            else
            {
                return(new CommonMessageResponse(ShowDetail().Trim('\n').Trim('\r'), _cm));
            }
        }
示例#8
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());
        }