Exemple #1
0
 public static Config LoadConfig()
 {
     CVTS.WriteLineInfo("Attempting to load program configuration file...");
     if (File.Exists(ConfigDir))
     {
         CVTS.WriteLineInfo($"{Path.GetFileName(ConfigDir)} found, will now attempt to load it.");
         try
         {
             var config = JsonConvert.DeserializeObject <Config>(File.ReadAllText(ConfigDir));
             CVTS.WriteLineOk($"{Path.GetFileName(ConfigDir)} loaded successfully!");
             return(config);
         }
         catch
         {
             CVTS.WriteLineError($"Failed to load {Path.GetFileName(ConfigDir)}! Please check for any errors and restart the application.");
             Console.ReadKey();
             Environment.Exit(0);
         }
     }
     else
     {
         CVTS.WriteLineError($"No config file found! A blank template under the name '{Path.GetFileName(ConfigDir)}' will be made in the application directory.");
         File.WriteAllText(ConfigDir, JsonConvert.SerializeObject(new Config(), Formatting.Indented));
         Console.ReadKey();
         Environment.Exit(0);
     }
     return(null);
 }
Exemple #2
0
 static void Main(string[] args)
 {
     // Enables Console Virtual Terminal Sequences
     CVTS.TryEnable();
     CVTS.WriteLineInfo($"{Process.GetCurrentProcess().ProcessName} version {Process.GetCurrentProcess().MainModule.FileVersionInfo.ProductVersion}, created by Jaika★.");
     // Download/reload Splatoon 2 data from the internet/local storage
     Data.LoadSplatoon2Data();
     // Load the config and shared info.
     Config = Config.LoadConfig();
     SharedBotInfo.LoadSharedInfo();
     SharedUserInfo.LoadUserInfo();
     // Initialise both bots
     DiscordBot.Init();
     TwitchBot.ChannelJoined += TwitchBot_ChannelJoined;
     TwitchBot.Connected     += TwitchBot_Connected;
     // Start both bots
     _ = DiscordBot.StartBot(Config.DiscordBotToken); // Needs discard token '_' since this function is asyncronous.
     _ = TwitchBot.Connect(Config.TwitchBotUsername, Config.TwitchOAuth2);
     // Sleep the thread indefinitely to stop it from closing.
     Thread.Sleep(-1);
 }
Exemple #3
0
        private static void DownloadSplatoon2Data()
        {
            CVTS.WriteLineInfo($"Downloading repository containing Splatoon 2 data from {s2DataUrl}...");
            try
            {
                string masterZipPath = $"{dataLocation}master.zip";
                webClient.DownloadFile(s2DataUrl, masterZipPath);
                CVTS.WriteLineOk($"Download succeeded, extracting data folder...");
                using (ZipArchive archive = ZipFile.OpenRead(masterZipPath))
                {
                    var result = from currEntry in archive.Entries
                                 where Path.GetDirectoryName(currEntry.FullName).Contains(@"leanny.github.io-master\data")
                                 where !string.IsNullOrEmpty(currEntry.Name)
                                 select currEntry;


                    foreach (ZipArchiveEntry entry in result)
                    {
                        string path = Path.Combine(dataLocation, entry.FullName.Replace(@"leanny.github.io-master/data/", null));
                        CVTS.WriteLineInfo($"Extracting {path}...");
                        if (!Directory.Exists(Path.GetDirectoryName(path)))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(path));
                        }
                        entry.ExtractToFile(path);
                    }
                }
                CVTS.WriteLineInfo($"Deleting master archive...");
                File.Delete(masterZipPath);
                CVTS.WriteLineOk($"Deletion successful!");
            }
            catch
            {
                CVTS.WriteLineError($"Download process failed to complete successfully!");
            }
        }
