Пример #1
0
        private async Task TenorSearch(params string[] stringArray)
        {
            var tenor = new TenorClient(_tenorToken);

            tenor.SetContentFilter(TenorSharp.Enums.ContentFilter.medium);
            GifObject[] gifs  = new GifObject[0];
            var         range = 10;

            while (range > 1)
            {
                try
                {
                    gifs  = tenor.Search(string.Join(" ", stringArray), range).GifResults;
                    range = 0;
                }
                catch
                {
                    range /= 2;
                }
            }

            if (gifs.Count() == 0)
            {
                gifs = tenor.Search("confused").GifResults;
            }

            var r   = new Random();
            var gif = gifs.ElementAt(r.Next(0, Math.Min(5, gifs.Count())));

            await ReplyAsync(gif.Url.OriginalString);
        }
Пример #2
0
        public async Task <List <GifResult> > Search(string query)
        {
            var client = new TenorClient("5Z2X4KYG2HVW");

            Gif results = null;

            try{
                results = client.Search(query);
            }
            catch (Exception ex)
            {
                Debug.Write(ex.Message);
            }

            GifObject[] gifResult = null;

            if (results != null)
            {
                gifResult = results.GifResults;
            }

            return(gifResult.Select(x => new GifResult()
            {
                Width = x.Media[0][GifFormat.mp4].Dims[0],
                Height = x.Media[0][GifFormat.mp4].Dims[1],
                Tags = x.Tags.ToList(),
                Title = x.Title,
                Url = x.Media[0][GifFormat.mp4].Url.AbsoluteUri
            }).ToList());
        }
Пример #3
0
        public async Task PoutAsync()
        {
            var tenor  = new TenorClient(Environment.GetEnvironmentVariable("TENOR_API"));
            var pouts  = tenor.Search("anime pout");
            var output = pouts.GifResults[new Random().Next(pouts.GifResults.Length)];

            await RankaReplyAsync($"{Context.User.Username} is pouting").ConfigureAwait(false);
            await RankaReplyAsync(output.Url.AbsoluteUri).ConfigureAwait(false);
        }
Пример #4
0
        public async Task HugAsync()
        {
            var tenor  = new TenorClient(Environment.GetEnvironmentVariable("TENOR_API"));
            var hugs   = tenor.Search("anime hug");
            var output = hugs.GifResults[new Random().Next(hugs.GifResults.Length)];

            await RankaReplyAsync($"Oh my you got nobody? Fine I'll give you a hug <(^-^)>").ConfigureAwait(false);
            await RankaReplyAsync(output.Url.AbsoluteUri).ConfigureAwait(false);
        }
Пример #5
0
        public async Task PoutAsync([Summary("That someone")] IUser user)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user), "No user mentioned");
            }
            var tenor  = new TenorClient(Environment.GetEnvironmentVariable("TENOR_API"));
            var pouts  = tenor.Search("anime pout");
            var output = pouts.GifResults[new Random().Next(pouts.GifResults.Length)];

            await RankaReplyAsync($"{Context.User.Username} is pouting at {user.Mention}").ConfigureAwait(false);
            await RankaReplyAsync(output.Url.AbsoluteUri).ConfigureAwait(false);
        }
Пример #6
0
        public async Task HugAsync([Summary("That someone")] IUser user, [Remainder][Summary("Reason")] string reason)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user), "No user mentioned");
            }
            var tenor  = new TenorClient(Environment.GetEnvironmentVariable("TENOR_API"));
            var hugs   = tenor.Search("anime hug");
            var output = hugs.GifResults[new Random().Next(hugs.GifResults.Length)];

            await RankaReplyAsync($"{Context.User.Username} hugs {user.Mention} for {reason}").ConfigureAwait(false);
            await RankaReplyAsync(output.Url.AbsoluteUri).ConfigureAwait(false);
        }
Пример #7
0
        public async Task SlapAsync([Summary("That someone")] IUser user, [Remainder][Summary("Reasoning")] string reasoning)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user), "No user mentioned");
            }
            if (user.IsBot && user.Id == Context.Client.CurrentUser.Id)
            {
                await RankaReplyAsync($"w-why? for {reasoning}?? .·´¯`(>▂<)´¯`·.").ConfigureAwait(false);

                return;
            }
            var tenor  = new TenorClient(Environment.GetEnvironmentVariable("TENOR_API"));
            var slaps  = tenor.Search("anime slap");
            var output = slaps.GifResults[new Random().Next(slaps.GifResults.Length)];

            await RankaReplyAsync($"{Context.User.Username} slapped {user.Mention} for {reasoning}").ConfigureAwait(false);
            await RankaReplyAsync(output.Url.AbsoluteUri).ConfigureAwait(false);
        }
Пример #8
0
        public async Task TenorSearch(string query, int numPosts)
        {
            var tenor = new TenorClient(_config["TenorApiKey"]);

            tenor.SetContentFilter(TenorSharp.Enums.ContentFilter.high);

            await Log(msg : new Discord.LogMessage(message: $"Getting gif results for: [{query}]", severity: Discord.LogSeverity.Info, source: "GifCommand"));

            var gifs = tenor.Search(query).GifResults;

            var rand = new Random();
            var gif  = gifs[rand.Next(0, Math.Min(numPosts, gifs.Length))].Url.OriginalString;

            await Log(msg : new Discord.LogMessage(message: $"Got the gif: [{gif}]", severity: Discord.LogSeverity.Info, source: "GifCommand"));

            await Context.Channel.SendMessageAsync(gif);

            await Log(msg : new Discord.LogMessage(message: "Gif sent", severity: Discord.LogSeverity.Info, source: "GifCommand"));
        }
Пример #9
0
        /// <summary>
        ///     returns the next set of GIFs for the used search term and a different result count
        /// </summary>
        /// <param name="count">the new result count</param>
        /// <returns>the next set of GIFs</returns>
        public Gif Next(int count)
        {
            switch (Type)
            {
            case SearchTypes.search:
                return(Client.Search(Term, count, NextGifs));

            case SearchTypes.trending:
                return(Client.Trending(count, NextGifs));

            case SearchTypes.getGifs:
                return(Client.GetGifs(count, NextGifs, Ids));

            case SearchTypes.getRandom:
                return(Client.GetRandomGifs(Term, count, NextGifs));

            default:
                return(null);
            }
        }