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

@ -30,7 +30,7 @@ public class Context
public Context(ILifetimeScope provider, int shardId, Guild? guild, Channel channel, MessageCreateEvent message,
int commandParseOffset, PKSystem senderSystem, SystemConfig config,
GuildConfig? guildConfig)
GuildConfig? guildConfig, string[] prefixes)
{
Message = (Message)message;
ShardId = shardId;
@ -47,6 +47,7 @@ public class Context
_provider = provider;
_commandMessageService = provider.Resolve<CommandMessageService>();
CommandPrefix = message.Content?.Substring(0, commandParseOffset);
DefaultPrefix = prefixes[0];
Parameters = new Parameters(message.Content?.Substring(commandParseOffset));
Rest = provider.Resolve<DiscordApiClient>();
Cluster = provider.Resolve<Cluster>();
@ -74,6 +75,7 @@ public class Context
public DateTimeZone Zone => Config?.Zone ?? DateTimeZone.Utc;
public readonly string CommandPrefix;
public readonly string DefaultPrefix;
public readonly Parameters Parameters;
internal readonly IDatabase Database;
@ -115,7 +117,7 @@ public class Context
if (deprecated && commandDef != null)
{
await Reply($"{Emojis.Warn} Server configuration has moved to `pk;serverconfig`. The command you are trying to run is now `pk;{commandDef.Key}`.");
await Reply($"{Emojis.Warn} Server configuration has moved to `{DefaultPrefix}serverconfig`. The command you are trying to run is now `{DefaultPrefix}{commandDef.Key}`.");
}
try
@ -127,7 +129,7 @@ public class Context
}
catch (PKSyntaxError e)
{
await Reply($"{Emojis.Error} {e.Message}\n**Command usage:**\n> pk;{commandDef?.Usage}");
await Reply($"{Emojis.Error} {e.Message}\n**Command usage:**\n> {DefaultPrefix}{commandDef?.Usage}");
}
catch (PKError e)
{

View file

@ -51,21 +51,21 @@ public static class ContextChecksExt
public static Context CheckSystem(this Context ctx)
{
if (ctx.System == null)
throw Errors.NoSystemError;
throw Errors.NoSystemError(ctx.DefaultPrefix);
return ctx;
}
public static Context CheckSystem(this Context ctx, PKSystem system)
{
if (system == null)
throw Errors.NoSystemError;
throw Errors.NoSystemError(ctx.DefaultPrefix);
return ctx;
}
public static Context CheckNoSystem(this Context ctx)
{
if (ctx.System != null)
throw Errors.ExistingSystemError;
throw Errors.ExistingSystemError(ctx.DefaultPrefix);
return ctx;
}