コード例 #1
0
        public async Task AutocompleteWaifu(string name, long malId)
        {
            var waifu = await WaifuDb.GetWaifu(name);

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

                return;
            }

            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";
                }
            }
            //desc.Replace(@"\r", @"\n\n");
            waifu.Description = desc;
            waifu.Source      = mal.Animeography.FirstOrDefault() == null ? "" : mal.Animeography.FirstOrDefault().Name;

            await WaifuDb.UpdateWaifu(waifu);

            await Context.Channel.SendMessageAsync($"Autocompleted **{waifu.Name}**. Has **{mal.MemberFavorites}** favorites.", false, WaifuUtil.WaifuEmbedBuilder(waifu, Context).Build());
        }
コード例 #2
0
        public async Task WaifuTier(string name, int tier)
        {
            var waifu = await WaifuUtil.ProcessWaifuListAndRespond(await WaifuDb.SearchWaifus(name, true), this);

            if (waifu == null)
            {
                return;
            }

            string old = waifu.Tier.ToString();

            waifu.Tier = tier;

            if (await WaifuDb.UpdateWaifu(waifu) > 0)
            {
                await SendWaifuUpdatedMessage(waifu, "Tier", old, waifu.Tier.ToString());
            }
            else
            {
                await Context.Channel.SendMessageAsync($":x: Failed to update {name}");
            }
        }
コード例 #3
0
        public async Task WaifuSource(string name, [Remainder] string source = null)
        {
            var waifu = await WaifuUtil.ProcessWaifuListAndRespond(await WaifuDb.SearchWaifus(name, true), this);

            if (waifu == null)
            {
                return;
            }

            string old = waifu.Source;

            waifu.Source = source;

            if (await WaifuDb.UpdateWaifu(waifu) > 0)
            {
                await SendWaifuUpdatedMessage(waifu, "Source", old, waifu.Source);
            }
            else
            {
                await Context.Channel.SendMessageAsync($":x: Failed to update {name}");
            }
        }
コード例 #4
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);
        }