Exemplo n.º 1
0
        public async Task InternalDapiCommand(string tag, DapiSearchType type, bool forceExplicit)
        {
            ImageCacherObject imgObj;

            imgObj = await _service.DapiSearch(tag, type, ctx.Guild?.Id, forceExplicit).ConfigureAwait(false);

            if (imgObj == null)
            {
                await ReplyErrorLocalizedAsync("no_results").ConfigureAwait(false);
            }
            else
            {
                var embed = new EmbedBuilder().WithOkColor()
                            .WithDescription($"{ctx.User} [{tag ?? "url"}]({imgObj}) ")
                            .WithFooter(efb => efb.WithText(type.ToString()));

                if (Uri.IsWellFormedUriString(imgObj.FileUrl, UriKind.Absolute))
                {
                    embed.WithImageUrl(imgObj.FileUrl);
                }
                else
                {
                    Log.Error($"Image link from {type} is not a proper Url: {imgObj.FileUrl}");
                }

                await ctx.Channel.EmbedAsync(embed).ConfigureAwait(false);
            }
        }
Exemplo n.º 2
0
        private bool IsValidTag(string tag) => tag.All(x => x != '+' && x != '?' && x != '/'); // tags mustn't contain + or ? or /

        private async Task <UrlReply> GetNsfwImageAsync(ulong guildId, string[] tags, bool forceExplicit, DapiSearchType dapi)
        {
            if (!tags.All(x => IsValidTag(x)))
            {
                return(new UrlReply
                {
                    Error = "One or more tags are invalid.",
                    Url = ""
                });
            }

            Log.Information("Getting {V} image for Guild: {GuildId}...", dapi.ToString(), guildId);
            try
            {
                _blacklistedTags.TryGetValue(guildId, out var blTags);

                var result = await _cache.GetImage(tags, forceExplicit, dapi, blTags);

                if (result is null)
                {
                    return(new UrlReply
                    {
                        Error = "Image not found.",
                        Url = ""
                    });
                }

                var reply = new UrlReply
                {
                    Error    = "",
                    Url      = result.FileUrl,
                    Rating   = result.Rating,
                    Provider = result.SearchType.ToString()
                };

                reply.Tags.AddRange(result.Tags);

                return(reply);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Failed getting {Dapi} image: {Message}", dapi, ex.Message);
                return(new UrlReply
                {
                    Error = ex.Message,
                    Url = ""
                });
            }
        }
