コード例 #1
0
		private string GetDescription(RomType romType)
		{
			string description;

			if (descriptionCache.TryGetValue(romType, out description))
				return description;
			else
				return romType.ToString();
		}
コード例 #2
0
ファイル: FileCache.cs プロジェクト: OatmealDome/JelonzoBot
        public static void SetVersusSettingForRomType(RomType romType, VersusSetting versusSetting, byte[] rawSetting)
        {
            VersusSettings[romType] = versusSetting;

            // Construct the local path
            string localPath = string.Format(VERSUS_SETTING_PATH, romType.ToString());

            // Write out the file
            File.WriteAllBytes(localPath, rawSetting);
        }
コード例 #3
0
        public void MakeBooking(RomType romType, DateTime fraDato, int lengdePåOpphold)
        {
            var page = _webDriver.Navigate <NewBookingPage>();

            page.WaitUntilLoaded();

            page.RoomType.SelectFirstOptionThatContainsText(romType.ToString());
            page.FromDate.TypeDate(fraDato);
            page.Duration.TypeText(lengdePåOpphold);

            page.SaveButton.Click();
        }
コード例 #4
0
        private static string GetDescription(RomType romType)
        {
            string description;

            if (_descriptionCache.TryGetValue(romType, out description))
            {
                return(description);
            }
            else
            {
                return(romType.ToString());
            }
        }
コード例 #5
0
ファイル: FileCache.cs プロジェクト: OatmealDome/JelonzoBot
        public static void AddOrUpdateFestivalSetting(RomType romType, FestivalSetting festivalSetting, byte[] rawSetting)
        {
            // Check if this festival is already in the cache
            int idx = FestivalSettings[romType].FindIndex(x => x.FestivalId == festivalSetting.FestivalId);

            // Check if it hasn't been added
            if (idx == -1)
            {
                // Add it
                FestivalSettings[romType].Add(festivalSetting);
            }
            else
            {
                // Update the existing entry
                FestivalSettings[romType][idx] = festivalSetting;
            }

            // Construct the local path
            string localPath = string.Format(FESTIVAL_SETTING_PATH, romType.ToString(), festivalSetting.FestivalId);

            // Write out the file
            File.WriteAllBytes(localPath, rawSetting);
        }
コード例 #6
0
        public static Task HandleFestival(RomType romType, Dictionary <string, byte[]> data, FestivalSetting previousFestival, FestivalSetting newFestival, byte[] rawFile)
        {
            // Don't do anything
            if (previousFestival.FestivalId == newFestival.FestivalId)
            {
                return(Task.FromResult(0));
            }

            // Get the language based off the RomType
            Language language;

            switch (romType)
            {
            case RomType.NorthAmerica:
                language = Language.EnglishUS;
                break;

            case RomType.Europe:
                language = Language.EnglishUK;
                break;

            case RomType.Japan:
                language = Language.Japanese;
                break;

            default:
                throw new Exception("Unsupported RomType (A)");
            }

            // Create the title
            string localizedRomType = Localizer.Localize(string.Format("romtype.{0}", romType.ToString().ToLower()), language);
            string title            = string.Format(Localizer.Localize("festival.twitter.title", language), localizedRomType);

            // Create the description
            string localizedDescription = Localizer.Localize("festival.twitter.description", language);
            string startTime            = Localizer.LocalizeDateTime(newFestival.Times.Start, language);
            string endTime = Localizer.LocalizeDateTime(newFestival.Times.End, language);

            localizedDescription = string.Format(localizedDescription, newFestival.Teams[0].ShortName[language], newFestival.Teams[1].ShortName[language], startTime, endTime);

            // Get the region code based off the RomType
            string regionCode;

            switch (romType)
            {
            case RomType.NorthAmerica:
                regionCode = "na";
                break;

            case RomType.Europe:
                regionCode = "eu";
                break;

            case RomType.Japan:
                regionCode = "jp";
                break;

            default:
                throw new Exception("Unsupported RomType (B)");
            }

            // Create the URL
            string url = string.Format(Localizer.Localize("festival.twitter.url", language), regionCode);

            // Get the target Twitter account
            string targetAccount;

            if (Configuration.LoadedConfiguration.IsProduction)
            {
                if (romType == RomType.NorthAmerica || romType == RomType.Europe)
                {
                    targetAccount = "JelonzoBot";
                }
                else if (romType == RomType.Japan)
                {
                    targetAccount = "JelonzoBotJP";
                }
                else
                {
                    throw new Exception("Unsupported RomType (C)");
                }
            }
            else
            {
                targetAccount = "JelonzoTest";
            }

            // Get the image
            string imagePath = string.Format(FileCache.FESTIVAL_PANEL_PATH, romType.ToString(), newFestival.FestivalId);

            byte[] image = File.ReadAllBytes(imagePath);

            // Tweet
            TwitterManager.GetAccount(targetAccount).Tweet(title, localizedDescription, url, image);

            return(Task.FromResult(0));
        }
