예제 #1
0
파일: Config.cs 프로젝트: Jaika1/MizuiroBot
 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);
 }
예제 #2
0
 private static async Task TwitchBot_Connected(object sender)
 {
     CVTS.WriteLineTwitch("Joining all specified channels in shared channel info...");
     foreach (SharedBotInfo shared in SharedBotInfo.SharedInfo)
     {
         if (!string.IsNullOrWhiteSpace(shared.TwitchChannelName))
         {
             CVTS.WriteLineTwitch($"Joining {shared.TwitchChannelName}...");
             await TwitchBot.JoinChannel(shared.TwitchChannelName);
         }
         else
         {
             CVTS.WriteLineTwitch($"Channel not found in shared info.");
         }
     }
     CVTS.WriteLineOk("Twitch bot started successfully!");
 }
예제 #3
0
 public static void LoadSharedInfo()
 {
     CVTS.WriteLineShared($"Loading shared info from '{SharedInfoLocation}'...");
     if (!Directory.Exists(SharedInfoLocation))
     {
         CVTS.WriteLineShared($"Shared info directory not found! directory will now be created...");
         Directory.CreateDirectory(SharedInfoLocation);
     }
     else
     {
         foreach (string file in Directory.EnumerateFiles(SharedInfoLocation, "*.json", SearchOption.TopDirectoryOnly))
         {
             SharedBotInfo b = JsonConvert.DeserializeObject <SharedBotInfo>(File.ReadAllText(file));
             sharedInfoCollection.Add(b);
         }
     }
     CVTS.WriteLineOk($"Successfully loaded shared info for {sharedInfoCollection.Count} servers!");
 }
예제 #4
0
        public async Task StartBot(string botToken)
        {
            CVTS.WriteLineDiscord("Building command service...");
            await commandService.AddModulesAsync(Assembly.GetEntryAssembly(), null);

            CVTS.WriteLineDiscord("Attempting to login to discord with the specified bot token...");
            await botUser.LoginAsync(TokenType.Bot, botToken);

            CVTS.WriteLineDiscord("Login succesful, starting bot service...");
            await botUser.StartAsync();

            CVTS.WriteLineOk("Discord bot started successfully!");
#if DEBUG
            await botUser.SetStatusAsync(UserStatus.Idle);

            await botUser.SetGameAsync("Testing Mode");
#endif
            await Task.Delay(-1);
        }
예제 #5
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!");
            }
        }
예제 #6
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.");
        }