예제 #1
0
        public async Task AnnounceToChannel(string type, string id)
        {
            switch (type)
            {
            case "event":
                await EventDiscordHandler.HandleAdded(ContainerCache.GetEventWithId(id));

                break;

            case "linenews":
                await LineNewsDiscordHandler.HandleAdded(ContainerCache.GetLineNewsWithId(id));

                break;

            case "popupnews":
                await PopUpNewsDiscordHandler.HandleAdded(ContainerCache.GetPopUpNewsWithId(id));

                break;

            case "present":
                await PresentDiscordHandler.HandleAdded(ContainerCache.GetPresentWithId(id));

                break;

            default:
                throw new Exception("Invalid type (must be event, linenews, popupnews, or present)");
            }

            await Context.Channel.SendMessageAsync("**[Admin]** OK, notified");
        }
예제 #2
0
        public async Task Execute(string id = null, string languageString = null)
        {
            // Get the language
            Language language = DiscordUtil.GetDefaultLanguage(Context.Guild, languageString);

            // Check for no ID
            if (id == null)
            {
                await ListCommand.ListContainers(FileType.Present, language, Context);

                return;
            }

            // Get the Present with this ID
            Present present = ContainerCache.GetPresentWithId(id);

            // Check if this exists
            if (present == null)
            {
                throw new LocalizedException("present.not_found");
            }

            // Localize the description
            string localizedDescription = string.Format(Localizer.Localize("present.description", language), present.ContentText[language], $"https://smash.oatmealdome.me/present/{present.Id}/{language.GetCode()}/");

            // Construct the image URL
            string url = $"https://cdn.oatmealdome.me/smash/present/{present.Id}/image.jpg";

            // Construct the Embed
            Embed embed = new EmbedBuilder()
                          .WithTitle(present.TitleText[language])
                          .WithDescription(localizedDescription)
                          .AddField(Localizer.Localize("present.start_time", language), Localizer.LocalizeDateTime(present.StartDateTime, language), true)
                          .AddField(Localizer.Localize("present.end_time", language), Localizer.LocalizeDateTime(present.EndDateTime, language), true)
                          .WithImageUrl(url)
                          .Build();

            await Context.Channel.SendMessageAsync(embed : embed);
        }