예제 #1
0
파일: Images.cs 프로젝트: ta1H3n/Namiko
        public async Task List([Remainder] string str = "")
        {
            var images = await ImageDb.GetImages();

            List <ImageCount> names = new List <ImageCount>();

            foreach (ReactionImage x in images)
            {
                Boolean flag = true;
                foreach (ImageCount a in names)
                {
                    if (a.Name.Equals(x.Name))
                    {
                        a.Count++;
                        flag = false;
                        break;
                    }
                }
                if (flag)
                {
                    names.Add(new ImageCount {
                        Name = x.Name, Count = 1
                    });
                }
            }

            names = names.OrderBy(x => x.Name).ToList();
            var eb = ImageUtil.ListAllEmbed(names, Program.GetPrefix(Context), Context.User);

            eb = ImageUtil.AddGuildImagesToEmbed(eb, (await ImageDb.GetImages(null, Context.Guild.Id)).Select(x => x.Name).Distinct().OrderBy(x => x));
            await Context.Channel.SendMessageAsync(embed : eb.Build());
        }
예제 #2
0
        public IActionResult ViewImages()
        {
            var db = new ImageDb(_connectionString);
            var vm = new ViewImagesViewModel
            {
                Images = db.GetImages()
            };

            return(View(vm));
        }
예제 #3
0
        public IActionResult ViewImage(int id)
        {
            var             db = new ImageDb(_connectionString);
            UploadViewModel vm = new UploadViewModel();

            vm.Image = db.GetImages().FirstOrDefault(i => i.Id == id);

            List <int> ids = HttpContext.Session.Get <List <int> >("ApprovedIds");

            if (ids != null && ids.Contains(id))
            {
                return(Redirect($"/home/viewpic?id={id}"));
            }

            return(View(vm));
        }
예제 #4
0
        public IActionResult Upload(IFormFile myfile, string password)
        {
            Guid   guid           = Guid.NewGuid();
            string actualFileName = $"{guid}-{myfile.FileName}";
            string finalFileName  = Path.Combine(_environment.WebRootPath, "uploads", actualFileName);

            using var fs = new FileStream(finalFileName, FileMode.CreateNew);
            myfile.CopyTo(fs);

            var db      = new ImageDb(_connectionString);
            int imageId = db.AddImage(actualFileName, password);

            UploadViewModel vm = new UploadViewModel();

            vm.Image = db.GetImages().FirstOrDefault(i => i.Id == imageId);
            vm.Link  = $"http://localhost:53644/home/ViewImage?id={imageId}";
            return(View(vm));
        }
예제 #5
0
        public IActionResult ViewPic(int id)
        {
            var             db    = new ImageDb(_connectionString);
            UploadViewModel vm    = new UploadViewModel();
            Image           image = db.GetImages().FirstOrDefault(i => i.Id == id);

            vm.Image = image;
            vm.Image.Views++;
            db.UpdateViewCount(vm.Image);

            List <int> ids = HttpContext.Session.Get <List <int> >("ApprovedIds");

            if (ids == null)
            {
                ids = new List <int>();
            }
            if (!ids.Contains(image.Id))
            {
                ids.Add(image.Id);
            }
            HttpContext.Session.Set("ApprovedIds", ids);

            return(View(vm));
        }
예제 #6
0
파일: Images.cs 프로젝트: ta1H3n/Namiko
        public async Task NewImage(string name, string url = null, [Remainder] string str = "")
        {
            await Context.Channel.TriggerTypingAsync();

            bool insider = Context.Guild.Id == 418900885079588884;

            url ??= Context.Message.Attachments.FirstOrDefault()?.Url;

            if (!insider)
            {
                if (!PremiumDb.IsPremium(Context.Guild.Id, ProType.GuildPlus))
                {
                    await Context.Channel.SendMessageAsync($"This server does not have Pro Guild+. `{Program.GetPrefix(Context)}pro`");

                    return;
                }

                if ((await ImageDb.GetImages(name, 0)).Any())
                {
                    await Context.Channel.SendMessageAsync($"There is already a default image command called **{name}**. It will be replaced with your custom one.");
                }
            }

            if (url == null)
            {
                await Context.Channel.SendMessageAsync("Can't get your attachment, there probably isn't one. *Heh, dummy...*");

                return;
            }

            url = url.EndsWith(".gifv") ? url.Replace(".gifv", ".gif") : url;
            url = url.EndsWith(".mp4") ? url.Replace(".mp4", ".gif") : url;

            if (ImgurAPI.RateLimit.ClientRemaining < 50)
            {
                await ReplyAsync("Not enough imgur credits to upload. Please try again later.");

                return;
            }

            string albumId;
            string albumName = insider ? name : name + Context.Guild.Id;

            if (!ImageDb.AlbumExists(albumName))
            {
                albumId = (await ImgurAPI.CreateAlbumAsync(albumName)).Id;
                await ImageDb.CreateAlbum(albumName, albumId);
            }
            else
            {
                albumId = ImageDb.GetAlbum(albumName).AlbumId;
            }

            var iImage = await ImgurAPI.UploadImageAsync(url, albumId);

            var img = await ImageDb.AddImage(name.ToLower(), iImage.Link, insider? 0 : Context.Guild.Id);

            if (!ReactionImageCommands.Contains(name.ToLower()))
            {
                ReactionImageCommands.Add(name.ToLower());
            }

            await ImgurAPI.EditImageAsync(iImage.Id.ToString(), null, img.Id.ToString());

            var rl = ImgurAPI.RateLimit;
            await ImageUtil.UploadReactionImage(img, Context.Channel);

            await Context.Channel.SendMessageAsync($"{rl.ClientRemaining-20}/{rl.ClientLimit} imgur credits remaining.", false, ImageUtil.ToEmbed(img).Build());
        }