Exemple #1
0
        public ActionResult Signup(User user, string password)
        {
            var db = new ImageDb(Properties.Settings.Default.ConStr);

            db.AddUser(user, password);
            return(Redirect("/home/upload"));
        }
Exemple #2
0
        public ActionResult ViewImage(int id, string password)
        {
            var db    = new ImageDb(_connectionString);
            var image = db.GetById(id);

            if (image == null)
            {
                return(RedirectToAction("Index"));
            }

            if (password != image.Password)
            {
                TempData["message"] = "Invalid password";
            }
            else
            {
                var allowedIds = HttpContext.Session.Get <List <int> >("allowedids");
                if (allowedIds == null)
                {
                    allowedIds = new List <int>();
                }
                allowedIds.Add(id);
                HttpContext.Session.Set("allowedids", allowedIds);
            }

            return(Redirect($"/home/viewimage?id={id}"));
        }
Exemple #3
0
        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());
        }
Exemple #4
0
        protected void UpdateImage_Click(object sender, EventArgs e)
        {
            ImageDb image = new ImageDb()
            {
                IdImage   = Convert.ToInt32(this.LabelImageId.Text),
                ImageName = this.tbEditImageName.Text,
                ImgAlt    = this.tbEditImageAlt.Text
            };

            if (this.CheckBoxNewImage.Checked)
            {
                UploadImageDb img = UploadFile.UploadImage(this.FileUploadEditImage, Server.MapPath("~/Upload/"), true);
                if (img.IsUploaded)
                {
                    image.BigPictureUrl       = img.BigPictureUrl;
                    image.SmallPictureUrl     = img.SmallPictureUrl;
                    this.GridView2.DataSource = OperationManager.Singleton.izvrsiOperaciju(new OpImageUpdate()
                    {
                        Image = image
                    }).DbItems.Cast <ImageDb>().ToArray();
                    this.GridView2.DataBind();
                }
            }
            else
            {
                this.GridView2.DataSource = OperationManager.Singleton.izvrsiOperaciju(new OpImageUpdateWithoutImg()
                {
                    Image = image
                }).DbItems.Cast <ImageDb>().ToArray();
                this.GridView2.DataBind();
            }
            this.PanelShowEditImage.Visible = false;
        }
Exemple #5
0
        public async Task DeleteImage(int id, [Remainder] string str = "")
        {
            bool insider = Context.Guild.Id == 418900885079588884;

            var image = ImageDb.GetImage(id);

            if (image == null)
            {
                await Context.Channel.SendMessageAsync($"There is no image with id: **{id}**");

                return;
            }
            if (!insider && image.GuildId != Context.Guild.Id)
            {
                await Context.Channel.SendMessageAsync($"There is no image with id **{id}** in your guild.");

                return;
            }

            await ImageDb.DeleteImage(id);

            await Context.Channel.SendMessageAsync($"Image **{id}** is gone forever. Why have you done this?");

            await ImgurAPI.EditImageAsync(ImgurAPI.ParseId(image.Url), null, image.Id.ToString() + " [DELETED]");
        }
        public ActionResult ViewImage(int id)
        {
            var viewModel = new ViewImageViewModel();

            if (TempData["message"] != null)
            {
                viewModel.Message = (string)TempData["message"];
            }

            if (!HasPermissionToView(id))
            {
                viewModel.HasPermissionToView = false;
                viewModel.Image = new Image {
                    Id = id
                };
            }
            else
            {
                viewModel.HasPermissionToView = true;
                var db = new ImageDb(Properties.Settings.Default.ConStr);
                db.IncrementViewCount(id);
                var image = db.GetById(id);
                if (image == null)
                {
                    return(RedirectToAction("Index"));
                }

                viewModel.Image = image;
            }

            return(View(viewModel));
        }
        public ActionResult ViewImage(int id, string password)
        {
            var db    = new ImageDb(Properties.Settings.Default.ConStr);
            var image = db.GetById(id);

            if (image == null)
            {
                return(RedirectToAction("Index"));
            }

            if (password != image.Password)
            {
                TempData["message"] = "Invalid password";
            }
            else
            {
                List <int> allowedIds;
                if (Session["allowedids"] == null)
                {
                    allowedIds            = new List <int>();
                    Session["allowedids"] = allowedIds;
                }
                else
                {
                    allowedIds = (List <int>)Session["allowedids"];
                }

                allowedIds.Add(id);
            }

            return(Redirect($"/image/viewimage?id={id}"));
        }
