Exemplo n.º 1
0
        public async Task vndb(params string[] vns)
        {
            p.doAction(Context.User, Context.Guild.Id, Program.Module.Vn);
            if (vns.Length == 0)
            {
                await ReplyAsync(Sentences.vndbHelp(Context.Guild.Id));

                return;
            }
            VisualNovel vn = await getVn(Program.addArgs(vns));

            if (vn == null || !Program.cleanWord(vn.Name).Contains(Program.cleanWord(Program.addArgs(vns))))
            {
                await ReplyAsync(Sentences.vndbNotFound(Context.Guild.Id));

                return;
            }
            List <string> tmpDesc = vn.Description.Split('\n').ToList();

            Console.WriteLine(tmpDesc.Count);
            if (tmpDesc[tmpDesc.Count - 1].Contains("[/url]"))
            {
                tmpDesc.RemoveAt(tmpDesc.Count - 1);
            }
            string desc = "";

            foreach (string s in tmpDesc)
            {
                desc += s + Environment.NewLine;
            }
            Dictionary <string, string> allLengths = new Dictionary <string, string>()
            {
                { "VeryShort", "< 2 hours" },
                { "Short", "2 - 10 hours" },
                { "Medium", "10 - 30 hours" },
                { "Long", "30 - 50 hours" },
                { "VeryLong", "> 50 hours" }
            };
            string finalDesc = ((vn.OriginalName != null) ? ("**" + vn.OriginalName + "** (" + vn.Name + ")") : ("**" + vn.Name + "**")) + Environment.NewLine
                               + ((vn.Languages.ToArray().Contains("en")) ? ("Available") : ("Not available")) + " in english." + Environment.NewLine
                               + ((vn.Platforms.Contains("win")) ? ("Available") : ("Not available")) + " on Windows." + Environment.NewLine
                               + ((vn.Length != null) ? (vn.Length.ToString().Replace("Very", "Very ") + " (" + allLengths[vn.Length.ToString()] + ")" + Environment.NewLine) : (""))
                               + "It's rate " + vn.Rating + "/10 on VNDB." + Environment.NewLine
                               + ((vn.Released.Year != null) ? ("Released" + ((vn.Released.Month != null) ? ((vn.Released.Day != null) ? (" the " + vn.Released.Day + "/" + vn.Released.Month + "/" + vn.Released.Year) : (" in " + vn.Released.Month + "/" + vn.Released.Year)) : (" in " + vn.Released.Year))) : ("Not released yet.")) + Environment.NewLine
                               + Environment.NewLine + Environment.NewLine
                               + desc;
            bool         isNsfw = (Context.Channel as ITextChannel).IsNsfw;
            EmbedBuilder embed  = new EmbedBuilder()
            {
                ImageUrl    = ((vn.IsImageNsfw && isNsfw || !vn.IsImageNsfw) ? (vn.Image) : (null)),
                Description = finalDesc,
                Color       = Color.Green
            };

            await ReplyAsync("", false, embed.Build());

            IGuildUser me = await Context.Guild.GetUserAsync(Sentences.myId);

            if (me.GuildPermissions.AttachFiles)
            {
                int counter = 0;
                foreach (ScreenshotMetadata image in vn.Screenshots.ToArray())
                {
                    if ((!isNsfw && !image.IsNsfw) || isNsfw)
                    {
                        using (WebClient wc = new WebClient())
                        {
                            string currName = "vn" + DateTime.Now.ToString("HHmmssfff") + Context.Guild.ToString() + Context.User.Id.ToString() + "." + image.Url.Split('.')[image.Url.Split('.').Length - 1];
                            wc.DownloadFile(image.Url, currName);
                            await Context.Channel.SendFileAsync(currName);

                            File.Delete(currName);
                            counter++;
                            if (counter == 1)
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }