Esempio n. 1
0
        private async Task InternalHentai(IMessageChannel channel, string tag, bool noError)
        {
            tag = tag?.Trim() ?? "";

            tag = "rating%3Aexplicit+" + tag;

            var           rng      = new NadekoRandom();
            Task <string> provider = Task.FromResult("");

            switch (rng.Next(0, 4))
            {
            case 0:
                provider = GetDanbooruImageLink(tag);
                break;

            case 1:
                provider = GetGelbooruImageLink(tag);
                break;

            case 2:
                provider = GetKonachanImageLink(tag);
                break;

            case 3:
                provider = GetYandereImageLink(tag);
                break;

            default:
                break;
            }
            var link = await provider.ConfigureAwait(false);

            if (string.IsNullOrWhiteSpace(link))
            {
                if (!noError)
                {
                    await channel.SendErrorAsync("No results found.").ConfigureAwait(false);
                }
                return;
            }

            await channel.EmbedAsync(new EmbedBuilder().WithOkColor()
                                     .WithImageUrl(link)
                                     .WithDescription("Tag: " + tag))
            .ConfigureAwait(false);
        }
        public async Task <bool> TryBlockLate(DiscordSocketClient client, IUserMessage msg, IGuild guild, IMessageChannel channel, IUser user, string moduleName, string commandName)
        {
            await Task.Yield();

            if (guild == null)
            {
                return(false);
            }
            else
            {
                var resetCommand = commandName == "resetperms";

                PermissionCache pc = GetCacheFor(guild.Id);
                if (!resetCommand && !pc.Permissions.CheckPermissions(msg, commandName, moduleName, out int index))
                {
                    if (pc.Verbose)
                    {
                        try { await channel.SendErrorAsync(_strings.GetText("trigger", guild.Id, "Permissions".ToLowerInvariant(), index + 1, Format.Bold(pc.Permissions[index].GetCommand(_cmd.GetPrefix(guild), (SocketGuild)guild)))).ConfigureAwait(false); } catch { }
                    }
                    return(true);
                }


                if (moduleName == nameof(Permissions))
                {
                    if (!(user is IGuildUser guildUser))
                    {
                        return(true);
                    }

                    if (guildUser.GuildPermissions.Administrator)
                    {
                        return(false);
                    }

                    var permRole = pc.PermRole;
                    if (!ulong.TryParse(permRole, out var rid))
                    {
                        rid = 0;
                    }
                    string returnMsg;
                    IRole  role;
                    if (string.IsNullOrWhiteSpace(permRole) || (role = guild.GetRole(rid)) == null)
                    {
                        returnMsg = $"You need Admin permissions in order to use permission commands.";
                        if (pc.Verbose)
                        {
                            try { await channel.SendErrorAsync(returnMsg).ConfigureAwait(false); } catch { }
                        }

                        return(true);
                    }
                    else if (!guildUser.RoleIds.Contains(rid))
                    {
                        returnMsg = $"You need the {Format.Bold(role.Name)} role in order to use permission commands.";
                        if (pc.Verbose)
                        {
                            try { await channel.SendErrorAsync(returnMsg).ConfigureAwait(false); } catch { }
                        }

                        return(true);
                    }
                    return(false);
                }
            }

            return(false);
        }
 private async Task <IUserMessage> ErrorAsync(string key, params object[] replacements)
 => await UserChannel.SendErrorAsync(GetText(key, replacements)).ConfigureAwait(false);