Пример #1
0
        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");
        }
Пример #2
0
        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");
        }
Пример #3
0
        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);
        }
Пример #4
0
        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");
        }
Пример #5
0
        public async Task Execute()
        {
            if (Configuration.LoadedConfiguration.IsProduction)
            {
                return;
            }

            /*Event marioEvent = ContainerCache.GetEventWithId(1003);
             * string path = Path.Combine(Path.GetDirectoryName(Program.LOCAL_LAST_TOPIC), "debug-event.json");
             * File.WriteAllText(path, ToJson(marioEvent));*/
            //await Context.Channel.SendMessageAsync("test <:thonk:508037103473655831>");
            //throw new Exception("test exception");

            //TestMessage testMessage = new TestMessage(Context.User);
            //await DiscordBot.SendInteractiveMessageAsync(Context.Channel, testMessage);

            //RecurringHousekeepingJob job = new RecurringHousekeepingJob();
            //await job.Execute(null);

            //TwitterManager.GetAccount("SSBUBot").Tweet("[Test]", "test tweet from debug command", "URL: https://google.com");

            //LineNewsTwitterHandler.HandleAdded(ContainerCache.GetLineNews().Last());

            /*IList<PopUpNews> newsList = ContainerCache.GetPopUpNews();
             * PopUpNews longestNews = newsList.FirstOrDefault();
             * foreach (PopUpNews news in newsList)
             * {
             *  if (news.TitleText[Language.EnglishUS].Length > longestNews.TitleText[Language.EnglishUS].Length)
             *  {
             *      longestNews = news;
             *  }
             * }
             *
             * await Context.Channel.SendMessageAsync("[Debug] tweeting " + longestNews.Id);
             *
             * PopUpNewsTwitterHandler.HandleAdded(longestNews);*/

            /*IList<LineNews> newsList = ContainerCache.GetLineNews();
             *
             * LineNews longestNews = newsList.FirstOrDefault();
             * OneLine longestLine = longestNews.OneLines[0];
             *
             * foreach (LineNews news in newsList)
             * {
             *  foreach (OneLine line in news.OneLines)
             *  {
             *      if (line.Text[Language.EnglishUS].Length > longestLine.Text[Language.EnglishUS].Length)
             *      {
             *          longestNews = news;
             *          longestLine = line;
             *      }
             *  }
             * }
             *
             * await Context.Channel.SendMessageAsync("[Debug] line news " + longestNews.Id + ", oneline " + longestLine.Id + " is " + longestLine.Text[Language.EnglishUS].Length);*/

            await Context.Channel.SendMessageAsync("[Debug] Test tweets...");

            PopUpNewsTwitterHandler.HandleAdded(ContainerCache.GetPopUpNews().FirstOrDefault());
            PresentTwitterHandler.HandleAdded(ContainerCache.GetPresents().FirstOrDefault());
            LineNewsTwitterHandler.HandleAdded(ContainerCache.GetLineNews().FirstOrDefault());
        }