예제 #1
0
        public SaveDiscordServer LoadData()
        {
            if (File.Exists("DiscordServerFiles/" + _guild.Id + ".json"))
            {
                String            JSONstring = File.ReadAllText("DiscordServerFiles/" + _guild.Id + ".json");
                SaveDiscordServer save       = JsonConvert.DeserializeObject <SaveDiscordServer>(JSONstring);
                if (save != null)
                {
                    discordServerSave = save;
                    if (save.WelcomeChannel != null)
                    {
                        WelcomeChannel = Guild.GetChannel(ulong.Parse(save.WelcomeChannel));
                    }
                    if (save.WelcomeRole != null)
                    {
                        WelcomeRole = Guild.GetRole(ulong.Parse(save.WelcomeRole));
                    }
                    if (save.swearJar != null)
                    {
                        swearJar = save.swearJar;
                    }
                    if (save.Users != null)
                    {
                        Users = save.Users;
                    }
                    if (save.voiceChannelRoles != null)
                    {
                        voiceChannelRoles = save.voiceChannelRoles;
                    }

                    if (save.lootItems != null)
                    {
                        lootItems = save.lootItems;
                    }

                    minimumBetPoints = save.minimumBetPoints;

                    return(save);
                }
            }
            return(null);
        }
예제 #2
0
        public void SaveData()
        {
            discordServerSave = new SaveDiscordServer(this);

            string outputJSON = JsonConvert.SerializeObject(discordServerSave);

            string jsonFormatted = JToken.Parse(outputJSON).ToString(Formatting.Indented);

            FileStream stream = null;

            if (!Directory.Exists("DiscordServerFiles/"))
            {
                Directory.CreateDirectory("DiscordServerFiles/");
            }
            if (!File.Exists("DiscordServerFiles/" + _guild.Id + ".json"))
            {
                stream = File.Create("DiscordServerFiles/" + _guild.Id + ".json");
            }
            if (stream != null)
            {
                stream.Close();
            }
            File.WriteAllText("DiscordServerFiles/" + _guild.Id + ".json", jsonFormatted);
        }