Exemple #4
0
        public static void LoadSplatoon2Data()
        {
            CVTS.WriteLineInfo($"Attempting to load Splatoon 2 data...");
            if (!Directory.Exists(dataLocation))
            {
                CVTS.WriteLineInfo("Splatoon 2 data not found! An attempt to download it will be made.");
                Directory.CreateDirectory(dataLocation);
                DownloadSplatoon2Data();
            }

            #region LOAD IN ALL THE DATA!
            // Load in each locale
            CVTS.WriteLineInfo("Loading in the en-us locale for Splatoon 2...");
            Locales[(int)LocaleSetting.English] = JsonConvert.DeserializeObject <Dictionary <string, string> >(File.ReadAllText(englishLocaleLocation));
            CVTS.WriteLineInfo("Loading in the de-eu locale for Splatoon 2...");
            Locales[(int)LocaleSetting.Deutsche] = JsonConvert.DeserializeObject <Dictionary <string, string> >(File.ReadAllText(germanLocaleLocation));
            CVTS.WriteLineInfo("Loading in the es-eu locale for Splatoon 2...");
            Locales[(int)LocaleSetting.Espanol] = JsonConvert.DeserializeObject <Dictionary <string, string> >(File.ReadAllText(spanishLocaleLocation));
            CVTS.WriteLineInfo("Loading in the fr-eu locale for Splatoon 2...");
            Locales[(int)LocaleSetting.Francais] = JsonConvert.DeserializeObject <Dictionary <string, string> >(File.ReadAllText(frenchLocaleLocation));
            CVTS.WriteLineInfo("Loading in the it-eu locale for Splatoon 2...");
            Locales[(int)LocaleSetting.Italiano] = JsonConvert.DeserializeObject <Dictionary <string, string> >(File.ReadAllText(italianLocaleLocation));
            CVTS.WriteLineInfo("Loading in the nl-eu locale for Splatoon 2...");
            Locales[(int)LocaleSetting.Nederlands] = JsonConvert.DeserializeObject <Dictionary <string, string> >(File.ReadAllText(dutchLocaleLocation));
            CVTS.WriteLineInfo("Loading in the ja-jp locale for Splatoon 2...");
            Locales[(int)LocaleSetting.Nihongo] = JsonConvert.DeserializeObject <Dictionary <string, string> >(File.ReadAllText(japaneseLocaleLocation));
            CVTS.WriteLineInfo("Loading in the ru-eu locale for Splatoon 2...");
            Locales[(int)LocaleSetting.Russkiy] = JsonConvert.DeserializeObject <Dictionary <string, string> >(File.ReadAllText(russianLocaleLocation));

            //#if DEBUG
            //            foreach (KeyValuePair<string, string> p in EnglishLocale)
            //                CVTS.WriteLine($"{p.Key,34}: {p.Value.Replace("\n", "\\n"),100}", Color.FromArgb(0x00, 0xFF, 0x00), "LOCALE");
            //#endif

            // Load in the main weapons
            MainWeapons = JsonConvert.DeserializeObject <List <MainWeaponInfo> >(File.ReadAllText(mainWeaponLocation));
#if DEBUG
            foreach (MainWeaponInfo m in MainWeapons)
            {
                CVTS.WriteLine($"{m.Name,30}: {m.GetName(LocaleSetting.English)}", Color.FromArgb(0xFF, 0x00, 0x99), "MAINWEPS");
            }
#endif

            // Load in the sub weapons
            SubWeapons = JsonConvert.DeserializeObject <List <SubWeaponInfo> >(File.ReadAllText(subWeaponLocation));
#if DEBUG
            foreach (SubWeaponInfo m in SubWeapons)
            {
                CVTS.WriteLine($"{m.Name,30}: {m.GetName(LocaleSetting.English)}", Color.FromArgb(0xFF, 0x77, 0x99), "SUBWEPS");
            }
#endif

            // Load in the special weapons
            SpecialWeapons = JsonConvert.DeserializeObject <List <SpecialWeaponInfo> >(File.ReadAllText(specialWeaponLocation));
#if DEBUG
            foreach (SpecialWeaponInfo m in SpecialWeapons)
            {
                CVTS.WriteLine($"{m.Name,30}: {m.GetName(LocaleSetting.English)}", Color.FromArgb(0xFF, 0xCC, 0x99), "SPECIALS");
            }
#endif
            #endregion

            // Check to see if any weapons have actually been loaded in.
            if (MainWeapons == null || MainWeapons.Count == 0)
            {
                CVTS.WriteLineWarn("No main weapons have been loaded, certain commands will not function correctly.");
            }
            if (SubWeapons == null || SubWeapons.Count == 0)
            {
                CVTS.WriteLineWarn("No sub weapons have been loaded, certain commands will not function correctly.");
            }
            if (SpecialWeapons == null || SpecialWeapons.Count == 0)
            {
                CVTS.WriteLineWarn("No special weapons have been loaded, certain commands will not function correctly.");
            }
            CVTS.WriteLineOk("Finished aquiring all Splatoon 2 data.");
        }