Exemplo n.º 1
0
        private static Task SaveConfig(StreamerStatus cfgjson)
        {
            // first, let's load our configuration file

            //write string to file
            //await File.OpenWrite("configMAL.json");
            using (StreamWriter file = File.CreateText("twitch.json"))
            {
                JsonSerializer serializer = new JsonSerializer();
                //serialize object directly into file stream
                serializer.Serialize(file, cfgjson);
            }
            // first, let's load our configuration file
            // convert json to class
            // return
            // next, let's load the values from that file
            // to our client's configuration
            //var cfgjson = JsonConvert.DeserializeObject<ConfigMAL>(json);
            return(Task.CompletedTask);
        }
Exemplo n.º 2
0
        public static async Task RunBotAsync()
        {
            Console.Title = "Zerator Discord";

            var    cfg = new ConfigJson();
            string json;

            if (!File.Exists("config.json"))
            {
                json = JsonConvert.SerializeObject(cfg);
                File.WriteAllText("config.json", json, new UTF8Encoding(false));
                Console.WriteLine("Config file was not found, a new one was generated. Fill it with proper values and rerun this program");
                Console.ReadKey();

                return;
            }
            if (!File.Exists("member.json"))
            {
                var cfgProg = new ListMembers();
                json = JsonConvert.SerializeObject(cfgProg);
                File.WriteAllText("member.json", json, new UTF8Encoding(false));
                Console.WriteLine("member file was not found, a new one was generated.");
            }
            if (!File.Exists("prog.json"))
            {
                var cfgProg = new ProgJson();
                json = JsonConvert.SerializeObject(cfgProg);
                File.WriteAllText("prog.json", json, new UTF8Encoding(false));
                Console.WriteLine("prog file was not found, a new one was generated.");
            }
            if (!File.Exists("twitch.json"))
            {
                var cfgTwitch = new StreamerStatus();
                json = JsonConvert.SerializeObject(cfgTwitch);
                File.WriteAllText("twitch.json", json, new UTF8Encoding(false));
                Console.WriteLine("twitch file was not found, a new one was generated.");
            }
            if (!File.Exists("configMAL.json"))
            {
                var cfgTwitch = new Dictionary <string, string>(new Dictionary <string, string>());;
                json = JsonConvert.SerializeObject(cfgTwitch);
                File.WriteAllText("configMAL.json", json, new UTF8Encoding(false));
                Console.WriteLine("configMAL file was not found, a new one was generated.");
            }
            json = File.ReadAllText("config.json", new UTF8Encoding(false));
            cfg  = JsonConvert.DeserializeObject <ConfigJson>(json);


            var tskl = new List <Task>();

            for (var i = 0; i < cfg.ShardCount; i++)
            {
                var bot = new Bot(cfg, i);
                Shards.Add(bot);
                tskl.Add(bot.RunAsync());
                await Task.Delay(7500).ConfigureAwait(false);
            }

            await Task.WhenAll(tskl).ConfigureAwait(false);

            try
            {
                await Task.Delay(-1, CancelToken).ConfigureAwait(false);
            }
            catch (Exception) { /* shush */ }
        }