コード例 #1
0
        public string Execute(string[] parameters)
        {
            if (parameters.Any() == false)
            {
                throw new ArgumentOutOfRangeException();
            }

            var giphy  = new GiphyService();
            var search = string.Join(" ", parameters);

            var result = giphy.GetGiphyRandom(search);

            // Build the image tag
            using (var sw = new StringWriter())
            {
                using (var htmlWriter = new HtmlTextWriter(sw))
                {
                    htmlWriter.AddAttribute(HtmlTextWriterAttribute.Src, result);
                    htmlWriter.AddAttribute(HtmlTextWriterAttribute.Alt, search);
                    htmlWriter.RenderBeginTag(HtmlTextWriterTag.Img);
                    htmlWriter.RenderEndTag();

                    return(sw.ToString());
                }
            }
        }
コード例 #2
0
        public async Task StartupAsync()
        {
            client     = new DiscordSocketClient();
            commands   = new CommandService();
            botSecrets = await BotSecrets.LoadFromFile();

            giphy    = new GiphyService(botSecrets.Giphy);
            services = new ServiceCollection()
                       .AddSingleton(client)
                       .AddSingleton(commands)
                       .AddSingleton(giphy)
                       .AddSingleton <RandomNumberService>()
                       .AddSingleton <FailMessageService>()
                       .BuildServiceProvider();

            await InstallCommandsAsync();

            client.Log += Log;

            await client.LoginAsync(TokenType.Bot, botSecrets.Discord.DevelopmentToken);

            await client.StartAsync();

            // Task doesn't return until program exit
            await Task.Delay(-1);
        }
コード例 #3
0
ファイル: Searches.cs プロジェクト: rishav394/SoraBot-v2
 public Searches(GiphyService giphyService, UbService ubService, ImdbService imdbService, WeatherService weatherService)
 {
     _giphyService   = giphyService;
     _ubService      = ubService;
     _imdbService    = imdbService;
     _weatherService = weatherService;
 }
コード例 #4
0
        public void GetGiphyRandom_Kangaroo()
        {
            var giphy    = new GiphyService();
            var imageUrl = giphy.GetGiphyRandom("kangaroo");

            Console.WriteLine($"The image url returned was: {imageUrl}");

            Assert.IsNotNull(imageUrl);
            Assert.IsNotEmpty(imageUrl);
        }
コード例 #5
0
        /// <summary>
        /// Function registers the classes in the FreshMVVM IOC container.
        /// </summary>
        private void RegisterServices()
        {
            GiphyService         giphyService         = new GiphyService();
            SearchCacheService   searchCacheService   = new SearchCacheService();
            GifCollectionService gifCollectionService = new GifCollectionService();
            GifDataService       gifDataService       = new GifDataService();

            FreshIOC.Container.Register(giphyService);
            FreshIOC.Container.Register(searchCacheService);
            FreshIOC.Container.Register(gifCollectionService);
            FreshIOC.Container.Register(gifDataService);
        }
コード例 #6
0
 public async Task InitAsync()
 {
     try {
         string json;
         using (var sr = new StreamReader("Resources/config.json"))
             json = await sr.ReadToEndAsync();
         var cfg = JsonConvert.DeserializeObject <BotConfig>(json);
         this.giphy = new GiphyService(cfg.GiphyKey);
     } catch {
         Assert.Warn("Config file not found or GIPHY key isn't valid (service disabled).");
         this.giphy = new GiphyService(null);
     }
 }
コード例 #7
0
        public async Task Giphy([Remainder] string search = "")
        {
            if (string.IsNullOrWhiteSpace(Config.bot.Apis.ApiGiphyKey))
            {
                await Context.Channel.SendMessageAsync("Giphy search is disabled by the bot owner.");

                return;
            }

            if (string.IsNullOrWhiteSpace(search))
            {
                await Context.Channel.SendMessageAsync("The search input cannot be blank!");

                return;
            }

            EmbedBuilder embed = new EmbedBuilder();

            embed.WithTitle($"Giphy Search '{search}'");
            embed.WithDescription("Searching Giphy...");
            embed.WithFooter($"Search by {Context.User}", Context.User.GetAvatarUrl());
            embed.WithCurrentTimestamp();
            embed.WithColor(FunCmdsConfig.giphyColor);

            RestUserMessage message = await Context.Channel.SendMessageAsync("", false, embed.Build());

            GiphySearchResult results = GiphyService.Search(search);

            if (!results.IsSuccessful)
            {
                if (results.ErrorReason == ErrorReason.Error)
                {
                    await Context.Channel.SendMessageAsync(
                        "Sorry, but an error occured while searching Giphy, please try again in a moment!");

                    return;
                }
            }

            embed.WithDescription($"**By**: {results.Data.GifAuthor}\n**URL**: {results.Data.GifLink}");
            embed.WithImageUrl(results.Data.GifUrl);
            embed.WithCurrentTimestamp();

            await MessageUtils.ModifyMessage(message, embed);
        }
コード例 #8
0
 public CognitoController(GiphyService giphyService, SlackService slackService, AylienSentimentFetch aylienSentimentFetch)
 {
     _giphyService  = giphyService;
     _slackService  = slackService;
     _aylienService = aylienSentimentFetch;
 }
コード例 #9
0
ファイル: GiphyModule.cs プロジェクト: lydianlights/chillbot
 public GiphyModule(GiphyService giphy)
 {
     this.giphy = giphy;
 }
コード例 #10
0
 public static void Setup(TestContext testContext)
 {
     giphyService = new GiphyService();
 }