예제 #1
0
        public LocalizedEmbedBuilder AddToEmbed(LocalizedEmbedBuilder emb, MovieInfo info)
        {
            emb.WithTitle(info.Title);
            emb.WithDescription(info.Plot);
            emb.WithColor(DiscordColor.Yellow);
            emb.WithUrl(this.Service.GetUrl(info.IMDbId));

            emb.AddLocalizedTitleField("str-type", info.Type, inline: true, unknown: false);
            emb.AddLocalizedTitleField("str-year", info.Year, inline: true, unknown: false);
            emb.AddLocalizedTitleField("str-id", info.IMDbId, inline: true, unknown: false);
            emb.AddLocalizedTitleField("str-genre", info.Genre, inline: true, unknown: false);
            emb.AddLocalizedTitleField("str-rel-date", info.ReleaseDate, inline: true, unknown: false);
            emb.AddLocalizedField("str-score", "fmt-rating-imdb", inline: true, contentArgs: new[] { info.IMDbRating, info.IMDbVotes });
            emb.AddLocalizedTitleField("str-rating", info.Rated, inline: true, unknown: false);
            emb.AddLocalizedTitleField("str-duration", info.Duration, inline: true, unknown: false);
            emb.AddLocalizedTitleField("str-writer", info.Writer, inline: true, unknown: false);
            emb.AddLocalizedTitleField("str-director", info.Director, inline: true, unknown: false);
            emb.AddLocalizedTitleField("str-actors", info.Actors, inline: true, unknown: false);
            if (!string.IsNullOrWhiteSpace(info.Poster) && info.Poster != "N/A")
            {
                emb.WithThumbnail(info.Poster);
            }

            emb.WithLocalizedFooter("fmt-powered-by", null, "OMDb");
            return(emb);
        }
