コード例 #1
0
 /*
  * [Command("cum")]
  * [Summary("Get cum nsfw!!")]
  * [Alias("cumming")]
  * public async Task NekoCumPic()
  * {
  *  await BadAtNaming(NsfwEndpoint.Cum_JPG, (ITextChannel)Context.Channel);
  * }
  *
  * [Command("b*****b")]
  * [Summary("Get b*****b nsfw!!")]
  * [Alias("b*****b")]
  * public async Task NekoBlowjob()
  * {
  *  await BadAtNaming(NsfwEndpoint.B*****b, (ITextChannel)Context.Channel);
  * }
  */
 private async Task BadAtNaming(NsfwEndpoint endpoint, ISocketMessageChannel channel)
 {
     /*
      * if (!IsNsfwChannel() && Context.User is SocketGuildUser userSend && userSend.GuildPermissions.ManageChannels)
      * {
      *  await ReplyAsync("Do you want to enable NSFW on this channel ?");
      *  var response = await NextMessageAsync(timeout: TimeSpan.FromSeconds(10));
      *  if (response == null) return;
      *  if (response.ToString().ToLower().Equals("yes")) await ((ITextChannel)channel).ModifyAsync(r => r.IsNsfw = true);
      * }
      */
     if (IsNsfwChannel())
     {
         try
         {
             var author = Context.User;
             var image  = await NekosClient.GetNsfwAsync(endpoint);
             await ReplyAsync(null, false,
                              new EmbedBuilder()
                              .WithDescription($"{author.Mention}, here you go '{endpoint.ToString().Replace("_", " ")}'")
                              .WithImageUrl(image.FileUrl).Build());
         }
         catch
         {
             await ReplyAsync("Error !!");
         }
     }
     else
     {
         await ReplyAsync(
             "You can only use this command in NSFW channel!! You can use *switch to enable nsfw here");
     }
 }
コード例 #2
0
ファイル: NekosV2Client.cs プロジェクト: Nekos-life/Nekos.Net
    /// <summary>
    ///     Get NSFW results.
    /// </summary>
    /// <param name="endpoints">Members of <see cref="NsfwEndpoint" /> enum representing the endpoints.</param>
    /// <param name="count">How many times EACH INDIVIDUAL REQUEST should be made.</param>
    /// <returns>Requested NSFW results.</returns>
    /// <exception cref="ArgumentException">When the count is zero.</exception>
    public async Task <IEnumerable <NekosImage> > RequestNsfwResultsAsync(NsfwEndpoint endpoints, uint count = 1)
    {
        if (count == 0)
        {
            throw new ArgumentException("\"count\" must not be zero", nameof(count));
        }

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

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

            if (endpoint == NsfwEndpoint.All)
            {
                var images = await RequestAllNsfwAsync(count).ConfigureAwait(false);

                responses.AddRange(images);
                continue;
            }

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

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

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

            // special case
            if (endpoint == NsfwEndpoint.Random_Hentai_Gif)
            {
                dest = "Random_hentai_gif";
            }

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

                responses.Add(response);
            }
        }

        return(responses);
    }