mirror of
				https://gitlab.com/Kwoth/nadekobot.git
				synced 2025-11-03 16:24:27 -05:00 
			
		
		
		
	- Fixed calls to SendAsync - they don't require EmbedBuilderService
- DmHelpText now uses smarttext and supports user-related placeholders
This commit is contained in:
		@@ -29,7 +29,7 @@ namespace NadekoBot
 | 
				
			|||||||
            (Footer != null && (!string.IsNullOrWhiteSpace(Footer.Text) || !string.IsNullOrWhiteSpace(Footer.IconUrl))) ||
 | 
					            (Footer != null && (!string.IsNullOrWhiteSpace(Footer.Text) || !string.IsNullOrWhiteSpace(Footer.IconUrl))) ||
 | 
				
			||||||
            (Fields != null && Fields.Length > 0);
 | 
					            (Fields != null && Fields.Length > 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public EmbedBuilder GetEmbed(IEmbedBuilderService eb)
 | 
					        public EmbedBuilder GetEmbed()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var embed = new EmbedBuilder()
 | 
					            var embed = new EmbedBuilder()
 | 
				
			||||||
                .WithColor(Color);
 | 
					                .WithColor(Color);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -469,7 +469,7 @@ namespace NadekoBot.Modules.Administration
 | 
				
			|||||||
                        return;
 | 
					                        return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    text = rep.Replace(text);
 | 
					                    text = rep.Replace(text);
 | 
				
			||||||
                    await ch.SendAsync(_eb, text, sanitizeAll: false);
 | 
					                    await ch.SendAsync(text, sanitizeAll: false);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                else if (ids[1].ToUpperInvariant().StartsWith("U:", StringComparison.InvariantCulture))
 | 
					                else if (ids[1].ToUpperInvariant().StartsWith("U:", StringComparison.InvariantCulture))
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
@@ -480,7 +480,7 @@ namespace NadekoBot.Modules.Administration
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                    var ch = await user.GetOrCreateDMChannelAsync();
 | 
					                    var ch = await user.GetOrCreateDMChannelAsync();
 | 
				
			||||||
                    text = rep.Replace(text);
 | 
					                    text = rep.Replace(text);
 | 
				
			||||||
                    await ch.SendAsync(_eb, text);
 | 
					                    await ch.SendAsync(text);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                else
 | 
					                else
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -156,7 +156,7 @@ namespace NadekoBot.Modules.Administration.Services
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public async Task EditMessage(ICommandContext context, ITextChannel chanl, ulong messageId, string text)
 | 
					        public async Task EditMessage(ICommandContext context, ITextChannel chanl, ulong messageId, string input)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var msg = await chanl.GetMessageAsync(messageId);
 | 
					            var msg = await chanl.GetMessageAsync(messageId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -167,23 +167,10 @@ namespace NadekoBot.Modules.Administration.Services
 | 
				
			|||||||
                    .WithDefault(context)
 | 
					                    .WithDefault(context)
 | 
				
			||||||
                    .Build();
 | 
					                    .Build();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (CREmbed.TryParse(text, out var crembed))
 | 
					            var text = SmartText.CreateFrom(input);
 | 
				
			||||||
            {
 | 
					            text = rep.Replace(text);
 | 
				
			||||||
                rep.Replace(crembed);
 | 
					
 | 
				
			||||||
                await umsg.ModifyAsync(x =>
 | 
					            await umsg.EditAsync(text);
 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    x.Embed = crembed.ToEmbed(_eb).Build();
 | 
					 | 
				
			||||||
                    x.Content = crembed.PlainText?.SanitizeMentions() ?? "";
 | 
					 | 
				
			||||||
                }).ConfigureAwait(false);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                await umsg.ModifyAsync(x =>
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    x.Content = text.SanitizeMentions();
 | 
					 | 
				
			||||||
                    x.Embed = null;
 | 
					 | 
				
			||||||
                }).ConfigureAwait(false);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,7 +23,6 @@ namespace NadekoBot.Modules.Help.Services
 | 
				
			|||||||
        private readonly DiscordPermOverrideService _dpos;
 | 
					        private readonly DiscordPermOverrideService _dpos;
 | 
				
			||||||
        private readonly BotConfigService _bss;
 | 
					        private readonly BotConfigService _bss;
 | 
				
			||||||
        private readonly IEmbedBuilderService _eb;
 | 
					        private readonly IEmbedBuilderService _eb;
 | 
				
			||||||
        private readonly Replacer _rep;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public HelpService(CommandHandler ch,
 | 
					        public HelpService(CommandHandler ch,
 | 
				
			||||||
            IBotStrings strings,
 | 
					            IBotStrings strings,
 | 
				
			||||||
@@ -36,12 +35,6 @@ namespace NadekoBot.Modules.Help.Services
 | 
				
			|||||||
            _dpos = dpos;
 | 
					            _dpos = dpos;
 | 
				
			||||||
            _bss = bss;
 | 
					            _bss = bss;
 | 
				
			||||||
            _eb = eb;
 | 
					            _eb = eb;
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            _rep = new ReplacementBuilder()
 | 
					 | 
				
			||||||
                .WithOverride("%prefix%", () => _bss.Data.Prefix)
 | 
					 | 
				
			||||||
                .WithOverride("%bot.prefix%", () => _bss.Data.Prefix)
 | 
					 | 
				
			||||||
                .Build();
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public Task LateExecute(IGuild guild, IUserMessage msg)
 | 
					        public Task LateExecute(IGuild guild, IUserMessage msg)
 | 
				
			||||||
@@ -52,10 +45,16 @@ namespace NadekoBot.Modules.Help.Services
 | 
				
			|||||||
                if (string.IsNullOrWhiteSpace(settings.DmHelpText) || settings.DmHelpText == "-")
 | 
					                if (string.IsNullOrWhiteSpace(settings.DmHelpText) || settings.DmHelpText == "-")
 | 
				
			||||||
                    return Task.CompletedTask;
 | 
					                    return Task.CompletedTask;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if (CREmbed.TryParse(settings.DmHelpText, out var embed))
 | 
					                var rep = new ReplacementBuilder()
 | 
				
			||||||
                    return msg.Channel.EmbedAsync(_rep.Replace(embed), _eb);
 | 
					                    .WithOverride("%prefix%", () => _bss.Data.Prefix)
 | 
				
			||||||
 | 
					                    .WithOverride("%bot.prefix%", () => _bss.Data.Prefix)
 | 
				
			||||||
 | 
					                    .WithUser(msg.Author)
 | 
				
			||||||
 | 
					                    .Build();
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
                return msg.Channel.SendMessageAsync(_rep.Replace(settings.DmHelpText));
 | 
					                var text = SmartText.CreateFrom(settings.DmHelpText);
 | 
				
			||||||
 | 
					                text = rep.Replace(text);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                return msg.Channel.SendAsync(text);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            return Task.CompletedTask;
 | 
					            return Task.CompletedTask;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -85,7 +85,7 @@ namespace NadekoBot.Modules.Utility
 | 
				
			|||||||
                var text = SmartText.CreateFrom(quote.Text);
 | 
					                var text = SmartText.CreateFrom(quote.Text);
 | 
				
			||||||
                text = rep.Replace(text);
 | 
					                text = rep.Replace(text);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                await ctx.Channel.SendAsync(_eb, $"`#{quote.Id}` 📣 " + text, true);
 | 
					                await ctx.Channel.SendAsync($"`#{quote.Id}` 📣 " + text, true);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            [NadekoCommand, Aliases]
 | 
					            [NadekoCommand, Aliases]
 | 
				
			||||||
@@ -173,7 +173,7 @@ namespace NadekoBot.Modules.Utility
 | 
				
			|||||||
                
 | 
					                
 | 
				
			||||||
                var text = SmartText.CreateFrom(quote.Text);
 | 
					                var text = SmartText.CreateFrom(quote.Text);
 | 
				
			||||||
                text = rep.Replace(text);
 | 
					                text = rep.Replace(text);
 | 
				
			||||||
                await ctx.Channel.SendAsync(_eb, infoText + text, true);
 | 
					                await ctx.Channel.SendAsync(infoText + text, true);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            [NadekoCommand, Aliases]
 | 
					            [NadekoCommand, Aliases]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -48,7 +48,7 @@ namespace NadekoBot.Modules.Utility
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            message = rep.Replace(message);
 | 
					            message = rep.Replace(message);
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
            await channel.SendAsync(_eb, message, !((IGuildUser)Context.User).GuildPermissions.MentionEveryone);
 | 
					            await channel.SendAsync(message, !((IGuildUser)Context.User).GuildPermissions.MentionEveryone);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        [NadekoCommand, Aliases]
 | 
					        [NadekoCommand, Aliases]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -35,6 +35,22 @@ namespace NadekoBot.Extensions
 | 
				
			|||||||
        public static TOut[] Map<TIn, TOut>(this TIn[] arr, Func<TIn, TOut> f)
 | 
					        public static TOut[] Map<TIn, TOut>(this TIn[] arr, Func<TIn, TOut> f)
 | 
				
			||||||
            => Array.ConvertAll(arr, x => f(x));
 | 
					            => Array.ConvertAll(arr, x => f(x));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public static Task EditAsync(this IUserMessage msg, SmartText text)
 | 
				
			||||||
 | 
					            => text switch
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                SmartEmbedText set => msg.ModifyAsync(x =>
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    x.Embed = set.GetEmbed().Build();
 | 
				
			||||||
 | 
					                    x.Content = set.PlainText?.SanitizeMentions() ?? "";
 | 
				
			||||||
 | 
					                }),
 | 
				
			||||||
 | 
					                SmartPlainText spt => msg.ModifyAsync(x =>
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    x.Content = spt.Text.SanitizeMentions();
 | 
				
			||||||
 | 
					                    x.Embed = null;
 | 
				
			||||||
 | 
					                }),
 | 
				
			||||||
 | 
					                _ => throw new ArgumentOutOfRangeException(nameof(text))
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        public static Task<IUserMessage> SendAsync(this IMessageChannel channel, string plainText, Embed embed, bool sanitizeAll = false)
 | 
					        public static Task<IUserMessage> SendAsync(this IMessageChannel channel, string plainText, Embed embed, bool sanitizeAll = false)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            plainText = sanitizeAll
 | 
					            plainText = sanitizeAll
 | 
				
			||||||
@@ -44,10 +60,10 @@ namespace NadekoBot.Extensions
 | 
				
			|||||||
            return channel.SendMessageAsync(plainText, embed: embed);
 | 
					            return channel.SendMessageAsync(plainText, embed: embed);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        public static Task<IUserMessage> SendAsync(this IMessageChannel channel, IEmbedBuilderService eb, SmartText text, bool sanitizeAll = false)
 | 
					        public static Task<IUserMessage> SendAsync(this IMessageChannel channel, SmartText text, bool sanitizeAll = false)
 | 
				
			||||||
            => text switch
 | 
					            => text switch
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                SmartEmbedText set => channel.SendAsync(set.PlainText, set.GetEmbed(eb).Build(), sanitizeAll),
 | 
					                SmartEmbedText set => channel.SendAsync(set.PlainText, set.GetEmbed().Build(), sanitizeAll),
 | 
				
			||||||
                SmartPlainText st => channel.SendAsync(st.Text, null, sanitizeAll),
 | 
					                SmartPlainText st => channel.SendAsync(st.Text, null, sanitizeAll),
 | 
				
			||||||
                _ => throw new ArgumentOutOfRangeException(nameof(text))
 | 
					                _ => throw new ArgumentOutOfRangeException(nameof(text))
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user