Example #1
0
File: Web.cs Project: ta1H3n/Namiko
        public async Task AutocompleteWaifu([Remainder] string name)
        {
            await Context.Channel.TriggerTypingAsync();

            var eb = new EmbedBuilderPrepared(Context.User);

            var waifus = await WebUtil.GetWaifus(name);

            string list = "";

            foreach (var w in waifus.Results.Take(10))
            {
                list += $"`{w.MalId}` [{w.Name}]({w.URL}) - *{(w.Animeography.FirstOrDefault() == null ? w.Mangaography.FirstOrDefault().Name : w.Animeography.FirstOrDefault().Name)}*\n";
            }
            eb.WithDescription(list);

            await Context.Channel.SendMessageAsync(embed : eb.Build());
        }
Example #2
0
        public async Task Status()
        {
            var shards = Context.Client.Shards;
            var eb     = new EmbedBuilderPrepared();

            int homeShard = -1;

            if (Context.Guild != null)
            {
                homeShard = (int)(Context.Guild.Id << 22) % Context.Client.Shards.Count;
            }

            foreach (var shard in shards)
            {
                eb.AddField($"Shard {shard.ShardId}{(shard.ShardId == homeShard ? " - your shard" : "")}",
                            $"State: {shard.ConnectionState}\n" +
                            $"Latency: {shard.Latency}\n",
                            true);
            }

            await Context.Channel.SendMessageAsync(embed : eb.Build());
        }
Example #3
0
        public async Task ListDisabledCommands([Remainder] string name = "")
        {
            string modules  = "-";
            string commands = "-";

            if (DisabledCommandHandler.DisabledCommands.TryGetValue(Context.Guild.Id, out var set) && set.Any())
            {
                commands = string.Join(" | ", set);
            }
            if (DisabledCommandHandler.DisabledModules.TryGetValue(Context.Guild.Id, out set) && set.Any())
            {
                modules = string.Join(" | ", set);
            }

            var eb = new EmbedBuilderPrepared(Context.User);

            eb.AddField("Disabled Modules", modules);
            eb.AddField("Disabled Commands", commands);
            if (DisabledCommandHandler.DisabledImages.Contains(Context.Guild.Id))
            {
                eb.AddField("Reaction Images", "All Disabled");
            }
            await ReplyAsync(embed : eb.Build());
        }
Example #4
0
        public static async Task Timer_RequestSauce(object sender, ElapsedEventArgs e)
        {
            Waifu        waifu  = null;
            List <Embed> embeds = new List <Embed>();
            SauceRequest req    = null;

            if (sender != null && sender is SauceRequest)
            {
                req   = sender as SauceRequest;
                waifu = req.Waifu;
            }

            try
            {
                using var db = new NamikoDbContext();
                if (waifu != null)
                {
                    waifu = await db.Waifus.AsQueryable().FirstOrDefaultAsync(x => x.Source.Equals(waifu.Source) && x.ImageSource.Equals("missing"));
                }
                if (waifu == null)
                {
                    waifu = await db.Waifus.AsQueryable().OrderBy(x => Guid.NewGuid()).FirstOrDefaultAsync(x => x.ImageSource.Equals("missing"));

                    if (waifu == null)
                    {
                        await WebhookClients.SauceRequestChannel.SendMessageAsync("`No unknown sauces. Idling...`");

                        return;
                    }
                }
                embeds.Add(WaifuUtil.WaifuEmbedBuilder(waifu).Build());

                var res = await WebUtil.SauceNETSearchAsync(waifu.HostImageUrl);

                if (res.Message.Contains("limit exceeded", StringComparison.OrdinalIgnoreCase))
                {
                    Console.WriteLine("Sauce limit exceeded");
                }
                else
                {
                    embeds.Add(WebUtil.SauceEmbed(res, waifu.HostImageUrl).Build());
                }

                var family = await db.Waifus.AsQueryable().Where(x => x.Source.Equals(waifu.Source) &&
                                                                 !(x.ImageSource == null || x.ImageSource.Equals("retry") || x.ImageSource.Equals("missing"))).ToListAsync();

                family = family.DistinctBy(x => x.ImageSource).ToList();

                string familySauces = "";
                foreach (var w in family)
                {
                    string add = $"**{w.Name}** - {w.ImageSource}\n";
                    if ((familySauces + add).Length < 1900)
                    {
                        familySauces += add;
                    }
                }
                if (familySauces != "")
                {
                    var eb = new EmbedBuilderPrepared();
                    eb.WithTitle("Possible sauces");
                    eb.WithDescription($"Image sauces of waifus from **{waifu.Source}**:\n{familySauces}");
                    embeds.Add(eb.Build());
                }

                if (req == null || req.Channel == null)
                {
                    await WebhookClients.SauceRequestChannel.SendMessageAsync("Missing waifu image sauce", embeds : embeds);
                }
                else
                {
                    foreach (var embed in embeds)
                    {
                        await req.Channel.SendMessageAsync(embed : embed);
                    }
                }
            }
            catch (Exception ex)
            {
                SentrySdk.WithScope(scope =>
                {
                    if (waifu != null)
                    {
                        scope.SetExtras(waifu.GetProperties());
                    }
                    SentrySdk.CaptureException(ex);
                });
                if (req == null || req.Channel == null)
                {
                    await WebhookClients.SauceRequestChannel.SendMessageAsync($"Broke on **{waifu.Name}** - please find source manually.");
                }
                else
                {
                    await req.Channel.SendMessageAsync($"Broke on **{waifu.Name}** - please find source manually.");
                }
            }
        }