mirror of
				https://gitlab.com/Kwoth/nadekobot.git
				synced 2025-11-03 16:24:27 -05:00 
			
		
		
		
	ban templates will now use smarttext instead of crembed
This commit is contained in:
		@@ -413,7 +413,7 @@ WHERE GuildId={guildId}
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public CREmbed GetBanUserDmEmbed(ICommandContext context, IGuildUser target, string defaultMessage,
 | 
			
		||||
        public SmartText GetBanUserDmEmbed(ICommandContext context, IGuildUser target, string defaultMessage,
 | 
			
		||||
            string banReason, TimeSpan? duration)
 | 
			
		||||
        {
 | 
			
		||||
            return GetBanUserDmEmbed(
 | 
			
		||||
@@ -426,7 +426,7 @@ WHERE GuildId={guildId}
 | 
			
		||||
                duration);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public CREmbed GetBanUserDmEmbed(DiscordSocketClient client, SocketGuild guild,
 | 
			
		||||
        public SmartText GetBanUserDmEmbed(DiscordSocketClient client, SocketGuild guild,
 | 
			
		||||
            IGuildUser moderator, IGuildUser target, string defaultMessage, string banReason, TimeSpan? duration)
 | 
			
		||||
        {
 | 
			
		||||
            var template = GetBanTemplate(guild.Id);
 | 
			
		||||
@@ -450,7 +450,6 @@ WHERE GuildId={guildId}
 | 
			
		||||
                .WithOverride("%ban.duration%", () => duration?.ToString(@"d\.hh\:mm")?? "perma")
 | 
			
		||||
                .Build();
 | 
			
		||||
 | 
			
		||||
            CREmbed crEmbed = null; 
 | 
			
		||||
            // if template isn't set, use the old message style
 | 
			
		||||
            if (string.IsNullOrWhiteSpace(template))
 | 
			
		||||
            {
 | 
			
		||||
@@ -459,8 +458,6 @@ WHERE GuildId={guildId}
 | 
			
		||||
                    color = Bot.ErrorColor.RawValue,
 | 
			
		||||
                    description = defaultMessage 
 | 
			
		||||
                });
 | 
			
		||||
                
 | 
			
		||||
                CREmbed.TryParse(template, out crEmbed);
 | 
			
		||||
            }
 | 
			
		||||
            // if template is set to "-" do not dm the user
 | 
			
		||||
            else if (template == "-")
 | 
			
		||||
@@ -468,23 +465,18 @@ WHERE GuildId={guildId}
 | 
			
		||||
                return default;
 | 
			
		||||
            }
 | 
			
		||||
            // if template is an embed, send that embed with replacements
 | 
			
		||||
            else if (CREmbed.TryParse(template, out crEmbed))
 | 
			
		||||
            {
 | 
			
		||||
                replacer.Replace(crEmbed);
 | 
			
		||||
            }
 | 
			
		||||
            // otherwise, treat template as a regular string with replacements
 | 
			
		||||
            else
 | 
			
		||||
            else if (!SmartText.CreateFrom(template).IsEmbed)
 | 
			
		||||
            {
 | 
			
		||||
                template = JsonConvert.SerializeObject(new
 | 
			
		||||
                {
 | 
			
		||||
                    color = Bot.ErrorColor.RawValue,
 | 
			
		||||
                    description = replacer.Replace(template) 
 | 
			
		||||
                    description = template
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
                CREmbed.TryParse(template, out crEmbed);
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
            return crEmbed;
 | 
			
		||||
            var output = SmartText.CreateFrom(template);
 | 
			
		||||
            return replacer.Replace(output);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -433,7 +433,7 @@ namespace NadekoBot.Modules.Administration
 | 
			
		||||
                        if (embed is not null)
 | 
			
		||||
                        {
 | 
			
		||||
                            var userChannel = await guildUser.GetOrCreateDMChannelAsync();
 | 
			
		||||
                            await userChannel.EmbedAsync(embed, _eb);
 | 
			
		||||
                            await userChannel.SendAsync(embed);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    catch
 | 
			
		||||
@@ -500,7 +500,7 @@ namespace NadekoBot.Modules.Administration
 | 
			
		||||
                    if (embed is not null)
 | 
			
		||||
                    {
 | 
			
		||||
                        var userChannel = await user.GetOrCreateDMChannelAsync();
 | 
			
		||||
                        await userChannel.EmbedAsync(embed, _eb);
 | 
			
		||||
                        await userChannel.SendAsync(embed);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                catch
 | 
			
		||||
@@ -577,13 +577,13 @@ namespace NadekoBot.Modules.Administration
 | 
			
		||||
            {
 | 
			
		||||
                var dmChannel = await ctx.User.GetOrCreateDMChannelAsync();
 | 
			
		||||
                var defaultMessage = GetText("bandm", Format.Bold(ctx.Guild.Name), reason);
 | 
			
		||||
                var crEmbed = _service.GetBanUserDmEmbed(Context,
 | 
			
		||||
                var embed = _service.GetBanUserDmEmbed(Context,
 | 
			
		||||
                    (IGuildUser)Context.User,
 | 
			
		||||
                    defaultMessage,
 | 
			
		||||
                    reason,
 | 
			
		||||
                    duration);
 | 
			
		||||
 | 
			
		||||
                if (crEmbed is null)
 | 
			
		||||
                if (embed is null)
 | 
			
		||||
                {
 | 
			
		||||
                    await ConfirmLocalizedAsync("bandm_disabled");
 | 
			
		||||
                }
 | 
			
		||||
@@ -591,7 +591,7 @@ namespace NadekoBot.Modules.Administration
 | 
			
		||||
                {
 | 
			
		||||
                    try
 | 
			
		||||
                    {
 | 
			
		||||
                        await dmChannel.EmbedAsync(crEmbed, _eb);
 | 
			
		||||
                        await dmChannel.SendAsync(embed);
 | 
			
		||||
                    }
 | 
			
		||||
                    catch (Exception)
 | 
			
		||||
                    {
 | 
			
		||||
 
 | 
			
		||||
@@ -49,7 +49,7 @@ namespace NadekoBot.Modules.Help
 | 
			
		||||
            _lazyClientId = new AsyncLazy<ulong>(async () => (await _client.GetApplicationInfoAsync()).Id);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public async Task<(string plainText, IEmbedBuilder embed)> GetHelpStringEmbed()
 | 
			
		||||
        public async Task<SmartText> GetHelpString()
 | 
			
		||||
        {
 | 
			
		||||
            var botSettings = _bss.Data;
 | 
			
		||||
            if (string.IsNullOrWhiteSpace(botSettings.HelpText) || botSettings.HelpText == "-")
 | 
			
		||||
@@ -64,18 +64,8 @@ namespace NadekoBot.Modules.Help
 | 
			
		||||
                .WithOverride("%bot.prefix%", () => Prefix)
 | 
			
		||||
                .Build();
 | 
			
		||||
 | 
			
		||||
            var app = await _client.GetApplicationInfoAsync();
 | 
			
		||||
 | 
			
		||||
            if (!CREmbed.TryParse(botSettings.HelpText, out var embed))
 | 
			
		||||
            {
 | 
			
		||||
                var eb = _eb.Create().WithOkColor()
 | 
			
		||||
                    .WithDescription(String.Format(botSettings.HelpText, clientId, Prefix));
 | 
			
		||||
                return ("", eb);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            r.Replace(embed);
 | 
			
		||||
 | 
			
		||||
            return (embed.PlainText, embed.ToEmbed(_eb));
 | 
			
		||||
            var text = SmartText.CreateFrom(botSettings.HelpText);
 | 
			
		||||
            return r.Replace(text);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [NadekoCommand, Aliases]
 | 
			
		||||
@@ -271,11 +261,10 @@ namespace NadekoBot.Modules.Help
 | 
			
		||||
                    : channel;
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                    var data = await GetHelpStringEmbed();
 | 
			
		||||
                    var data = await GetHelpString();
 | 
			
		||||
                    if (data == default)
 | 
			
		||||
                        return;
 | 
			
		||||
                    var (plainText, helpEmbed) = data;
 | 
			
		||||
                    await ch.EmbedAsync(helpEmbed, msg: plainText ?? "").ConfigureAwait(false);
 | 
			
		||||
                    await ch.SendAsync(data);
 | 
			
		||||
                    try{ await ctx.OkAsync(); } catch { } // ignore if bot can't react
 | 
			
		||||
                }
 | 
			
		||||
                catch (Exception)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user