예제 #2
0
        private async Task CreateWebhookAsync(CommandContext ctx, DiscordChannel channel, string name, Uri?avatarUrl, string?reason)
        {
            // TODO what about other channel types? news, store etc?
            if (channel?.Type != ChannelType.Text)
            {
                throw new InvalidCommandUsageException(ctx, "cmd-err-chn-type-text");
            }

            if (string.IsNullOrWhiteSpace(name) || name.Length > DiscordLimits.NameLimit)
            {
                throw new CommandFailedException(ctx, "cmd-err-name", DiscordLimits.NameLimit);
            }

            DiscordWebhook wh;

            if (avatarUrl is null)
            {
                wh = await channel.CreateWebhookAsync(name, reason : ctx.BuildInvocationDetailsString(reason));
            }
            else
            {
                (_, HttpContentHeaders headers) = await HttpService.HeadAsync(avatarUrl);

                if (!headers.ContentTypeHeaderIsImage() || headers.ContentLength.GetValueOrDefault() > 8 * 1024 * 1024)
                {
                    throw new CommandFailedException(ctx, "err-url-image-8mb");
                }
                try {
                    using MemoryStream ms = await HttpService.GetMemoryStreamAsync(avatarUrl);

                    wh = await channel.CreateWebhookAsync(name, ms, reason : ctx.BuildInvocationDetailsString(reason));
                } catch (WebException e) {
                    throw new CommandFailedException(ctx, "err-url-image-fail", e);
                }
            }

            if (await ctx.WaitForBoolReplyAsync("q-send-token"))
            {
                try {
                    DiscordDmChannel?dm = await ctx.Client.CreateDmChannelAsync(ctx.User.Id);

                    if (dm is { })
                    {
                        var emb = new LocalizedEmbedBuilder(this.Localization, ctx.Guild.Id);
                        emb.WithLocalizedTitle("fmt-wh-add", Formatter.Bold(Formatter.Strip(wh.Name)), channel.Mention);
                        emb.WithDescription($"||{wh.BuildUrlString()}||");
                        emb.WithColor(this.ModuleColor);
                        emb.WithThumbnail(wh.AvatarUrl);
                        emb.AddLocalizedTitleField("str-id", wh.Id, inline: true);
                        emb.AddLocalizedTitleField("str-name", wh.Name, inline: true);
                        emb.AddLocalizedTitleField("str-token", $"||{wh.Token}||");
                        await dm.SendMessageAsync(embed : emb.Build());
                    }
                    else
                    {
                        await ctx.FailAsync("err-dm-fail");
                    }
                } catch {
예제 #3
0
 private LocalizedEmbedBuilder AddDataToEmbed(LocalizedEmbedBuilder emb, PartialWeatherData data)
 {
     emb.WithColor(this.ModuleColor);
     emb.AddLocalizedTitleField("str-w-condition", data.Weather.Select(w => w.Main).JoinWith(", "), inline: true, titleArgs: Emojis.Cloud);
     emb.AddLocalizedTitleField("str-w-humidity", $"{data.Main.Humidity}%", inline: true, titleArgs: Emojis.Drops);
     emb.AddLocalizedTitleField("str-w-temp", $"{data.Main.Temp:F1}°C", inline: true, titleArgs: Emojis.Thermometer);
     emb.AddLocalizedTitleField("str-w-temp-minmax", $"{data.Main.TempMin:F1}°C / {data.Main.TempMax:F1}°C", inline: true, titleArgs: Emojis.Thermometer);
     emb.AddLocalizedTitleField("str-w-wind", $"{data.Wind.Speed} m/s", inline: true, titleArgs: Emojis.Wind);
     emb.WithThumbnail(WeatherService.GetWeatherIconUrl(data.Weather[0]));
     emb.WithLocalizedFooter("fmt-powered-by", null, "openweathermap.org");
     return(emb);
 }
예제 #4
0
        public async Task InfoAsync(CommandContext ctx,
                                    [Description("desc-emoji-info")] DiscordEmoji emoji)
        {
            try {
                DiscordGuildEmoji gemoji = await ctx.Guild.GetEmojiAsync(emoji.Id);

                var emb = new LocalizedEmbedBuilder(this.Localization, ctx.Guild.Id);
                emb.WithColor(this.ModuleColor);
                emb.WithLocalizedTitle("str-emoji-details");
                emb.WithDescription($"{gemoji.GetDiscordName()} ({gemoji.Id})");
                emb.WithThumbnail(gemoji.Url);

                emb.AddLocalizedTitleField("str-created-by", gemoji.User?.ToDiscriminatorString(), inline: true);
                emb.AddLocalizedTitleField("str-animated", gemoji.IsAnimated, inline: true);
                emb.AddLocalizedTitleField("str-managed", gemoji.IsManaged, inline: true);
                emb.AddLocalizedTitleField("str-url", gemoji.Url);
                emb.AddLocalizedTimestampField("str-created-at", gemoji.CreationTimestamp);

                await ctx.RespondAsync(embed : emb.Build());
            } catch (NotFoundException) {
                throw new CommandFailedException(ctx, "cmd-err-emoji-404");
            }
        }
예제 #5
0
        public static DiscordEmbed ToDiscordEmbed(this GuildConfig gcfg, DiscordGuild guild, LocalizationService lcs, bool update = false)
        {
            var emb = new LocalizedEmbedBuilder(lcs, guild.Id);

            emb.WithLocalizedTitle(DiscordEventType.GuildUpdated, update ? "evt-cfg-update" : "str-guild-cfg");
            emb.WithThumbnail(guild.IconUrl);

            emb.AddLocalizedTitleField("str-prefix", gcfg.Prefix ?? lcs.GetString(guild.Id, "str-default"), inline: true);
            emb.AddLocalizedTitleField("str-silent", gcfg.ReactionResponse, inline: true);
            emb.AddLocalizedTitleField("str-cmd-suggestions", gcfg.SuggestionsEnabled, inline: true);

            if (gcfg.LoggingEnabled)
            {
                DiscordChannel?logchn = guild.GetChannel(gcfg.LogChannelId);
                if (logchn is null)
                {
                    emb.AddLocalizedField("str-logging", "err-log-404", inline: true);
                }
                else
                {
                    emb.AddLocalizedField("str-logging", "fmt-logs", inline: true, contentArgs: new[] { logchn.Mention });
                }
            }
            else
            {
                emb.AddLocalizedField("str-logging", "str-off", inline: true);
            }

            emb.AddLocalizedField("str-backup", gcfg.BackupEnabled ? "str-enabled" : "str-disabled", inline: true);

            if (gcfg.WelcomeChannelId != default)
            {
                DiscordChannel?wchn = guild.GetChannel(gcfg.WelcomeChannelId);
                if (wchn is null)
                {
                    emb.AddLocalizedField("str-memupd-w", "err-memupd-w-404", inline: true);
                }
                else
                {
                    emb.AddLocalizedField("str-memupd-w", "fmt-memupd", inline: true, contentArgs: new[] {
                        wchn.Mention,
                        Formatter.Strip(gcfg.WelcomeMessage ?? lcs.GetString(guild.Id, "str-default"))
                    });
                }
            }
            else
            {
                emb.AddLocalizedField("str-memupd-w", "str-off", inline: true);
            }

            if (gcfg.LeaveChannelId != default)
            {
                DiscordChannel?lchn = guild.GetChannel(gcfg.LeaveChannelId);
                if (lchn is null)
                {
                    emb.AddLocalizedField("str-memupd-l", "err-memupd-l-404", inline: true);
                }
                else
                {
                    emb.AddLocalizedField("str-memupd-l", "fmt-memupd", inline: true, contentArgs: new[] {
                        lchn.Mention,
                        Formatter.Strip(gcfg.LeaveMessage ?? lcs.GetString(guild.Id, "str-default"))
                    });
                }
            }
            else
            {
                emb.AddLocalizedField("str-memupd-l", "str-off", inline: true);
            }

            emb.AddLocalizedTitleField("str-ratelimit", gcfg.RatelimitSettings.ToEmbedFieldString(guild.Id, lcs), inline: true);
            emb.AddLocalizedTitleField("str-antispam", gcfg.AntispamSettings.ToEmbedFieldString(guild.Id, lcs), inline: true);
            emb.AddLocalizedTitleField("str-antiflood", gcfg.AntifloodSettings.ToEmbedFieldString(guild.Id, lcs), inline: true);
            emb.AddLocalizedTitleField("str-instantleave", gcfg.AntiInstantLeaveSettings.ToEmbedFieldString(guild.Id, lcs), inline: true);

            if (gcfg.MuteRoleId != default)
            {
                DiscordRole?muteRole = guild.GetRole(gcfg.MuteRoleId);
                if (muteRole is null)
                {
                    emb.AddLocalizedField("str-muterole", "err-muterole-404", inline: true);
                }
                else
                {
                    emb.AddLocalizedTitleField("str-muterole", muteRole.Name, inline: true);
                }
            }
            else
            {
                emb.AddLocalizedField("str-muterole", "str-none", inline: true);
            }

            emb.AddLocalizedTitleField("str-lf", gcfg.LinkfilterSettings.ToEmbedFieldString(guild.Id, lcs), inline: true);

            return(emb.Build());
        }