예제 #1
0
        public override ValueTask <TypeParserResult <DiscordColor> > ParseAsync(Parameter parameter, string value, RiasCommandContext context)
        {
            var hex = RiasUtilities.HexToInt(value);

            if (hex.HasValue)
            {
                return(TypeParserResult <DiscordColor> .Successful(new DiscordColor(hex.Value)));
            }

            var color = default(System.Drawing.Color);

            if (Enum.TryParse <System.Drawing.KnownColor>(value.Replace(" ", string.Empty), true, out var knownColor))
            {
                color = System.Drawing.Color.FromKnownColor(knownColor);
            }

            if (!color.IsEmpty)
            {
                return(TypeParserResult <DiscordColor> .Successful(new DiscordColor(color.R, color.G, color.B)));
            }

            var localization = context.Services.GetRequiredService <Localization>();

            return(TypeParserResult <DiscordColor> .Failed(localization.GetText(context.Guild?.Id, Localization.TypeParserInvalidColor)));
        }
예제 #2
0
            public async Task MangaAsync([Remainder] string title)
            {
                var(type, method) = int.TryParse(title, out _) ? ("Int", "id") : ("String", "search");
                var query = AnimeService.MangaQuery.Replace("[type]", type)
                            .Replace("[var]", method);

                var manga = await Service.GetAniListInfoAsync <AnimeMangaContent>(query, new { manga = title }, "Media");

                if (manga is null)
                {
                    await ReplyErrorAsync(Localization.SearchesMangaNotFound);

                    return;
                }

                var description = new StringBuilder(manga.Description);

                if (!string.IsNullOrEmpty(manga.Description))
                {
                    description.Replace("<br>", "");
                    description.Replace("<i>", "");
                    description.Replace("</i>", "");
                }

                if (description.Length == 0)
                {
                    description.Append('-');
                }

                var startDate = "-";

                if (manga.StartDate.Year.HasValue && manga.StartDate.Month.HasValue && manga.StartDate.Day.HasValue)
                {
                    startDate = new DateTime(manga.StartDate.Year.Value, manga.StartDate.Month.Value, manga.StartDate.Day.Value)
                                .ToString("MMM dd, yyyy", CultureInfo.InvariantCulture);
                }

                var endDate = "-";

                if (manga.EndDate.Year.HasValue && manga.EndDate.Month.HasValue && manga.EndDate.Day.HasValue)
                {
                    endDate = new DateTime(manga.EndDate.Year.Value, manga.EndDate.Month.Value, manga.EndDate.Day.Value)
                              .ToString("MMM dd, yyyy", CultureInfo.InvariantCulture);
                }

                var synonyms = manga.Synonyms != null
                    ? manga.Synonyms.Length != 0
                        ? string.Join("\n", manga.Synonyms)
                        : "-"
                    : "-";

                var genres = manga.Genres != null
                    ? manga.Genres.Length != 0
                        ? string.Join("\n", manga.Genres)
                        : "-"
                    : "-";

                var embed = new DiscordEmbedBuilder
                {
                    Color       = RiasUtilities.HexToInt(manga.CoverImage.Color) ?? RiasUtilities.ConfirmColor,
                    Url         = manga.SiteUrl,
                    Title       = $"{(string.IsNullOrEmpty(manga.Title.Romaji) ? manga.Title.English : manga.Title.Romaji)} (AniList)",
                    Description = $"{description.ToString().Truncate(1900)} [{GetText(Localization.CommonMore).ToLowerInvariant()}]({manga.SiteUrl})"
                }.AddField(GetText(Localization.SearchesTitleRomaji), !string.IsNullOrEmpty(manga.Title.Romaji) ? manga.Title.Romaji : "-", true)
                .AddField(GetText(Localization.SearchesTitleEnglish), !string.IsNullOrEmpty(manga.Title.English) ? manga.Title.English : "-", true)
                .AddField(GetText(Localization.SearchesTitleNative), !string.IsNullOrEmpty(manga.Title.Native) ? manga.Title.Native : "-", true)
                .AddField(GetText(Localization.CommonId), manga.Id.ToString(), true)
                .AddField(GetText(Localization.SearchesFormat), !string.IsNullOrEmpty(manga.Format) ? manga.Format : "-", true)
                .AddField(GetText(Localization.SearchesChapters), manga.Chapters.HasValue ? manga.Chapters.Value.ToString() : "-", true)
                .AddField(GetText(Localization.SearchesVolumes), manga.Volumes.HasValue ? manga.Volumes.Value.ToString() : "-", true)
                .AddField(GetText(Localization.UtilityStatus), !string.IsNullOrEmpty(manga.Status) ? manga.Status : "-", true)
                .AddField(GetText(Localization.SearchesStartDate), startDate, true)
                .AddField(GetText(Localization.SearchesEndDate), endDate, true)
                .AddField(GetText(Localization.SearchesAverageScore), manga.AverageScore.HasValue ? manga.AverageScore.Value.ToString() : "-", true)
                .AddField(GetText(Localization.SearchesMeanScore), manga.MeanScore.HasValue ? manga.MeanScore.Value.ToString() : "-", true)
                .AddField(GetText(Localization.SearchesPopularity), manga.Popularity.HasValue ? manga.Popularity.Value.ToString() : "-", true)
                .AddField(GetText(Localization.SearchesFavourites), manga.Favourites.HasValue ? manga.Favourites.Value.ToString() : "-", true)
                .AddField(GetText(Localization.SearchesSource), !string.IsNullOrEmpty(manga.Source) ? manga.Source : "-", true)
                .AddField(GetText(Localization.SearchesGenres), genres, true)
                .AddField(GetText(Localization.SearchesSynonyms), synonyms, true)
                .AddField(GetText(Localization.SearchesIsAdult), manga.IsAdult.ToString(), true);

                switch (manga.IsAdult)
                {
                case true when Context.Channel.IsNSFW:
                case false:
                    embed.WithImageUrl(manga.CoverImage.ExtraLarge);
                    break;
                }

                await ReplyAsync(embed);
            }