コード例 #7
0
        public static Task HandleFestival(RomType romType, Dictionary <string, byte[]> data, FestivalSetting previousFestival, FestivalSetting newFestival, byte[] rawFile)
        {
            // Check if this is the same
            if (previousFestival.FestivalId == newFestival.FestivalId)
            {
                //return Task.FromResult(0);
            }

            // Construct the path
            string s3Path = $"/splatoon/festival/{romType.ToString()}/{newFestival.FestivalId}";

            // Deserialize the FestivalSetting dynamically
            dynamic settingDynamic = ByamlLoader.GetByamlDynamic(rawFile);

            // Serialize the FestivalSetting to JSON
            string json = JsonConvert.SerializeObject(settingDynamic);

            // Upload to S3
            S3Api.TransferFile(Encoding.UTF8.GetBytes(json), s3Path, "setting.json", "application/json");

            // Load the panel texture file
            using (MemoryStream panelStream = new MemoryStream(data[FileType.FestivalPanelTexture.GetPath()]))
            {
                // Parse the BFRES
                ResFile panelRes = new ResFile(panelStream);

                // Load the BNTX
                using (MemoryStream bntxStream = new MemoryStream(panelRes.ExternalFiles[0].Data))
                {
                    // Parse the BNTX
                    BinaryTexture bt = new BinaryTexture(bntxStream);

                    // Decode the first texture
                    if (PixelDecoder.TryDecode(bt.Textures[0], out Bitmap Img))
                    {
                        // Open a destination MemoryStream
                        using (MemoryStream bitmapStream = new MemoryStream())
                        {
                            // Write the bitmap as a PNG to the MemoryStream
                            Img.Save(bitmapStream, ImageFormat.Png);

                            // Get the data
                            byte[] imageData = bitmapStream.ToArray();

                            // Upload to S3
                            S3Api.TransferFile(imageData, s3Path, "panel.png");

                            // Write to local
                            File.WriteAllBytes(string.Format(FileCache.FESTIVAL_PANEL_PATH, romType.ToString(), newFestival.FestivalId), imageData);
                        }
                    }
                }
            }

            lock (WebFileHandler.Lock)
            {
                // Get the WebConfig
                JelonzoBotWebConfig webConfig = ((JelonzoBotConfiguration)Configuration.LoadedConfiguration).WebConfig;

                // Connect to the remote server if needed
                WebFileHandler.Connect(webConfig);

                // Format the container list path
                string manifestPath = webConfig.LatestFestivalManifestPath;

                // Check if the file exists
                LatestFestivalManifest manifest;
                if (WebFileHandler.Exists(manifestPath))
                {
                    // Deserialize the manifest
                    manifest = WebFileHandler.ReadAllText <LatestFestivalManifest>(manifestPath);
                }
                else
                {
                    // Create a new manifest
                    manifest = new LatestFestivalManifest();
                    manifest.NorthAmerica = FileCache.GetLatestFestivalSettingForRomType(RomType.NorthAmerica).FestivalId;
                    manifest.Europe       = FileCache.GetLatestFestivalSettingForRomType(RomType.Europe).FestivalId;
                    manifest.Japan        = FileCache.GetLatestFestivalSettingForRomType(RomType.Japan).FestivalId;
                }

                // Update the manifest
                switch (romType)
                {
                case RomType.NorthAmerica:
                    manifest.NorthAmerica = newFestival.FestivalId;
                    break;

                case RomType.Europe:
                    manifest.Europe = newFestival.FestivalId;
                    break;

                case RomType.Japan:
                    manifest.Japan = newFestival.FestivalId;
                    break;

                default:
                    throw new Exception("Invalid RomType");
                }

                // Upload the manifest
                WebFileHandler.WriteSerializedJson(manifestPath, manifest);

                // Get the FestivalSetting JSON path
                string path = webConfig.FestivalSettingPath;
                switch (romType)
                {
                case RomType.NorthAmerica:
                    path = string.Format(path, "na");
                    break;

                case RomType.Europe:
                    path = string.Format(path, "eu");
                    break;

                case RomType.Japan:
                    path = string.Format(path, "jp");
                    break;

                default:
                    throw new Exception("Invalid RomType");
                }

                // Upload to the server
                WebFileHandler.WriteAllText(path, json);

                // Disconnect
                WebFileHandler.Disconnect();
            }

            return(Task.FromResult(0));
        }
