public async Task RebuildIndex() { await Context.Channel.SendMessageAsync("**[Admin]** OK, building index"); // Create a dummy ContainerIndex using latest data ContainerIndex containerIndex = new ContainerIndex(); containerIndex.Event = StrippedContainer.ConvertToStrippedContainer(ContainerCache.GetEvents().First()); containerIndex.LineNews = StrippedContainer.ConvertToStrippedContainer(ContainerCache.GetLineNews().First()); containerIndex.PopUpNews = StrippedContainer.ConvertToStrippedContainer(ContainerCache.GetPopUpNews().First()); containerIndex.Present = StrippedContainer.ConvertToStrippedContainer(ContainerCache.GetPresents().First()); // Acquire the WebFileHandler lock lock (WebFileHandler.Lock) { // Connect WebFileHandler.Connect(((SsbuBotConfiguration)Configuration.LoadedConfiguration).WebConfig); // Write the file WebFileHandler.WriteAllText(((SsbuBotConfiguration)Configuration.LoadedConfiguration).WebConfig.ContainerIndexPath, WebFileHandler.ToJson(containerIndex)); // Disconnect WebFileHandler.Disconnect(); } await Context.Channel.SendMessageAsync("**[Admin]** Done"); }
public async Task RebuildList(string type) { await Context.Channel.SendMessageAsync("**[Admin]** OK, building list"); // Create a new StrippedContainer list List <StrippedContainer> containerList = new List <StrippedContainer>(); // Declare a variable to hold the path string indexPath = ((SsbuBotConfiguration)Configuration.LoadedConfiguration).WebConfig.ContainerListPath; switch (type) { case "event": ContainerCache.GetEvents().ForEach(x => containerList.Add(StrippedContainer.ConvertToStrippedContainer(x))); indexPath = string.Format(indexPath, "event"); break; case "linenews": ContainerCache.GetLineNews().ForEach(x => containerList.Add(StrippedContainer.ConvertToStrippedContainer(x))); indexPath = string.Format(indexPath, "line_news"); break; case "popupnews": ContainerCache.GetPopUpNews().ForEach(x => containerList.Add(StrippedContainer.ConvertToStrippedContainer(x))); indexPath = string.Format(indexPath, "popup_news"); break; case "present": ContainerCache.GetPresents().ForEach(x => containerList.Add(StrippedContainer.ConvertToStrippedContainer(x))); indexPath = string.Format(indexPath, "present"); break; default: throw new Exception("Invalid type (must be event, linenews, popupnews, or present)"); } // Acquire the WebFileHandler lock lock (WebFileHandler.Lock) { // Connect WebFileHandler.Connect(((SsbuBotConfiguration)Configuration.LoadedConfiguration).WebConfig); // Upload the file WebFileHandler.WriteAllText(indexPath, WebFileHandler.ToJson(containerList)); // Disconnect WebFileHandler.Disconnect(); } await Context.Channel.SendMessageAsync("**[Admin]** Done"); }
public static async Task ListContainers(FileType fileType, Language language, SocketCommandContext context) { // Create a list of IDs and their names List <string> ids = new List <string>(); switch (fileType) { case FileType.Event: foreach (Event smashEvent in ContainerCache.GetEvents()) { ids.Add($"``{smashEvent.Id}`` - {smashEvent.TitleText[language]}"); } break; case FileType.LineNews: foreach (LineNews lineNews in ContainerCache.GetLineNews()) { ids.Add($"``{lineNews.Id}``"); } break; case FileType.PopUpNews: // TODO: hack something better can be made, pages maybe? foreach (PopUpNews news in ContainerCache.GetPopUpNews().Where(x => !x.Id.Contains("_")).Take(10)) { ids.Add($"``{news.Id}`` - {news.TitleText[language]}"); } ids.Add("(only the 10 most recent Pop-Up News is displayed)"); break; case FileType.Present: foreach (Present present in ContainerCache.GetPresents()) { ids.Add($"``{present.Id}`` - {present.TitleText[language]}"); } break; default: throw new LocalizedException("list.unknown_file_type"); } Embed embed = new EmbedBuilder() .WithTitle(Localizer.Localize("list.title", language)) .WithDescription(Localizer.Localize("list.description", language) + string.Join('\n', ids) + "") .WithColor(Color.Green) .Build(); await context.Channel.SendMessageAsync(embed : embed); }
public async Task UploadCacheToS3() { await Context.Channel.SendMessageAsync("**[Admin]** OK, building list"); List <Container> allContainers = new List <Container>(); // Add all Containers to the List allContainers.AddRange(ContainerCache.GetEvents()); allContainers.AddRange(ContainerCache.GetLineNews()); allContainers.AddRange(ContainerCache.GetPopUpNews()); allContainers.AddRange(ContainerCache.GetPresents()); // Loop over every Container foreach (Container container in allContainers) { await Context.Channel.SendMessageAsync("**[Admin]** Uploading " + container.GetType().Name + " with ID " + container.Id); ContainerWebHandler.HandleContainer(container); } await Context.Channel.SendMessageAsync("**[Admin]** Done"); }
protected override async Task Run() { await DiscordBot.LoggingChannel.SendMessageAsync($"**[WebPConversionOneTimeTask]** Starting WebP image conversion"); List <Container> allContainers = new List <Container>(); // Add all Containers to the List allContainers.AddRange(ContainerCache.GetEvents()); allContainers.AddRange(ContainerCache.GetPopUpNews()); allContainers.AddRange(ContainerCache.GetPresents()); // Loop over every Container foreach (Container container in allContainers) { // Get the FileType FileType fileType = FileTypeExtensions.GetTypeFromContainer(container); // Format the destination S3 path string s3Path = $"/smash/{FileTypeExtensions.GetNamePrefixFromType(fileType)}/{container.Id}"; // Get the raw image byte[] jpgImage = (byte[])container.GetType().GetProperty("Image").GetValue(container); // Create a new MagickImage using (MagickImage image = new MagickImage(jpgImage)) { // Set the output format to WebP image.Format = MagickFormat.WebP; // Create the raw WebP byte[] webpImage = image.ToByteArray(); await DiscordBot.LoggingChannel.SendMessageAsync($"**[WebPConversionOneTimeTask]** Uploading image for {fileType.ToString()} ID {container.Id}"); // Upload to S3 S3Api.TransferFile(webpImage, s3Path, "image.webp", "image/webp"); } } }