Exemple #1
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 #2
0
        // Embeds
        //Embed Method: profile
        public static async Task <EmbedBuilder> ProfileEmbed(SocketGuildUser user)
        {
            var eb = new EmbedBuilder();

            string name = user.Username;

            var role = RoleUtil.GetMemberRole(user.Guild, user) ?? RoleUtil.GetLeaderRole(user.Guild, user);

            if (role != null)
            {
                var team = TeamDb.TeamByMember(role.Id) ?? TeamDb.TeamByLeader(role.Id);
                if (team != null)
                {
                    role = user.Roles.FirstOrDefault(x => x.Id == team.LeaderRoleId);
                    if (role == null)
                    {
                        role = user.Roles.FirstOrDefault(x => x.Id == team.MemberRoleId);
                    }

                    name += $" | {role.Name}";
                }
            }

            if (PremiumDb.IsPremium(user.Id, ProType.ProPlus))
            {
                name += " | Pro+ 🌟";
            }
            else if (PremiumDb.IsPremium(user.Id, ProType.Pro))
            {
                name += " | Pro ⭐";
            }
            eb.WithAuthor(name, user.GetAvatarUrl(), $"https://namiko.moe/Guild/{user.Guild.Id}/{user.Id}");

            var waifus     = UserInventoryDb.GetWaifus(user.Id, user.Guild.Id);
            int waifucount = waifus.Count();
            int waifuprice = WaifuUtil.WaifuValue(waifus);

            var  daily   = DailyDb.GetDaily(user.Id, user.Guild.Id);
            long timeNow = DateTimeOffset.Now.ToUnixTimeMilliseconds();

            string text = "";

            text += $"Amount: {BalanceDb.GetToasties(user.Id, user.Guild.Id).ToString("n0")}\n" +
                    $"Daily: {(daily == null ? "0" : ((daily.Date + 172800000) < timeNow ? "0" : daily.Streak.ToString()))}\n" +
                    $"Boxes Opened: {ProfileDb.GetLootboxOpenedAmount(user.Id)}\n";
            eb.AddField("Toasties <:toastie3:454441133876183060>", text, true);

            text = $"Amount: {waifucount}\n" +
                   $"Value: {waifuprice.ToString("n0")}\n";
            foreach (var x in MarriageDb.GetMarriages(user.Id, user.Guild.Id))
            {
                try
                {
                    if (!text.Contains("Married: "))
                    {
                        text += "Married: ";
                    }
                    text += $"{BasicUtil.IdToMention(GetWifeId(x, user.Id))}\n";
                } catch { }
            }
            eb.AddField("Waifus :two_hearts:", text, true);

            var waifu = FeaturedWaifuDb.GetFeaturedWaifu(user.Id, user.Guild.Id);

            if (waifu != null)
            {
                eb.WithImageUrl(waifu.HostImageUrl);
                eb.AddField("Featured Waifu <:MiaHug:536580304018735135>", $"**{waifu.Name}** - *{waifu.Source}*");
            }

            var    rep    = ProfileDb.GetRepAmount(user.Id);
            string footer = $"Votes: {await VoteDb.VoteCount(user.Id)} • ";

            footer += $"Rep: {rep} • ";
            // Activities require guildpresence
            //footer += $"Status: '{user.Status}'";
            //var activity = user.Activities.FirstOrDefault();
            //if (activity != null)
            //    footer += $", {activity.Type}: '{activity.Name}'";
            eb.WithFooter(footer);

            //quote
            string quote = ProfileDb.GetQuote(user.Id);

            if (!String.IsNullOrEmpty(quote) & !WebUtil.IsValidUrl(quote))
            {
                eb.WithDescription(quote);
            }

            //image
            string image = ProfileDb.GetImage(user.Id);

            if (WebUtil.IsValidUrl(image))
            {
                eb.WithThumbnailUrl(image);
            }

            eb.Color = ProfileDb.GetHex(out string colour, user.Id)? (Discord.Color)HexToColor(colour) : BasicUtil.RandomColor();
            return(eb);
        }
Exemple #3
0
        public async Task DownloadFiles(string path, int amount, int skip = 0, ulong channelId = 0)
        {
            await Context.Message.DeleteAsync();

            var ch       = channelId == 0 ? Context.Channel : (ISocketMessageChannel)Context.Client.GetChannel(channelId);
            var messages = await ch.GetMessagesAsync(amount, CacheMode.AllowDownload).FlattenAsync();

            int total      = 0;
            int downloaded = 0;

            foreach (var msg in messages.Skip(skip))
            {
                if (msg.Type != MessageType.Default)
                {
                    continue;
                }

                foreach (var attachment in msg.Attachments.Where(x => x.Height != null && x.Width != null))
                {
                    if (WebUtil.IsValidUrl(attachment.ProxyUrl))
                    {
                        Task.Run(() => DownloadFile(attachment.ProxyUrl,
                                                    path + @"\"
                                                    + msg.Timestamp.UtcDateTime.ToString("yyyy-MM-dd_HHmm") + "_"
                                                    + attachment.Filename))
                        .ContinueWith(x =>
                        {
                            if (x.Result == true)
                            {
                                downloaded++;
                                if (downloaded % 5 == 0)
                                {
                                    Console.WriteLine("Downloaded: " + downloaded);
                                }
                            }
                        });
                        total++;
                        if (total % 50 == 0)
                        {
                            Console.WriteLine("Total: " + total);
                        }
                    }
                }

                foreach (var word in msg.Content.Split(' '))
                {
                    if (WebUtil.IsValidUrl(word) && WebUtil.IsImageUrl(word))
                    {
                        Task.Run(() => DownloadFile(word,
                                                    path + @"\"
                                                    + msg.Timestamp.UtcDateTime.ToString("yyyy-MM-dd_HHmm") + "_"
                                                    + word.Split(@"/").Last()))
                        .ContinueWith(x =>
                        {
                            if (x.Result == true)
                            {
                                downloaded++;
                                if (downloaded % 5 == 0)
                                {
                                    Console.WriteLine("Downloaded: " + downloaded);
                                }
                            }
                        });
                        total++;
                        if (total % 50 == 0)
                        {
                            Console.WriteLine("Total: " + total);
                        }
                    }
                }
            }
            Console.WriteLine("Total: " + total);
        }