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
        private async Task MessageReceived(SocketMessage msg)
        {
            SocketUserMessage umsg = (SocketUserMessage)msg;

            if (msg == null)
            {
                return;
            }

            int argPos = 0;

            if (!umsg.HasCharPrefix(CommandPrefix, ref argPos))
            {
                return;
            }
            if (umsg.Author.IsBot)
            {
                return;
            }
            if (umsg.Author.IsWebhook)
            {
                return;
            }
            if (umsg.Channel is SocketDMChannel)
            {
                return;
            }

            var context = new SocketCommandContext(botUser, umsg);

            IResult commandResult = await commandService.ExecuteAsync(context, argPos, null);

            if (commandResult.Error.HasValue)
            {
                if (commandResult.Error.Value != CommandError.UnknownCommand)
                {
                    CVTS.WriteLineError(commandResult.ErrorReason);
                }
                else
                {
                    SharedBotInfo shared = SharedBotInfo.GetSharedInfo(context.Guild.Id);
                    if (shared != null)
                    {
                        try
                        {
                            CustomTwitchCommandInfo customCommand = shared.CustomCommands.First(x => x.Key.StartsWith(umsg.Content.Remove(0, 1)));
                            await context.Channel.SendMessageAsync(customCommand.Value);
                        }
                        catch { }
                    }
                }
            }
        }
 public void SaveSharedInfo()
 {
     CVTS.WriteLineShared($"Attempting to save shared info for discord guild ID {DiscordGuildId}...");
     if (!Directory.Exists(SharedInfoLocation))
     {
         CVTS.WriteLineShared($"Shared info directory not found! directory will now be created...");
         Directory.CreateDirectory(SharedInfoLocation);
     }
     try
     {
         File.WriteAllText(@$ "{SharedInfoLocation}\{DiscordGuildId}.json", JsonConvert.SerializeObject(this));
         CVTS.WriteLineOk($"Saved shared info successfully.");
     }
Exemple #4
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!");
 }
 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!");
 }
Exemple #6
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);
        }
Exemple #7
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 #8
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 #9
0
 public void Init()
 {
     CVTS.WriteLineDiscord("Initialising the Discord bot...");
     botUser.MessageReceived += MessageReceived;
     CVTS.WriteLineDiscord("Initialization of the Discord bot has completed!");
 }
Exemple #10
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.");
        }