Exemple #8
0
        public ActionResult MyAccount()
        {
            var db     = new ImageDb(Properties.Settings.Default.ConStr);
            var images = db.GetUserImages(User.Identity.Name);

            return(View(images));
        }
        public ActionResult MyAccount()
        {
            var db   = new ImageDb(Properties.Settings.Default.ConStr);
            var user = db.GetByEmail(User.Identity.Name);
            IEnumerable <Image> images = db.GetImagesForUser(user.Id);

            return(View(images));
        }
        public IActionResult ViewImages()
        {
            var db = new ImageDb(_connectionString);
            var vm = new ViewImagesViewModel
            {
                Images = db.GetImages()
            };

            return(View(vm));
        }
        public ActionResult Upload(Image image, int UserId, HttpPostedFileBase imageFile)
        {
            var fileName = $"{Guid.NewGuid()}{Path.GetExtension(imageFile.FileName)}";

            imageFile.SaveAs(Path.Combine(Server.MapPath("/UploadedImages"), fileName));
            image.FileName = fileName;
            var db = new ImageDb(Properties.Settings.Default.ConStr);

            db.Add(image, UserId);
            return(View(image));
        }
Exemple #12
0
        public ActionResult Delete(int id)
        {
            var db       = new ImageDb(Properties.Settings.Default.ConStr);
            var imageIds = db.GetUserImages(User.Identity.Name).Select(i => i.Id);

            if (!imageIds.Contains(id))
            {
                return(Redirect("http://www.google.com")); // go away....
            }
            db.DeleteImage(id);
            return(RedirectToAction("MyAccount"));
        }
Exemple #13
0
        public async Task Image(int id, [Remainder] string str = "")
        {
            var image = ImageDb.GetImage(id);

            if (image == null || (image.GuildId != 0 && image.GuildId != Context.Guild.Id))
            {
                await Context.Channel.SendMessageAsync($"There is no image with id: {id}");

                return;
            }
            var embed = ImageUtil.ToEmbed(image).Build();
            await Context.Channel.SendMessageAsync("", false, embed);
        }
        public ActionResult SubmitUpload(Image image, HttpPostedFileBase imageFile)
        {
            var db   = new ImageDb(Properties.Settings.Default.ConStr);
            var user = db.GetByEmail(User.Identity.Name);

            image.UserId = user.Id;
            var fileName = $"{Guid.NewGuid()}{Path.GetExtension(imageFile.FileName)}";

            imageFile.SaveAs(Path.Combine(Server.MapPath("/UploadedImages"), fileName));
            image.FileName = fileName;
            db.Add(image);
            return(View(image));
        }
Exemple #15
0
        public ActionResult Login(string email, string password)
        {
            var db   = new ImageDb(Properties.Settings.Default.ConStr);
            var user = db.Login(email, password);

            if (user == null)
            {
                TempData["message"] = "Invalid login attempt";
                return(Redirect("/home/upload"));
            }

            FormsAuthentication.SetAuthCookie(email, true);
            return(Redirect("/"));
        }
        public IActionResult Upload(IFormFile myfile)
        {
            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);

            db.AddImage(actualFileName);

            return(Redirect("/"));
        }
Exemple #17
0
        public ActionResult Upload(Image image, IFormFile imageFile)
        {
            var    fileName = $"{Guid.NewGuid()}{Path.GetExtension(imageFile.FileName)}";
            string fullPath = Path.Combine(_environment.WebRootPath, "uploads", fileName);

            using (FileStream stream = new FileStream(fullPath, FileMode.CreateNew))
            {
                imageFile.CopyTo(stream);
            }
            image.FileName = fileName;
            var db = new ImageDb(_connectionString);

            db.Add(image);
            return(View(image));
        }
Exemple #18
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));
        }
Exemple #19
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));
        }
