コード例 #1
0
        private Task OnGuildAvailable(SocketGuild arg)
        {
            if (AndroidInstances.TryGetValue(arg.Id, out var existing))
            {
                existing.Shutdown();
                AndroidInstances.Remove(arg.Id);
            }

            var instance = new AndroidInstance(arg.Id);

            if (AndroidStateSerialiser.Load(instance.GuildID, out var state))
            {
                foreach (var item in state.Listeners)
                {
                    item.Android = instance;
                    item.Initialise();
                }

                instance.Active = state.Active;
                instance.Listeners.AddRange(state.Listeners);
                instance.Moderation.MutesByUser = state.MutedUsers;
            }

            AndroidInstances.Add(arg.Id, instance);
            return(Task.CompletedTask);
        }
コード例 #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);
        }