示例#1
0
        private async Task CleanGuilds()
        {
            var settings = new JsonSerializerSettings
            {
                NullValueHandling     = NullValueHandling.Ignore,
                MissingMemberHandling = MissingMemberHandling.Ignore
            };

            Guilds guilds = JsonConvert.DeserializeObject <Guilds>(File.ReadAllText(FileDirUtil.JSONGUILDS), settings);

            if (guilds.guilds != null)
            {
                foreach (Guild guild in guilds.guilds)
                {
                    string startfile = FileDirUtil.GetGuildFile(guild.id, FileDirUtil.JSONSTART);
                    string stopfile  = FileDirUtil.GetGuildFile(guild.id, FileDirUtil.JSONSTOP);
                    if (File.Exists(startfile))
                    {
                        try
                        {
                            File.Delete(FileDirUtil.GetGuildFile(guild.id, FileDirUtil.JSONSTART));
                            Console.WriteLine("Cleaned up start files for " + guild.name);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("couldn't clean up start files " + e);
                        }
                    }
                    else
                    {
                        Console.WriteLine("no start file present, carry on");
                    }

                    if (File.Exists(stopfile))
                    {
                        try
                        {
                            File.Delete(FileDirUtil.GetGuildFile(guild.id, FileDirUtil.JSONSTOP));
                            Console.WriteLine("Cleaned up stop files for " + guild.name);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("couldn't clean up stop files " + e);
                        }
                    }
                    else
                    {
                        Console.WriteLine("no stop file present, carry on");
                    }
                }
            }
        }
示例#2
0
        private async Task JoinedGuild(SocketGuild guild)
        {
            Console.WriteLine("Entered guild ");
            var settings = new JsonSerializerSettings
            {
                NullValueHandling     = NullValueHandling.Ignore,
                MissingMemberHandling = MissingMemberHandling.Ignore
            };

            Guilds guilds = JsonConvert.DeserializeObject <Guilds>(File.ReadAllText(FileDirUtil.JSONGUILDS), settings);//checks json containing all guilds + their settings

            Console.WriteLine("got guilds json");
            string id   = guild.Id.ToString();
            string name = guild.Name;

            List <string> ids = guilds.GetIds();

            Console.WriteLine("Entered guild " + name + " " + id);
            //if this is a brand new guild
            if ((guilds.guilds == null) || !ids.Contains(id))
            {
                string guildpath   = FileDirUtil.GetGuildDir(id);
                string settingfile = Path.Combine(guildpath, FileDirUtil.JSONSETTINGS);

                Console.WriteLine("new guild!");

                Settings gdst = new Settings("!!", id, 0);
                Console.WriteLine("settings!");

                Guild newguilld = new Guild(id, name, DateTime.Now, DateTime.Now);    //create the new guild with info
                Console.WriteLine("newguild!");

                guilds.AddGuild(newguilld);
                Console.WriteLine("addedguild!");

                await FileDirUtil.EstablishGuildFiles(newguilld);

                Console.WriteLine("writing guilds back to file");
                JSONUtil.WriteJsonToFile(guilds, FileDirUtil.JSONGUILDS);
                JSONUtil.WriteJsonToFile(gdst, settingfile);
                Console.WriteLine("completed setting up for new guild!");
            }
            else
            {
                Console.WriteLine("existing guild");
                await FileDirUtil.VerifyGuildFiles(id);
            }
            //write back the json
        }