feat: dynamically show primary command prefix

This commit is contained in:
rladenson 2024-12-31 08:09:18 -07:00 committed by Petal Ladenson
parent 1d50022d6d
commit edfc6714d6
30 changed files with 202 additions and 197 deletions

View file

@ -57,11 +57,11 @@ public class ProxyService
}
public async Task<bool> HandleIncomingMessage(MessageCreateEvent message, MessageContext ctx,
Guild guild, Channel channel, bool allowAutoproxy, PermissionSet botPermissions)
Guild guild, Channel channel, bool allowAutoproxy, PermissionSet botPermissions, string prefix)
{
var rootChannel = await _cache.GetRootChannel(message.GuildId!.Value, message.ChannelId);
if (!ShouldProxy(channel, rootChannel, message, ctx))
if (!ShouldProxy(channel, rootChannel, message, ctx, prefix))
return false;
var autoproxySettings = await _repo.GetAutoproxySettings(ctx.SystemId.Value, guild.Id, null);
@ -81,10 +81,10 @@ public class ProxyService
using (_metrics.Measure.Timer.Time(BotMetrics.ProxyMembersQueryTime))
members = (await _repo.GetProxyMembers(message.Author.Id, message.GuildId!.Value)).ToList();
if (!_matcher.TryMatch(ctx, autoproxySettings, members, out var match, message.Content, message.Attachments.Length > 0,
if (!_matcher.TryMatch(ctx, autoproxySettings, members, out var match, message.Content, prefix, message.Attachments.Length > 0,
allowAutoproxy, ctx.CaseSensitiveProxyTags)) return false;
var canProxy = await CanProxy(channel, rootChannel, message, ctx);
var canProxy = await CanProxy(channel, rootChannel, message, ctx, prefix);
if (canProxy != null)
{
if (ctx.ProxyErrorMessageEnabled)
@ -112,7 +112,7 @@ public class ProxyService
}
// Proxy checks that give user errors
public async Task<string> CanProxy(Channel channel, Channel rootChannel, Message msg, MessageContext ctx)
public async Task<string> CanProxy(Channel channel, Channel rootChannel, Message msg, MessageContext ctx, string prefix)
{
if (!DiscordUtils.IsValidGuildChannel(channel))
return $"PluralKit cannot proxy messages in this type of channel.";
@ -128,13 +128,13 @@ public class ProxyService
if (!ctx.TagEnabled)
{
return "This server requires PluralKit users to have a system tag, but your system tag is disabled in this server. " +
"Use `pk;s servertag -enable` to enable it for this server.";
$"Use `{prefix}s servertag -enable` to enable it for this server.";
}
if (!ctx.HasProxyableTag())
{
return "This server requires PluralKit users to have a system tag, but you do not have one set. " +
"A system tag can be set for all servers with `pk;s tag`, or for just this server with `pk;s servertag`.";
$"A system tag can be set for all servers with `{prefix}s tag`, or for just this server with `{prefix}s servertag`.";
}
}
@ -154,11 +154,11 @@ public class ProxyService
}
// Proxy checks that don't give user errors unless `pk;debug proxy` is used
public bool ShouldProxy(Channel channel, Channel rootChannel, Message msg, MessageContext ctx)
public bool ShouldProxy(Channel channel, Channel rootChannel, Message msg, MessageContext ctx, string prefix)
{
// Make sure author has a system
if (ctx.SystemId == null)
throw new ProxyChecksFailedException(Errors.NoSystemError.Message);
throw new ProxyChecksFailedException(Errors.NoSystemError(prefix).Message);
// Make sure channel is a guild text channel and this is a normal message
if (!DiscordUtils.IsValidGuildChannel(channel))
@ -182,7 +182,7 @@ public class ProxyService
// Make sure the system has proxying enabled in the server
if (!ctx.ProxyEnabled)
throw new ProxyChecksFailedException(
"Your system has proxying disabled in this server. Type `pk;proxy on` to enable it.");
$"Your system has proxying disabled in this server. Type `{prefix}proxy on` to enable it.");
// Make sure we have an attachment, message content, or poll
var isMessageBlank = msg.Content == null || msg.Content.Trim().Length == 0;
@ -259,7 +259,7 @@ public class ProxyService
await HandleProxyExecutedActions(ctx, autoproxySettings, trigger, proxyMessage, match);
}
public async Task ExecuteReproxy(Message trigger, PKMessage msg, List<ProxyMember> members, ProxyMember member)
public async Task ExecuteReproxy(Message trigger, PKMessage msg, List<ProxyMember> members, ProxyMember member, string prefix)
{
var originalMsg = await _rest.GetMessageOrNull(msg.Channel, msg.Mid);
if (originalMsg == null)
@ -279,7 +279,7 @@ public class ProxyService
var autoproxySettings = await _repo.GetAutoproxySettings(ctx.SystemId.Value, msg.Guild!.Value, null);
var config = await _repo.GetSystemConfig(ctx.SystemId.Value);
var prevMatched = _matcher.TryMatch(ctx, autoproxySettings, members, out var prevMatch, originalMsg.Content,
var prevMatched = _matcher.TryMatch(ctx, autoproxySettings, members, out var prevMatch, originalMsg.Content, prefix,
originalMsg.Attachments.Length > 0, false, ctx.CaseSensitiveProxyTags);
var match = new ProxyMatch