Exemplo n.º 1
0
        private async Task SendFunCmd(SfwEndpoint endpoint, IUser user)
        {
            try
            {
                var author = Context.User;
                var image  = await NekosClient.GetSfwAsync(endpoint);

                var f*g = endpoint.ToString().ToLower()
                          .Replace("kiss", "kissed")
                          .Replace("hug", "hugged")
                          .Replace("poke", "poked")
                          .Replace("cuddle", "cuddled")
                          .Replace("slap", "slapped")
                          .Replace("pat", "patted")
                          .Replace("tickle", "tickled");
                await ReplyAsync(null, false, new EmbedBuilder()
                                 .WithDescription(user == null || author == user
                        ? $"{author.Mention} {f*g} themselves ?"
                        : $"{author.Mention} {f*g} {user.Mention}!")
                                 .WithImageUrl(image.FileUrl)
                                 .WithFooter("Powered by cdn.nekos.life")
                                 .Build());
            }
            catch
            {
                await ReplyAndDeleteAsync("Error !!", false, null, TimeSpan.FromSeconds(5));
            }
        }
Exemplo n.º 2
0
    /// <summary>
    ///     Get SFW results.
    /// </summary>
    /// <param name="endpoints">Members of <see cref="SfwEndpoint" /> enum representing the endpoints.</param>
    /// <param name="count">How many times EACH INDIVIDUAL REQUEST should be made.</param>
    /// <returns>Requested SFW results.</returns>
    /// <exception cref="ArgumentException">When the count is zero.</exception>
    public async Task <IEnumerable <NekosImage> > RequestSfwResultsAsync(SfwEndpoint endpoints, uint count = 1)
    {
        if (count == 0)
        {
            throw new ArgumentException("\"count\" must not be zero", nameof(count));
        }

        List <NekosImage>         responses      = new();
        IEnumerable <SfwEndpoint> availableFlags = Enum.GetValues <SfwEndpoint>();

        foreach (var endpoint in availableFlags)
        {
            var isSet = (endpoint & endpoints) != 0;
            if (!isSet)
            {
                continue;
            }

            if (endpoint == SfwEndpoint.All)
            {
                var images = await RequestAllSfwAsync(count).ConfigureAwait(false);

                responses.AddRange(images);
                continue;
            }

            SfwEndpoint tempEndpoint = endpoint;

            while (tempEndpoint == SfwEndpoint.Random)
            {
                var r = new Random();
                // random is 0
                // so simply ignore it
                var indexPick = r.Next(1, Enum.GetNames(typeof(SfwEndpoint)).Length - 1);
                tempEndpoint = availableFlags.ToArray()[indexPick];

                if (IsLoggingAllowed)
                {
                    NekoLogger.LogWarning($"Replaced \"Random\" with \"{tempEndpoint.ToString().ToLower()}\"");
                }
            }

            var dest = tempEndpoint.ToString().ToLower();

            for (var i = 0; i < count; ++i)
            {
                var response = await GetResponse <NekosImage>($"{HostUrl}{MediaRequestUrlSegment}/{dest}").ConfigureAwait(false);

                responses.Add(response);
            }
        }

        return(responses);
    }