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

@ -19,11 +19,11 @@ public class ProxyMatcher
}
public bool TryMatch(MessageContext ctx, AutoproxySettings settings, IReadOnlyCollection<ProxyMember> members, out ProxyMatch match,
string messageContent,
string messageContent, string prefix,
bool hasAttachments, bool allowAutoproxy, bool caseSensitive)
{
if (TryMatchTags(members, messageContent, hasAttachments, caseSensitive, out match)) return true;
if (allowAutoproxy && TryMatchAutoproxy(ctx, settings, members, messageContent, out match)) return true;
if (allowAutoproxy && TryMatchAutoproxy(ctx, settings, members, messageContent, prefix, out match)) return true;
return false;
}
@ -38,14 +38,14 @@ public class ProxyMatcher
}
private bool TryMatchAutoproxy(MessageContext ctx, AutoproxySettings settings, IReadOnlyCollection<ProxyMember> members,
string messageContent,
string messageContent, string prefix,
out ProxyMatch match)
{
match = default;
if (!ctx.AllowAutoproxy)
throw new ProxyService.ProxyChecksFailedException(
"Autoproxy is disabled for your account. Type `pk;cfg autoproxy account enable` to re-enable it.");
$"Autoproxy is disabled for your account. Type `{prefix}cfg autoproxy account enable` to re-enable it.");
// Skip autoproxy match if we hit the escape character
if (messageContent.StartsWith(AutoproxyEscapeCharacter))
@ -71,7 +71,7 @@ public class ProxyMatcher
{
if (settings.AutoproxyMode == AutoproxyMode.Front)
throw new ProxyService.ProxyChecksFailedException(
"You are using autoproxy front, but no members are currently registered as fronting. Please use `pk;switch <member>` to log a new switch.");
$"You are using autoproxy front, but no members are currently registered as fronting. Please use `{prefix}switch <member>` to log a new switch.");
if (settings.AutoproxyMode == AutoproxyMode.Member)
throw new ProxyService.ProxyChecksFailedException(
"You are using member-specific autoproxy with an invalid member. Was this member deleted?");
@ -84,7 +84,7 @@ public class ProxyMatcher
if (settings.AutoproxyMode != AutoproxyMode.Member && !member.AllowAutoproxy)
throw new ProxyService.ProxyChecksFailedException(
"This member has autoproxy disabled. To enable it, use `pk;m <member> autoproxy on`.");
$"This member has autoproxy disabled. To enable it, use `{prefix}m <member> autoproxy on`.");
// Moved the IsLatchExpired() check to here, so that an expired latch and a latch without any previous messages throw different errors
if (settings.AutoproxyMode == AutoproxyMode.Latch && IsLatchExpired(ctx, settings))

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