/// <summary> /// Set the condition named <paramref name="_conditionName"/> to the bool <paramref name="_value"/> in the current profile /// Then save it. /// </summary> /// <param name="_conditionName">Name of the condition to change</param> /// <param name="_value">New value of the condition</param> public static void SetConditionBoolValue(string _conditionName, bool _value) { string[] _conditions = m_dialogsSettings.LuaConditions.Split('\n'); string[] _variable; for (int i = 0; i < _conditions.Length; i++) { _variable = _conditions[i].Trim().Split('='); if (_variable[0].Trim() == _conditionName.Trim()) { _variable[1] = _value.ToString().ToLower(); _conditions[i] = _variable[0] + "=" + _variable[1] + ";"; break; } } string _temp = string.Empty; for (int i = 0; i < _conditions.Length; i++) { _temp += _conditions[i] + "\n"; } m_dialogsSettings.LuaConditions = _temp; SaveProfile(); OnSettingsModified?.Invoke(); }
public void ReadSettings(Reddit r) { var wiki = r.GetSubreddit(Subreddit).Wiki; WikiPage settingsPage; try { settingsPage = wiki.GetPage(WikiPageName); } catch (WebException ex) { if ((ex.Response as HttpWebResponse).StatusCode == HttpStatusCode.NotFound) { //Page doesn't exist, create it with defaults. CreateWikiPage(wiki); OnSettingsModified?.Invoke(this, EventArgs.Empty); return; } else if ((ex.Response as HttpWebResponse).StatusCode == HttpStatusCode.Unauthorized) { throw new Exception("Bot needs wiki permissions yo!"); } else //todo retry handling? { throw; } } if (string.IsNullOrEmpty(settingsPage.MarkdownContent)) { CreateWikiPage(wiki); OnSettingsModified?.Invoke(this, EventArgs.Empty); return; } if (settingsPage.RevisionDate != null && settingsPage.RevisionDate.Value > LastModified) { BotSettings sets; try { sets = JsonConvert.DeserializeObject <BotSettings>(settingsPage.MarkdownContent); } catch { throw new Exception("Wikipage is corrupted. Fix it, clear wiki page, or delete the page to recreate with defaults."); } Version = sets.Version; LastModified = settingsPage.RevisionDate.Value; RemoveScoreThreshold = sets.RemoveScoreThreshold; ReportScoreThreshold = sets.ReportScoreThreshold; RunEveryXMinutes = sets.RunEveryXMinutes; var addedDefaults = false; /***Module Defaults***/ if (sets.LicensingSmasher == null) { LicensingSmasher = new LicensingSmasherSettings(); addedDefaults = true; } else { LicensingSmasher = sets.LicensingSmasher; } if (sets.YouTubeSpamDetector == null) { YouTubeSpamDetector = new YouTubeSpamDetectorSettings(); addedDefaults = true; } else { YouTubeSpamDetector = sets.YouTubeSpamDetector; } if (sets.UserStalker == null) { UserStalker = new UserStalkerSettings(); addedDefaults = true; } else { UserStalker = sets.UserStalker; } if (sets.SelfPromotionCombustor == null) { SelfPromotionCombustor = new SelfPromotionCombustorSettings(); addedDefaults = true; } else { SelfPromotionCombustor = sets.SelfPromotionCombustor; } if (sets.HighTechBanHammer == null) { HighTechBanHammer = new HighTechBanHammerSettings(); addedDefaults = true; } else { HighTechBanHammer = sets.HighTechBanHammer; } /***End Module Defaults ***/ if (addedDefaults) { wiki.EditPage(WikiPageName, JsonConvert.SerializeObject(this, Formatting.Indented, new StringEnumConverter()).Replace("\r\n ", "\r\n\r\n "), reason: "Add module default"); LastModified = DateTime.UtcNow.AddMinutes(1); } Console.WriteLine("Settings in wiki changed or read for first time : Revision Date = {0}", LastModified); OnSettingsModified?.Invoke(this, EventArgs.Empty); } else { Console.WriteLine("No updates to settings detected in wiki"); } }
public static void SettingsChanged(object sender, string hidInstance, GamingPanelEnum gamingPanelEnum) { OnSettingsModified?.Invoke(sender, new PanelInfoArgs { HidInstance = hidInstance, PanelType = gamingPanelEnum }); }