Пример #1
0
        public static async Task <LoadFileOperation> LoadToJSONObject(string path)
        {
            LoadFileOperation operation = new LoadFileOperation()
            {
                Success = false,
                Result  = null
            };

            if (File.Exists(path))
            {
                string fileContent = "";
                try
                {
                    fileContent = await File.ReadAllTextAsync(path, Encoding.UTF8);

                    operation.Result  = new JSONObject(fileContent);
                    operation.Success = true;
                    return(operation);
                }
                catch (Exception e)
                {
                    await BotCore.Logger(new Discord.LogMessage(Discord.LogSeverity.Critical, "Save/Load", "Failed to load " + path, e));
                }
            }
            return(operation);
        }
        public static async Task LoadMissionSettings()
        {
            LoadFileOperation operation = await ResourcesModel.LoadToJSONObject(ResourcesModel.MissionSettingsFilePath);

            if (operation.Success)
            {
                JSONObject json = operation.Result;
                json.GetField(ref lastMissionNumber, JSON_MISSIONNUMBER);
                string text = "";
                string jMissionCategoryID = "";
                json.GetField(ref jMissionCategoryID, JSON_MISSIONCATEGORYID);
                ulong.TryParse(jMissionCategoryID, out MissionCategoryId);
                if (json.GetField(ref text, JSON_DEFAULTTOPIC))
                {
                    DefaultTopic = text;
                }
                if (json.GetField(ref text, JSON_EXPLORERQUESTIONS))
                {
                    ExplorerQuestions = text;
                }
                if (json.GetField(ref text, JSON_TESTIMONIALPROMPT))
                {
                    TestimonialPrompt = text;
                }
                if (json.GetField(ref text, JSON_FILEREPORTPROMPT))
                {
                    FileReportPrompt = text;
                }
            }
        }
Пример #3
0
        public static async Task LoadMissions()
        {
            LoadFileOperation operation = await ResourcesModel.LoadToJSONObject(ResourcesModel.MissionsFilePath);

            if (operation.Success)
            {
                JSONObject json = operation.Result;
                if (json.IsArray)
                {
                    foreach (JSONObject jMission in json.list)
                    {
                        ulong nId;
                        if (ulong.TryParse(jMission.str, out nId))
                        {
                            missionList.Add(nId);
                        }
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Loads and applies Settings from appdata/locallow/Ciridium Wing Bot/Settings.json
        /// </summary>
        /// <returns></returns>
        private static async Task loadSettings()
        {
            LoadFileOperation operation = await ResourcesModel.LoadToJSONObject(ResourcesModel.SettingsFilePath);

            if (operation.Success)
            {
                JSONObject json = operation.Result;
                if (json.GetField(ref token, JSON_BOTTOKEN) && json.HasField(JSON_ADMINIDS))
                {
                    JSONObject botadmins = json[JSON_ADMINIDS];
                    if (botadmins.IsArray && botadmins.list != null)
                    {
                        foreach (var admin in botadmins.list)
                        {
                            ulong nID;
                            if (ulong.TryParse(admin.str, out nID))
                            {
                                botAdminIDs.Add(nID);
                            }
                        }
                    }
                    if (json.HasField(JSON_ENABLEDEBUG))
                    {
                        JSONObject debugSettings = json[JSON_ENABLEDEBUG];
                        if (debugSettings.IsArray)
                        {
                            for (int i = 0; i < debugSettings.list.Count; i++)
                            {
                                debugLogging[i] = debugSettings.list[i].b;
                            }
                        }
                    }
                    string id = "";
                    if (json.GetField(ref id, JSON_DEBUGCHANNEL))
                    {
                        ulong.TryParse(id, out DebugMessageChannelId);
                    }
                    if (json.GetField(ref id, JSON_WELCOMINGCHANNEL))
                    {
                        ulong.TryParse(id, out WelcomeMessageChannelId);
                    }
                    json.GetField(ref welcomingMessage, JSON_WELCOMINGMESSAGE);
                    if (json.GetField(ref id, JSON_MODERATORROLE))
                    {
                        ulong.TryParse(id, out ModeratorRole);
                    }
                    if (json.GetField(ref id, JSON_PILOTROLE))
                    {
                        ulong.TryParse(id, out EscortPilotRole);
                    }
                    if (json.GetField(ref id, JSON_BOTDEVROLE))
                    {
                        ulong.TryParse(id, out BotDevRole);
                    }
                    if (json.GetField(ref id, JSON_DISPATCHROLE))
                    {
                        ulong.TryParse(id, out DispatchRole);
                    }
                    json.GetField(ref Inara_APIkey, JSON_INARA_APIKEY);
                    string prefix_str = string.Empty;
                    if (json.GetField(ref prefix_str, JSON_PREFIX))
                    {
                        if (prefix_str.Length > 0)
                        {
                            CommandService.Prefix = prefix_str[0];
                        }
                    }
                }
            }
        }