Exemplo n.º 3
0
        //[NadekoCommand, Usage, Description, Aliases]
        //public async Task MCPing([Remainder] string query2 = null)
        //{
        //    var query = query2;
        //    if (string.IsNullOrWhiteSpace(query))
        //        return;
        //    await Context.Channel.TriggerTypingAsync().ConfigureAwait(false);
        //    using (var http = new HttpClient())
        //    {
        //        http.DefaultRequestHeaders.Clear();
        //        var ip = query.Split(':')[0];
        //        var port = query.Split(':')[1];
        //        var res = await http.GetStringAsync($"https://api.minetools.eu/ping/{Uri.EscapeUriString(ip)}/{Uri.EscapeUriString(port)}").ConfigureAwait(false);
        //        try
        //        {
        //            var items = JObject.Parse(res);
        //            var sb = new StringBuilder();
        //            var ping = (int)Math.Ceiling(double.Parse(items["latency"].ToString()));
        //            sb.AppendLine($"`Server:` {query}");
        //            sb.AppendLine($"`Version:` {items["version"]["name"]} / Protocol {items["version"]["protocol"]}");
        //            sb.AppendLine($"`Description:` {items["description"]}");
        //            sb.AppendLine($"`Online Players:` {items["players"]["online"]}/{items["players"]["max"]}");
        //            sb.Append($"`Latency:` {ping}");
        //            await Context.Channel.SendMessageAsync(sb.ToString());
        //        }
        //        catch
        //        {
        //            await Context.Channel.SendErrorAsync($"Failed finding `{query}`.").ConfigureAwait(false);
        //        }
        //    }
        //}

        //[NadekoCommand, Usage, Description, Aliases]
        //public async Task MCQ([Remainder] string query = null)
        //{
        //    var arg = query;
        //    if (string.IsNullOrWhiteSpace(arg))
        //    {
        //        await Context.Channel.SendErrorAsync("Please enter `ip:port`.").ConfigureAwait(false);
        //        return;
        //    }
        //    await Context.Channel.TriggerTypingAsync().ConfigureAwait(false);
        //    using (var http = new HttpClient())
        //    {
        //        http.DefaultRequestHeaders.Clear();
        //        try
        //        {
        //            var ip = arg.Split(':')[0];
        //            var port = arg.Split(':')[1];
        //            var res = await http.GetStringAsync($"https://api.minetools.eu/query/{Uri.EscapeUriString(ip)}/{Uri.EscapeUriString(port)}").ConfigureAwait(false);
        //            var items = JObject.Parse(res);
        //            var sb = new StringBuilder();
        //            sb.AppendLine($"`Server:` {arg} 〘Status: {items["status"]}〙");
        //            sb.AppendLine("`Player List (First 5):`");
        //            foreach (var item in items["Playerlist"].Take(5))
        //            {
        //                sb.AppendLine($"〔:rosette: {item}〕");
        //            }
        //            sb.AppendLine($"`Online Players:` {items["Players"]} / {items["MaxPlayers"]}");
        //            sb.AppendLine($"`Plugins:` {items["Plugins"]}");
        //            sb.Append($"`Version:` {items["Version"]}");
        //            await Context.Channel.SendMessageAsync(sb.ToString());
        //        }
        //        catch
        //        {
        //            await Context.Channel.SendErrorAsync($"Failed finding server `{arg}`.").ConfigureAwait(false);
        //        }
        //    }
        //}


        public async Task InternalDapiCommand(IUserMessage umsg, string tag, DapiSearchType type)
        {
            var channel = umsg.Channel;

            tag = tag?.Trim() ?? "";

            var imgObj = await _service.DapiSearch(tag, type, Context.Guild?.Id).ConfigureAwait(false);

            if (imgObj == null)
            {
                await channel.SendErrorAsync(umsg.Author.Mention + " " + GetText("no_results"));
            }
            else
            {
                await channel.EmbedAsync(new EmbedBuilder().WithOkColor()
                                         .WithDescription($"{umsg.Author.Mention} [{tag ?? "url"}]({imgObj.FileUrl})")
                                         .WithImageUrl(imgObj.FileUrl)
                                         .WithFooter(efb => efb.WithText(type.ToString()))).ConfigureAwait(false);
            }
        }
Exemplo n.º 4
0
        public static async Task InternalDapiCommand(IUserMessage umsg, string tag, DapiSearchType type)
        {
            var channel = umsg.Channel;

            tag = tag?.Trim() ?? "";

            var url = await InternalDapiSearch(tag, type).ConfigureAwait(false);

            if (url == null)
            {
                await channel.SendErrorAsync(umsg.Author.Mention + " No results.");
            }
            else
            {
                await channel.EmbedAsync(new EmbedBuilder().WithOkColor()
                                         .WithDescription(umsg.Author.Mention + " " + tag)
                                         .WithImageUrl(url)
                                         .WithFooter(efb => efb.WithText(type.ToString()))).ConfigureAwait(false);
            }
        }
Exemplo n.º 5
0
        public async Task InternalDapiCommand(string tag, DapiSearchType type, bool forceExplicit)
        {
            ImageCacherObject imgObj;

            try
            {
                imgObj = await _service.DapiSearch(tag, type, Context.Guild?.Id, forceExplicit).ConfigureAwait(false);
            }
            catch (TagBlacklistedException)
            {
                await ReplyErrorLocalized("blacklisted_tag").ConfigureAwait(false);

                return;
            }

            if (imgObj == null)
            {
                await ReplyErrorLocalized("not_found").ConfigureAwait(false);
            }
            else
            {
                var embed = new EmbedBuilder().WithOkColor()
                            .WithTitle(type.ToString())
                            .WithDescription($"{Context.User} [{tag ?? "url"}]({imgObj}) ")
                            .WithFooter(efb => efb.WithText("Image Tags: " + string.Join(",", imgObj.Tags)));

                if (Uri.IsWellFormedUriString(imgObj.FileUrl, UriKind.Absolute))
                {
                    embed.WithImageUrl(imgObj.FileUrl);
                }
                else
                {
                    _log.Error($"Image link from {type} is not a proper Url: {imgObj.FileUrl}");
                }

                await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
            }
        }