Esempio n. 1
0
        public async Task Imgur(CommandContext ctx,
                                [Description("Search query to pass to Imgur.")][RemainingText]
                                string query)
        {
            await ctx.TriggerTypingAsync();

            var results = ImgurService.GetImgurGalleryAsync(Program.Settings.Tokens.ImgurToken, query).Result;
            var output  = new DiscordEmbedBuilder().WithColor(new DiscordColor("#89C623"));

            switch (results)
            {
            case GalleryImage image:
                output.WithDescription(image.Title ?? "Search results for " + Formatter.Bold(query) + " on Imgur");
                output.WithImageUrl(image.Link);
                await ctx.RespondAsync(output.Build()).ConfigureAwait(false);

                break;

            case GalleryAlbum album:
                output.WithDescription(album.Title ?? "Search results for " + Formatter.Bold(query) + " on Imgur");
                output.WithImageUrl(album.Link);
                await ctx.RespondAsync(output.Build()).ConfigureAwait(false);

                break;

            default:
                await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseType.Missing)
                .ConfigureAwait(false);

                break;
            }
        }
Esempio n. 2
0
        public void UploadTest()
        {
            string imageFileName = Path.GetFullPath("snagitimgur.png");

            var          service      = new ImgurService();
            UploadResult uploadResult = service.UploadImage(imageFileName);

            Assert.IsNotNull(uploadResult);
        }
Esempio n. 3
0
        public async Task GetImgurGalleryData()
        {
            var results = await ImgurService.GetImgurGalleryAsync("cats", GallerySortOrder.Top, TimeWindow.All).ConfigureAwait(false);

            Assert.IsNotNull(results);

            results = await ImgurService.GetImgurGalleryAsync("dogs", GallerySortOrder.Top, TimeWindow.All).ConfigureAwait(false);

            Assert.IsNotNull(results);
        }
Esempio n. 4
0
        public async Task GetImgurGalleryData()
        {
            var results = await ImgurService.GetImgurGalleryAsync(TestSetup.Tokens.ImgurToken, "cats")
                          .ConfigureAwait(false);

            Assert.IsNotNull(results);

            results = await ImgurService.GetImgurGalleryAsync(TestSetup.Tokens.ImgurToken, "dogs")
                      .ConfigureAwait(false);

            Assert.IsNotNull(results);
        }
 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.imgur = new ImgurService(cfg.ImgurKey);
     } catch {
         Assert.Warn("Config file not found or Imgur key isn't valid (service disabled).");
         this.imgur = new ImgurService(null);
     }
 }
Esempio n. 6
0
        public void InitializeComponent(object pExtensionHost, IComponent pComponent, componentInitializeType initType)
        {
            try
            {
                var snagitHost = pExtensionHost as ISnagIt;
                if (snagitHost == null)
                {
                    throw new InvalidOperationException("Unable to communicate with Snagit");
                }

                var imgurService           = new ImgurService();
                var temporaryImageProvider = new TemporaryImageProvider(snagitHost);
                snagitFacade = new SnagitFacade(snagitHost, temporaryImageProvider, imgurService);
            }
            catch (Exception e)
            {
                // todo temp code, replace with proper reporting!
                MessageBox.Show("An unandled exception occured:\n" + e);
            }
        }
Esempio n. 7
0
        public async Task Imgur(CommandContext ctx,
                                [Description("Search query to pass to Imgur")][RemainingText] string query)
        {
            var results = ImgurService.GetImgurGalleryAsync(query).Result;

            switch (results)
            {
            case GalleryAlbum _:
                await ctx.RespondAsync(((GalleryAlbum)results).Link).ConfigureAwait(false);

                break;

            case GalleryImage _:
                await ctx.RespondAsync(((GalleryImage)results).Link).ConfigureAwait(false);

                break;

            default:
                await BotServices.SendEmbedAsync(ctx, Resources.NOT_FOUND_GENERIC, EmbedType.Missing).ConfigureAwait(false);

                break;
            }
        }
Esempio n. 8
0
 public AslanModule(ImgurService imgurService, BotConfig config, HttpClient client)
 {
     _imgurService = imgurService;
     _config       = config;
     _client       = client;
 }
Esempio n. 9
0
 public ImgurModule(ImgurService service)
 {
     Service = service;
 }