コード例 #8
0
 public static async Task HandleVersus(RomType romType, Dictionary <string, byte[]> data, VersusSetting previousSetting, VersusSetting newSetting, byte[] rawFile)
 {
     await DiscordBot.LoggingChannel.SendMessageAsync($"**[VS] <@{Configuration.LoadedConfiguration.DiscordConfig.AdministratorIds[0]}> Settings for {romType.ToString()} updated.");
 }
コード例 #9
0
        public static string ConvertFile(string InFilePath, string OutDirPath, RomType OutFileType)
        {
            Debug.WriteLine("Converting n64 Roms from [n64,v64,z64] to [n64,v64,z64]");
            try {
                var OutFileName = OutDirPath + "\\" + Path.GetFileNameWithoutExtension(new FileInfo(InFilePath).ToString()) + "." + OutFileType.ToString();

                if (InFilePath == OutFileName)
                {
                    return(InFilePath);
                }

                //Just be sure we don't try to read a huge file into memory. (Max File size is 128MB)
                if (new FileInfo(InFilePath).Length > 134217728)
                {
                    throw new Exception("File too large");
                }
                else
                {
                    using (FileStream infs = File.OpenRead(InFilePath))
                    {
                        if (File.Exists(OutFileName))
                        {
                            Debug.WriteLine("Overwriting File " + OutFileName);
                        }

                        using (FileStream outfs = File.Create(OutFileName))
                        {
                            //Read input File;
                            byte[] inBuffer = new byte[(int)infs.Length];
                            infs.Read(inBuffer, 0, (int)infs.Length);

                            //get file header type
                            infs.Seek(0, SeekOrigin.Begin);

                            RomType romHeader   = 0;
                            byte[]  headerArray = new byte[4];
                            infs.Read(headerArray, 0, 4);
                            if (BitConverter.IsLittleEndian)
                            {
                                Array.Reverse(headerArray);
                            }
                            romHeader = (RomType)Enum.ToObject(typeof(RomType), BitConverter.ToUInt32(headerArray, 0));

                            infs.Seek(0, SeekOrigin.Begin);

                            //get the right format of the original ROM
                            switch (romHeader)
                            {
                            case RomType.n64:
                                switch (OutFileType)
                                {
                                case RomType.n64:
                                    //nothing to do here
                                    break;

                                case RomType.v64:
                                    wordSwap(dWordSwap(inBuffer));
                                    break;

                                case RomType.z64:
                                    dWordSwap(inBuffer);
                                    break;

                                default:
                                    break;
                                }
                                break;

                            case RomType.z64:
                                switch (OutFileType)
                                {
                                case RomType.n64:
                                    dWordSwap(inBuffer);
                                    break;

                                case RomType.v64:
                                    wordSwap(inBuffer);
                                    break;

                                case RomType.z64:
                                    //nothing to do here
                                    break;

                                default:
                                    break;
                                }
                                break;

                            case RomType.v64:
                                switch (OutFileType)
                                {
                                case RomType.n64:
                                    dWordSwap(wordSwap(inBuffer));
                                    break;

                                case RomType.v64:
                                    //nothing to do here
                                    break;

                                case RomType.z64:
                                    wordSwap(inBuffer);
                                    break;

                                default:
                                    break;
                                }
                                break;

                            default:
                                throw new Exception("Unrecognised File");
                            }


                            outfs.Write(inBuffer, 0, inBuffer.Length);
                        }
                    }
                }

                Debug.WriteLine("finished conversion");
                return(OutFileName);
            } catch (Exception e) {
                Debug.WriteLine(e);
            }
            return("");
        }
