mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-13 18:58:27 -04:00
Finished new response system
This commit is contained in:
@@ -2,11 +2,22 @@ using NadekoBot.Common.ModuleBehaviors;
|
||||
|
||||
namespace NadekoBot.Modules.Help.Services;
|
||||
|
||||
public class HelpService(BotConfigService bss, IReplacementService repSvc) : IExecNoCommand, INService
|
||||
public class HelpService : IExecNoCommand, INService
|
||||
{
|
||||
private readonly BotConfigService _bss;
|
||||
private readonly IReplacementService _rs;
|
||||
private readonly IMessageSenderService _sender;
|
||||
|
||||
public HelpService(BotConfigService bss, IReplacementService repSvc, IMessageSenderService sender)
|
||||
{
|
||||
_bss = bss;
|
||||
_rs = repSvc;
|
||||
_sender = sender;
|
||||
}
|
||||
|
||||
public async Task ExecOnNoCommandAsync(IGuild? guild, IUserMessage msg)
|
||||
{
|
||||
var settings = bss.Data;
|
||||
var settings = _bss.Data;
|
||||
if (guild is null)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(settings.DmHelpText) || settings.DmHelpText == "-")
|
||||
@@ -14,20 +25,20 @@ public class HelpService(BotConfigService bss, IReplacementService repSvc) : IEx
|
||||
|
||||
// only send dm help text if it contains one of the keywords, if they're specified
|
||||
// if they're not, then reply to every DM
|
||||
if (settings.DmHelpTextKeywords is not null &&
|
||||
!settings.DmHelpTextKeywords.Any(k => msg.Content.Contains(k)))
|
||||
if (settings.DmHelpTextKeywords is not null
|
||||
&& !settings.DmHelpTextKeywords.Any(k => msg.Content.Contains(k)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var repCtx = new ReplacementContext(guild: guild, channel: msg.Channel, users: msg.Author)
|
||||
.WithOverride("%prefix%", () => bss.Data.Prefix)
|
||||
.WithOverride("%bot.prefix%", () => bss.Data.Prefix);
|
||||
.WithOverride("%prefix%", () => _bss.Data.Prefix)
|
||||
.WithOverride("%bot.prefix%", () => _bss.Data.Prefix);
|
||||
|
||||
var text = SmartText.CreateFrom(settings.DmHelpText);
|
||||
text = await repSvc.ReplaceAsync(text, repCtx);
|
||||
text = await _rs.ReplaceAsync(text, repCtx);
|
||||
|
||||
await msg.Channel.SendAsync(text);
|
||||
await _sender.Response(msg.Channel).Text(text).SendAsync();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user