예제 #3
0
            public async Task AnimeAsync([Remainder] string title)
            {
                var(type, method) = int.TryParse(title, out _) ? ("Int", "id") : ("String", "search");
                var query = AnimeService.AnimeQuery.Replace("[type]", type)
                            .Replace("[var]", method);

                var anime = await Service.GetAniListInfoAsync <AnimeMangaContent>(query, new { anime = title }, "Media");

                if (anime is null)
                {
                    await ReplyErrorAsync(Localization.SearchesAnimeNotFound);

                    return;
                }

                var description = new StringBuilder(anime.Description);

                if (!string.IsNullOrEmpty(anime.Description))
                {
                    description.Replace("<br>", "");
                    description.Replace("<i>", "");
                    description.Replace("</i>", "");
                }

                if (description.Length == 0)
                {
                    description.Append('-');
                }

                var episodeDuration = anime.Duration.HasValue
                    ? TimeSpan.FromMinutes(anime.Duration.Value).Humanize(2, new CultureInfo(Localization.GetGuildLocale(Context.Guild?.Id)))
                    : "-";

                var startDate = "-";

                if (anime.StartDate.Year.HasValue && anime.StartDate.Month.HasValue && anime.StartDate.Day.HasValue)
                {
                    startDate = new DateTime(anime.StartDate.Year.Value, anime.StartDate.Month.Value, anime.StartDate.Day.Value)
                                .ToString("MMM dd, yyyy", CultureInfo.InvariantCulture);
                }

                var endDate = "-";

                if (anime.EndDate.Year.HasValue && anime.EndDate.Month.HasValue && anime.EndDate.Day.HasValue)
                {
                    endDate = new DateTime(anime.EndDate.Year.Value, anime.EndDate.Month.Value, anime.EndDate.Day.Value)
                              .ToString("MMM dd, yyyy", CultureInfo.InvariantCulture);
                }

                var genres = anime.Genres != null
                    ? anime.Genres.Length != 0
                        ? string.Join("\n", anime.Genres)
                        : "-"
                    : "-";

                var embed = new DiscordEmbedBuilder
                {
                    Color       = RiasUtilities.HexToInt(anime.CoverImage.Color) ?? RiasUtilities.ConfirmColor,
                    Url         = anime.SiteUrl,
                    Title       = $"{(string.IsNullOrEmpty(anime.Title.Romaji) ? anime.Title.English : anime.Title.Romaji)} (AniList)",
                    Description = $"{description.ToString().Truncate(1900)} [{GetText(Localization.CommonMore).ToLowerInvariant()}]({anime.SiteUrl})"
                }.AddField(GetText(Localization.SearchesTitleRomaji), !string.IsNullOrEmpty(anime.Title.Romaji) ? anime.Title.Romaji : "-", true)
                .AddField(GetText(Localization.SearchesTitleEnglish), !string.IsNullOrEmpty(anime.Title.English) ? anime.Title.English : "-", true)
                .AddField(GetText(Localization.SearchesTitleNative), !string.IsNullOrEmpty(anime.Title.Native) ? anime.Title.Native : "-", true)
                .AddField(GetText(Localization.CommonId), anime.Id.ToString(), true)
                .AddField(GetText(Localization.SearchesFormat), !string.IsNullOrEmpty(anime.Format) ? anime.Format : "-", true)
                .AddField(GetText(Localization.SearchesEpisodes), anime.Episodes.HasValue ? anime.Episodes.Value.ToString() : "-", true)
                .AddField(GetText(Localization.SearchesEpisodeDuration), episodeDuration, true)
                .AddField(GetText(Localization.UtilityStatus), !string.IsNullOrEmpty(anime.Status) ? anime.Status : "-", true)
                .AddField(GetText(Localization.SearchesStartDate), startDate, true)
                .AddField(GetText(Localization.SearchesEndDate), endDate, true)
                .AddField(GetText(Localization.SearchesSeason), !string.IsNullOrEmpty(anime.Season) ? anime.Season : "-", true)
                .AddField(GetText(Localization.SearchesAverageScore), anime.AverageScore.HasValue ? anime.AverageScore.Value.ToString() : "-", true)
                .AddField(GetText(Localization.SearchesMeanScore), anime.MeanScore.HasValue ? anime.MeanScore.Value.ToString() : "-", true)
                .AddField(GetText(Localization.SearchesPopularity), anime.Popularity.HasValue ? anime.Popularity.Value.ToString() : "-", true)
                .AddField(GetText(Localization.SearchesFavourites), anime.Favourites.HasValue ? anime.Favourites.Value.ToString() : "-", true)
                .AddField(GetText(Localization.SearchesSource), !string.IsNullOrEmpty(anime.Source) ? anime.Source : "-", true)
                .AddField(GetText(Localization.SearchesGenres), genres, true)
                .AddField(GetText(Localization.SearchesIsAdult), anime.IsAdult ? GetText(Localization.CommonYes) : GetText(Localization.CommonNo), true);

                switch (anime.IsAdult)
                {
                case true when Context.Channel.IsNSFW:
                case false:
                    embed.WithImageUrl(anime.CoverImage.ExtraLarge);
                    break;
                }

                await ReplyAsync(embed);
            }