コード例 #10
0
        public static async Task HandleFestival(RomType romType, Dictionary <string, byte[]> data, FestivalSetting previousFestival, FestivalSetting newFestival, byte[] rawFile)
        {
            // Don't do anything
            if (previousFestival.FestivalId == newFestival.FestivalId)
            {
                return;
            }

            // Get the Color for the neutral team
            System.Drawing.Color drawingColor = newFestival.Teams[2].GetColor4fAsColor();

            // Localize the times
            Dictionary <Language, string> startTime = Localizer.LocalizeDateTimeToAllLanguages(newFestival.Times.Start);
            Dictionary <Language, string> endTime   = Localizer.LocalizeDateTimeToAllLanguages(newFestival.Times.End);

            // Create the format parameters
            Dictionary <Language, object[]> formatParams = new Dictionary <Language, object[]>();

            foreach (Language language in BlitzUtil.SupportedLanguages)
            {
                formatParams[language] = new object[] { startTime[language], endTime[language] };
            }

            // Format the final string
            Dictionary <Language, string> periodStr = Localizer.LocalizeToAllLanguagesWithFormat("festival.period_format", BlitzUtil.SupportedLanguages, formatParams);

            Dictionary <Language, string> AddMissingLocalizations(Dictionary <Language, string> originalDict)
            {
                // Add any missing strings for team alpha
                Dictionary <Language, string> names = new Dictionary <Language, string>();

                foreach (Language language in BlitzUtil.SupportedLanguages)
                {
                    // Try getting the name from the original dictionary
                    if (originalDict.TryGetValue(language, out string name))
                    {
                        names.Add(language, $"**{name}**");
                    }
                    else
                    {
                        // Use the RomType to get the name
                        switch (romType)
                        {
                        case RomType.NorthAmerica:
                            names.Add(language, $"**{originalDict[Language.EnglishUS]}**");
                            break;

                        case RomType.Europe:
                            names.Add(language, $"**{originalDict[Language.EnglishUK]}**");
                            break;

                        case RomType.Japan:
                            names.Add(language, $"**{originalDict[Language.Japanese]}**");
                            break;

                        default:
                            throw new Exception("Unsupported RomType");
                        }
                    }
                }

                return(names);
            }

            // Add any missing strings for the teams
            Dictionary <Language, string> alphaNames = AddMissingLocalizations(newFestival.Teams[0].Name);
            Dictionary <Language, string> bravoNames = AddMissingLocalizations(newFestival.Teams[1].Name);

            // Localize the RomType
            Dictionary <Language, string> localizedRomType = Localizer.LocalizeToAllLanguages($"romtype.{romType.ToString().ToLower()}");

            // Use the special title if necessary
            Dictionary <Language, string> localizedTitle;

            if (newFestival.SpecialType != null)
            {
                // Localize the special type
                Dictionary <Language, string> localizedSpecialTypes = Localizer.LocalizeToAllLanguages($"festival.special_type.{newFestival.SpecialType.ToLower()}");

                // Create the format parameters
                formatParams = new Dictionary <Language, object[]>();
                foreach (Language language in BlitzUtil.SupportedLanguages)
                {
                    formatParams[language] = new object[] { localizedRomType[language], localizedSpecialTypes[language] };
                }

                // Localize the title
                localizedTitle = Localizer.LocalizeToAllLanguagesWithFormat("festival.title_special", BlitzUtil.SupportedLanguages, formatParams);
            }
            else
            {
                // Create the format parameters
                formatParams = new Dictionary <Language, object[]>();
                foreach (Language language in BlitzUtil.SupportedLanguages)
                {
                    formatParams[language] = new object[] { localizedRomType[language] };
                }

                // Localize the title
                localizedTitle = Localizer.LocalizeToAllLanguagesWithFormat("festival.title", BlitzUtil.SupportedLanguages, formatParams);
            }

            // Start building the embed
            LocalizedEmbedBuilder embedBuilder = new LocalizedEmbedBuilder(BlitzUtil.SupportedLanguages)
                                                 .WithTitle(localizedTitle)
                                                 .AddField("festival.team_alpha", alphaNames, true)
                                                 .AddField("festival.team_bravo", bravoNames, true)
                                                 .AddField("festival.rule", BlitzLocalizer.LocalizeRuleToAllLanguages(newFestival.VersusRule), true)
                                                 .AddField("festival.special_stage", BlitzLocalizer.LocalizeStageToAllLanguages(newFestival.SpecialStage), true)
                                                 .AddField("festival.announcement_time", Localizer.LocalizeDateTimeToAllLanguages(newFestival.Times.Announcement))
                                                 .AddField("festival.period", periodStr)
                                                 .AddField("festival.results_time", Localizer.LocalizeDateTimeToAllLanguages(newFestival.Times.Result))
                                                 .WithImageUrl($"https://cdn.oatmealdome.me/splatoon/festival/{romType.ToString()}/{newFestival.FestivalId}/panel.png")
                                                 .WithColor(new Color(drawingColor.R, drawingColor.G, drawingColor.B));

            // Send the notification
            await DiscordBot.SendNotificationAsync("**[Splatfest]**", embedBuilder.Build());
        }