public static void SetBotVar(BotVar var) { lock (savelock) { botVars[var.Identifier] = var; SetDirty(); } handleBotVarUpdated(var); }
private static void handleBotVarUpdated(BotVar var) { if (onBotVarUpdated.TryGetValue(var.Identifier, out HashSet <BotVarUpdated> subscriberList)) { foreach (BotVarUpdated updateHandler in subscriberList) { updateHandler.Invoke(var); } } }
/// <summary> /// Sets or creates a generic config variable /// </summary> /// <param name="id">Identifier</param> /// <param name="value">Value to assign</param> public void SetBotVar(string id, JSONContainer value) { BotVar var = new BotVar(id, value); lock (savelock) { BotVars[id] = var; SetDirty(); } handleBotVarUpdated(var); }
/// <summary> /// Sets or creates a generic config variable /// </summary> /// <param name="id">Identifier</param> /// <param name="value">Value to assign</param> public void SetBotVar(string id, IGenericBotVar value) { BotVar var = new BotVar(id, value.ToJSON()); lock (savelock) { BotVars[id] = var; SetDirty(); } handleBotVarUpdated(var); }
/// <summary> /// Retrieves a config variable struct /// </summary> /// <param name="id">Identifier</param> /// <param name="var">Result</param> /// <returns>True, if either a variable or a default value was found</returns> public bool TryGetBotVar(string id, out BotVar var) { if (BotVars.TryGetValue(id, out var)) { return(true); } else { return(BotVarDefaults.TryGetValue(id, out var)); } }
/// <summary> /// Sets or creates a config variable of type boolean /// </summary> /// <param name="id">Identifier</param> /// <param name="value">Value to assign</param> public static void SetBotVar(string id, bool value) { BotVar var = new BotVar(id, value); lock (savelock) { botVars[id] = var; SetDirty(); } handleBotVarUpdated(var); }
/// <summary> /// Sets or creates a config variable /// </summary> /// <param name="id">Identifier</param> /// <param name="value">Value to assign</param> public void SetBotVar(BotVar var) { if (var.TypeNullTested == BotVarType.Undefined || var.TypeNullTested == BotVarType.Deleted) { throw new ArgumentNullException(nameof(var)); } lock (savelock) { BotVars[var.Identifier] = var; SetDirty(); } handleBotVarUpdated(var); }
private void handleBotVarUpdated(BotVar var) { if (onBotVarUpdated.TryGetValue(var.Identifier, out HashSet <BotVarUpdatedGuild> subscriberList)) { foreach (BotVarUpdatedGuild updateHandler in subscriberList) { updateHandler.Invoke(GuildID, var); } } //if (onBotVarUpdatedGuild.TryGetValue(var.Identifier, out HashSet<BotVarUpdatedGuild> guildSubscriberList)) //{ // foreach (BotVarUpdatedGuild updateHandler in guildSubscriberList) // { // updateHandler.Invoke(GuildID, var); // } //} }
/// <summary> /// Removes a bot variable /// </summary> /// <param name="id">Identifier</param> /// <returns>True, if a matching botvar was found</returns> public bool DeleteBotVar(string id) { bool removesuccess; lock (savelock) { removesuccess = BotVars.Remove(id); } if (!BotVarDefaults.TryGetValue(id, out BotVar def)) { def = new BotVar { Type = BotVarType.Deleted }; } handleBotVarUpdated(def); return(removesuccess); }
private void FromJSON(JSONContainer source) { BotVars.Clear(); if (source.IsArray) { foreach (JSONField jsonField in source.Array) { if (jsonField.IsObject) { BotVar var = new BotVar(); if (var.FromJSON(jsonField.Container)) { BotVars.Add(var.Identifier, var); handleBotVarUpdated(var); } } } } }
/// <summary> /// Sets a default bot variable /// </summary> /// <param name="id">Identifier</param> /// <param name="var">Value</param> public static void SetDefault(BotVar var) { BotVarDefaults[var.Identifier] = var; }
/// <summary> /// Sets a default bot variable of type generic as JSONContainer /// </summary> /// <param name="id">Identifier</param> /// <param name="var">Value</param> public static void SetDefault(string id, JSONContainer var) { BotVarDefaults[id] = new BotVar(id, var); }
/// <summary> /// Sets a default bot variable of type IGenericBotVar /// </summary> /// <param name="id">Identifier</param> /// <param name="var">Value</param> public static void SetDefault(string id, IGenericBotVar var) { BotVarDefaults[id] = new BotVar(id, var.ToJSON()); }
/// <summary> /// Sets a default bot variable of type boolean /// </summary> /// <param name="id">Identifier</param> /// <param name="var">Value</param> public static void SetDefault(string id, bool var) { BotVarDefaults[id] = new BotVar(id, var); }
public static void SetDefault(string id, double var) { botVarDefaults[id] = new BotVar(id, var); }