Пример #1
0
        /// <summary>
        /// Load an instance by guild ID from the state files
        /// </summary>
        /// <param name="ID">guild ID</param>
        /// <param name="result">resulting state</param>
        /// <returns>Was the operation successful?</returns>
        public static bool Load(ulong ID, out AndroidState result)
        {
            result = default;
            var fullpath = GetPath(ID);

            if (!File.Exists(fullpath))
            {
                return(false);
            }

            var json = File.ReadAllText(fullpath);

            result = JsonConvert.DeserializeObject <AndroidState>(json, serializerSettings);

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Save an instance to the state files
        /// </summary>
        /// <param name="instance"></param>
        public static void Save(AndroidInstance instance)
        {
            if (!Directory.Exists(BasePath))
            {
                Directory.CreateDirectory(BasePath);
            }

            var path = GetPath(instance.GuildID);

            AndroidState state = new AndroidState
            {
                Listeners  = instance.Listeners,
                MutedUsers = instance.Moderation.MutesByUser,
                Active     = instance.Active
            };

            var json = JsonConvert.SerializeObject(state, serializerSettings);

            File.WriteAllText(path, json);
        }