예제 #4
0
        public void LoadCredentials()
        {
            var config = new ConfigurationBuilder().AddJsonFile(_configurationPath).Build();

            Prefix = config.GetValue <string>(nameof(Prefix));
            Token  = config.GetValue <string>(nameof(Token));

            MasterId = config.GetValue <ulong>(nameof(MasterId));
            Currency = config.GetValue <string>(nameof(Currency));

            Invite            = config.GetValue <string>(nameof(Invite));
            OwnerServerInvite = config.GetValue <string>(nameof(OwnerServerInvite));
            OwnerServerId     = config.GetValue <ulong>(nameof(OwnerServerId));

            var confirmColor = RiasUtilities.HexToInt(config.GetValue <string>(nameof(RiasUtilities.ConfirmColor)));

            if (confirmColor.HasValue)
            {
                RiasUtilities.ConfirmColor = new DiscordColor(confirmColor.Value);
            }

            var errorColor = RiasUtilities.HexToInt(config.GetValue <string>(nameof(RiasUtilities.ErrorColor)));

            if (errorColor.HasValue)
            {
                RiasUtilities.ErrorColor = new DiscordColor(errorColor.Value);
            }

            Patreon        = config.GetValue <string>(nameof(Patreon));
            Website        = config.GetValue <string>(nameof(Website));
            DiscordBotList = config.GetValue <string>(nameof(DiscordBotList));

            UrbanDictionaryApiKey = config.GetValue <string>(nameof(UrbanDictionaryApiKey));
            ExchangeRateAccessKey = config.GetValue <string>(nameof(ExchangeRateAccessKey));
            DiscordBotListToken   = config.GetValue <string>(nameof(DiscordBotListToken));
            DiscordBotsToken      = config.GetValue <string>(nameof(DiscordBotsToken));
            WeebServicesToken     = config.GetValue <string>(nameof(WeebServicesToken));

            var databaseConfiguration = config.GetSection(nameof(DatabaseConfiguration));

            DatabaseConfiguration = !databaseConfiguration.Exists() ? null : new DatabaseConfiguration
            {
                Host            = databaseConfiguration.GetValue <string>(nameof(DatabaseConfiguration.Host)),
                Port            = databaseConfiguration.GetValue <ushort>(nameof(DatabaseConfiguration.Port)),
                Database        = databaseConfiguration.GetValue <string>(nameof(DatabaseConfiguration.Database)),
                Username        = databaseConfiguration.GetValue <string>(nameof(DatabaseConfiguration.Username)),
                Password        = databaseConfiguration.GetValue <string>(nameof(DatabaseConfiguration.Password)),
                ApplicationName = databaseConfiguration.GetValue <string>(nameof(DatabaseConfiguration.ApplicationName))
            };

            var votesConfiguration = config.GetSection(nameof(VotesConfiguration));

            VotesConfiguration = !votesConfiguration.Exists() ? null : new VotesConfiguration
            {
                WebSocketHost      = votesConfiguration.GetValue <string>(nameof(VotesConfiguration.WebSocketHost)),
                WebSocketPort      = votesConfiguration.GetValue <ushort>(nameof(VotesConfiguration.WebSocketPort)),
                IsSecureConnection = votesConfiguration.GetValue <bool>(nameof(VotesConfiguration.IsSecureConnection)),
                UrlParameters      = votesConfiguration.GetValue <string>(nameof(VotesConfiguration.UrlParameters)),
                Authorization      = votesConfiguration.GetValue <string>(nameof(VotesConfiguration.Authorization))
            };

            var patreonConfiguration = config.GetSection(nameof(PatreonConfiguration));

            PatreonConfiguration = !patreonConfiguration.Exists() ? null : new PatreonConfiguration
            {
                WebSocketHost      = patreonConfiguration.GetValue <string>(nameof(PatreonConfiguration.WebSocketHost)),
                WebSocketPort      = patreonConfiguration.GetValue <ushort>(nameof(PatreonConfiguration.WebSocketPort)),
                IsSecureConnection = patreonConfiguration.GetValue <bool>(nameof(PatreonConfiguration.IsSecureConnection)),
                UrlParameters      = patreonConfiguration.GetValue <string>(nameof(PatreonConfiguration.UrlParameters)),
                Authorization      = patreonConfiguration.GetValue <string>(nameof(PatreonConfiguration.Authorization))
            };
        }