Exemple #20
0
        public async Task <bool> SendRandomImage(ICommandContext Context)
        {
            if (Context.Guild != null && DisabledCommandHandler.IsDisabled("", Context.Guild.Id, DisabledCommandType.Images))
            {
                return(false);
            }

            string text = Context.Message.Content;

            text = text.Replace(Program.GetPrefix(Context.Guild), "");
            text = text.Split(' ')[0];

            if (!ReactionImageCommands.Contains(text))
            {
                return(false);
            }

            text = text.ToLower();
            var image = Context.Guild == null ? null : ImageDb.GetRandomImage(text, Context.Guild.Id);

            if (image == null)
            {
                image = ImageDb.GetRandomImage(text);
                if (image == null)
                {
                    return(false);
                }
            }

            if (!RateLimit.CanExecute(Context.Channel.Id))
            {
                await Context.Channel.SendMessageAsync($"Woah there, Senpai, calm down! I locked this channel for **{RateLimit.InvokeLockoutPeriod.Seconds}** seconds <:MeguExploded:627470499278094337>\n" +
                                                       $"You can only use **{RateLimit.InvokeLimit}** commands per **{RateLimit.InvokeLimitPeriod.Seconds}** seconds per channel.");

                return(false);
            }

            var embed = ImageUtil.ToEmbed(image).Build();
            await Context.Channel.SendMessageAsync("", false, embed);

            return(true);
        }
Exemple #21
0
        // SET-UP

        private static void SetUp()
        {
            switch (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"))
            {
            case "Development":
                Development = true;
                Pause       = true;
                break;

            default:
                Console.WriteLine("Entry: " + Assembly.GetEntryAssembly().Location);
                _ = ImgurAPI.ImgurSetup();
                break;
            }
            NamikoDbContext.ConnectionString = AppSettings.ConnectionString;
            _        = LootboxStats.Reload(Locations.LootboxStatsJSON);
            Prefixes = ServerDb.GetPrefixes();
            Images.ReactionImageCommands = ImageDb.GetReactionImageCommandHashSet();
            Blacklist  = BlacklistDb.GetAll();
            Waifu.Path = AppSettings.ImageUrlPath + "waifus/";
        }
Exemple #22
0
        public async Task All(string name, [Remainder] string str = "")
        {
            var album  = Context.Guild == null ? null : ImageDb.GetAlbum(name + Context.Guild.Id);
            var album2 = ImageDb.GetAlbum(name);

            string albums = album == null ? "" : $"<{ImgurAPI.ParseAlbumLink(album.AlbumId)}>";

            if (album2 != null)
            {
                albums += $"\n<{ImgurAPI.ParseAlbumLink(album2.AlbumId)}>";
            }

            if (albums == "")
            {
                await Context.Channel.SendMessageAsync($"Album **{name}** doesn't exist.");

                return;
            }

            await Context.Channel.SendMessageAsync(albums);
        }
Exemple #23
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (this.Page.IsValid)
            {
                UploadImageDb img = UploadFile.UploadImage(this.FileUploadImage, Server.MapPath("~/Upload/"), true);
                if (img.IsUploaded)
                {
                    ImageDb image = new ImageDb()
                    {
                        IdProject       = ProjectId,
                        ImageName       = this.tbImageName.Text,
                        ImgAlt          = this.tbImageAlt.Text,
                        SmallPictureUrl = img.SmallPictureUrl,
                        BigPictureUrl   = img.BigPictureUrl
                    };

                    OperacijaRezultat res = OperationManager.Singleton.izvrsiOperaciju(new OpImageInsertOnly()
                    {
                        Image = image
                    });
                    if (res.Status)
                    {
                        Response.Redirect("/SingleProject.aspx?projectid=" + ProjectId);
                    }
                    else
                    {
                        this.LabelMessage.Visible = true;
                        this.LabelMessage.Text    = "something went wrong. we couldnt insert into database";
                    }
                }
                else
                {
                    this.LabelMessage.Visible = true;
                    this.LabelMessage.Text    = "something went wrong. we couldnt upload image";
                }
            }
        }
Exemple #24
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));
        }
Exemple #25
0
        public async Task NewWaifu(string name, int tier, string url = null)
        {
            var exists = await WaifuDb.GetWaifu(name);

            if (exists != null)
            {
                await ReplyAsync($"**{exists.Name}** is already a waifu.");

                return;
            }

            await Context.Channel.TriggerTypingAsync();

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

            if (url != null)
            {
                url = url.EndsWith(".gifv") ? url.Replace(".gifv", ".gif") : url;
                url = url.EndsWith(".mp4") ? url.Replace(".mp4", ".gif") : url;

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

                    return;
                }

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

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

                url = iImage.Link;
            }

            var waifu = new Waifu {
                Name = name, Tier = tier, ImageUrl = url, Description = null, LongName = null
            };
            await WaifuUtil.UploadWaifuImage(waifu, Context.Channel);

            if (await WaifuDb.AddWaifu(waifu) > 0)
            {
                await Context.Channel.SendMessageAsync($"{name} added.");
            }
            else
            {
                await Context.Channel.SendMessageAsync($"Failed to add {name}");
            }

            await Context.Channel.TriggerTypingAsync();

            await WaifuUtil.FindAndUpdateWaifuImageSource(waifu, Context.Channel);
        }
