コード例 #1
0
 public static void SetBotVar(BotVar var)
 {
     lock (savelock)
     {
         botVars[var.Identifier] = var;
         SetDirty();
     }
     handleBotVarUpdated(var);
 }
コード例 #2
0
 private static void handleBotVarUpdated(BotVar var)
 {
     if (onBotVarUpdated.TryGetValue(var.Identifier, out HashSet <BotVarUpdated> subscriberList))
     {
         foreach (BotVarUpdated updateHandler in subscriberList)
         {
             updateHandler.Invoke(var);
         }
     }
 }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
 /// <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));
     }
 }
コード例 #6
0
        /// <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);
        }
コード例 #7
0
 /// <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);
 }
コード例 #8
0
 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);
     //    }
     //}
 }
コード例 #9
0
        /// <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);
        }
コード例 #10
0
 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);
                 }
             }
         }
     }
 }
コード例 #11
0
 /// <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;
 }
コード例 #12
0
 /// <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);
 }
コード例 #13
0
 /// <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());
 }
コード例 #14
0
 /// <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);
 }
コード例 #15
0
 public static void SetDefault(string id, double var)
 {
     botVarDefaults[id] = new BotVar(id, var);
 }