Пример #1
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public Wallpapers()
 {
     Client    = new E621Client(API_KEY);
     WebClient = new HttpClient();
     FetchFile();
     Timer = new Timer((uint)Helper.Settings.WallpaperTime);
 }
Пример #2
0
        public static IFlurlRequest Authenticated(this IFlurlRequest flurlRequest, E621Client e621Client)
        {
            if (!e621Client.HasLogin)
            {
                throw E621ClientNotAuthenticatedException.Create();
            }

#pragma warning disable 8602 // If the E621Client instance has a login, then the credentials are always available.
            return(flurlRequest.WithBasicAuth(e621Client.Credentials.Username, e621Client.Credentials.ApiKey));

#pragma warning restore 8602
        }
Пример #3
0
        public async Task E621(params string[] tags)
        {
            tags
            .ContainsBlacklistedTags()
            .IsSuccessAsync(x => containsIllegalTags(x.Data, tags, Context))
            .IsErrorAsync(async x =>
            {
                var posts = await E621Client.GetImagesAsync(tags).ConfigureAwait(false);
                StatsdClient.DogStatsd.Increment("web.get");

                if (posts == null || !posts.Any())
                {
                    await EmbedExtensions.FromError("Couldn't find an image.", Context).QueueMessageAsync(Context).ConfigureAwait(false);
                    return;
                }

                var post = posts.Where(x => x.Tags.All(z => !z.Value.ContainsBlacklistedTags().Successful)).RandomValue();

                await post.GetMessage(Context).QueueMessageAsync(Context).ConfigureAwait(false);
            }
                          );
        }
Пример #4
0
        public async Task HentaiBomb([Remainder] string tags = null)
        {
            List <string> localTags = new List <string>();

            if (tags != null)
            {
                tags.Split(' ').ToArray();
            }

            localTags
            .ContainsBlacklistedTags()
            .IsSuccessAsync(x => containsIllegalTags(x.Data, localTags, Context))
            .IsError(x =>
            {
                ""
                .ThenAsync(async x =>
                {
                    var posts = await YandereClient.GetImagesAsync(tags).ConfigureAwait(false);
                    StatsdClient.DogStatsd.Increment("web.get");
                    if (posts != null && posts.Any())
                    {
                        var post = posts.Where(x => !x.Tags.ContainsBlacklistedTags().Successful).RandomValue();
                        if (post != null)
                        {
                            x = $"Yande.re: {post.GetMessage(Context, true)}\n";
                        }
                    }

                    return(x);
                })
                .ThenAsync(async x =>
                {
                    if (localTags.Count < 6)
                    {
                        var posts = await KonaChanClient.GetImagesAsync(tags).ConfigureAwait(false);
                        StatsdClient.DogStatsd.Increment("web.get");
                        if (posts != null && posts.Any())
                        {
                            var post = posts.Where(x => !x.Tags.ContainsBlacklistedTags().Successful).RandomValue();
                            if (post != null)
                            {
                                x += $"Konachan {post.GetMessage(Context, true)}\n";
                            }
                        }
                    }

                    return(x);
                })
                .ThenAsync(async x =>
                {
                    var posts = await E621Client.GetImagesAsync(tags).ConfigureAwait(false);
                    StatsdClient.DogStatsd.Increment("web.get");
                    if (posts != null && posts.Any())
                    {
                        var post = posts.Where(x => !x.Tags.All(z => z.Value.ContainsBlacklistedTags().Successful)).RandomValue();
                        if (post != null)
                        {
                            x += $"E621: {post.GetMessage(Context, true)}\n";
                        }
                    }

                    return(x);
                })
                .ThenAsync(async x =>
                {
                    var posts = await Rule34Client.GetImagesAsync(tags).ConfigureAwait(false);
                    StatsdClient.DogStatsd.Increment("web.get");
                    if (posts != null && posts.Any())
                    {
                        var post = posts.Where(x => !x.Tags.ContainsBlacklistedTags().Successful).RandomValue();
                        if (post != null)
                        {
                            x += $"R34: {post.GetMessage(Context, true)}\n";
                        }
                    }

                    return(x);
                })
                .ThenAsync(async x =>
                {
                    var posts = await GelbooruClient.GetImagesAsync(tags).ConfigureAwait(false);
                    StatsdClient.DogStatsd.Increment("web.get");
                    if (posts != null && posts.Any())
                    {
                        var post = posts.Where(x => !x.Tags.ContainsBlacklistedTags().Successful).RandomValue();
                        if (post != null)
                        {
                            x += $"Gelbooru: {post.GetMessage(Context, true)}\n";
                        }
                    }

                    return(x);
                })
                .ThenAsync(async x =>
                {
                    var posts = await DanbooruClient.GetImagesAsync(tags).ConfigureAwait(false);
                    StatsdClient.DogStatsd.Increment("web.get");
                    if (posts != null && posts.Any())
                    {
                        var post = posts.Where(x => !x.Tags.ContainsBlacklistedTags().Successful).RandomValue();
                        if (post != null)
                        {
                            x += $"Danbooru: {post.GetMessage(Context, true)}\n";
                        }
                    }

                    return(x);
                })
                .Then(async x =>
                {
                    if (!string.IsNullOrEmpty((string)x))
                    {
                        await x.QueueMessageAsync(Context).ConfigureAwait(false);
                    }
                });
            }
                     );
        }
Пример #5
0
 public E621Service(IOptions <E621Options> options)
 {
     _client = new E621Client(options.Value.UserAgent);
 }
Пример #6
0
 public static IFlurlRequest AuthenticatedIfPossible(this IFlurlRequest flurlRequest, E621Client e621Client)
 {
     return(e621Client.Credentials == null
         ? flurlRequest
         : flurlRequest.Authenticated(e621Client));
 }