Exemple #26
0
        public async Task WaifuImage(string name, string url = null)
        {
            var waifu = await WaifuUtil.ProcessWaifuListAndRespond(await WaifuDb.SearchWaifus(name, true), this);

            if (waifu == null)
            {
                return;
            }

            await Context.Channel.TriggerTypingAsync();

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

            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 < 15)
            {
                await ReplyAsync("Not enough imgur credits to upload. Please try again later.");

                return;
            }

            string albumId;

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

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

            string old = waifu.ImageUrl;

            waifu.ImageUrl = iImage.Link;
            await WaifuUtil.UploadWaifuImage(waifu, Context.Channel);

            if (await WaifuDb.UpdateWaifu(waifu) > 0)
            {
                await SendWaifuUpdatedMessage(waifu, "ImageUrl", old, waifu.ImageUrl);
            }
            else
            {
                await Context.Channel.SendMessageAsync($":x: Failed to update {name}");
            }

            await Context.Channel.TriggerTypingAsync();

            await WaifuUtil.FindAndUpdateWaifuImageSource(waifu, Context.Channel);
        }
Exemple #27
0
        public async Task NewWaifuAutocomplete(string name, long malId, string url = null)
        {
            var exists = await WaifuDb.GetWaifu(name);

            if (exists != null)
            {
                await ReplyAsync($"**{exists.Name}** is already a waifu.");

                return;
            }

            await Context.Channel.TriggerTypingAsync();

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

            if (url != null)
            {
                url = url.EndsWith(".gifv") ? url.Replace(".gifv", ".gif") : url;
                url = url.EndsWith(".mp4") ? url.Replace(".mp4", ".gif") : url;

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

                    return;
                }

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

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

                url = iImage.Link;
            }

            var waifu = new Waifu {
                Name = name, Tier = 404, ImageUrl = url, Description = null, LongName = null
            };
            await WaifuUtil.UploadWaifuImage(waifu, Context.Channel);

            var mal = await WebUtil.GetWaifu(malId);

            waifu.LongName = $"{mal.Name} ({mal.NameKanji})";
            var    about = mal.About;
            var    lines = about.Split('\n');
            string desc  = "";

            foreach (var line in lines)
            {
                if (line.Split(' ')[0].EndsWith(':'))
                {
                    continue;
                }
                if (line.StartsWith('('))
                {
                    continue;
                }

                var l = Regex.Replace(line, @"\t|\n|\r|\\n|\\t|\\r", "");
                if (l != "")
                {
                    desc += l + "\n\n";
                }
            }
            waifu.Description = desc;
            waifu.Source      = mal.Animeography.FirstOrDefault() == null ? "" : mal.Animeography.FirstOrDefault().Name;
            try
            {
                waifu.Tier = WaifuUtil.FavoritesToTier(mal.MemberFavorites.Value);
            } catch { }

            if (waifu.Tier == 0)
            {
                waifu.Tier = 3;
                await Context.Channel.SendMessageAsync($"Not enough favorites! Are you sure you wish to create this waifu? Remove - `!dw {waifu.Name}`");
            }

            if (await WaifuDb.AddWaifu(waifu) > 0)
            {
                await Context.Channel.SendMessageAsync
                (
                    $"Autocompleted **{waifu.Name}**. Has **{mal.MemberFavorites}** favorites.",
                    embed : WaifuUtil.WaifuEmbedBuilder(waifu, Context).Build()
                );

                await WaifuDb.AddMalWaifu(new MalWaifu
                {
                    MalId        = malId,
                    WaifuName    = waifu.Name,
                    LastUpdated  = DateTime.Now,
                    MalConfirmed = true
                });
            }
            else
            {
                await Context.Channel.SendMessageAsync("Rip");
            }

            await Context.Channel.TriggerTypingAsync();

            await WaifuUtil.FindAndUpdateWaifuImageSource(waifu, Context.Channel);
        }
Exemple #28
0
        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());
        }
        public ActionResult MyAccount(int id)
        {
            var db = new ImageDb(Properties.Settings.Default.ConStr);

            return(View(db.AllImagesForUser(id)));
        }