feat(bot): don't query db message context when running commands
This commit is contained in:
@@ -89,10 +89,12 @@ public class Autoproxy
|
||||
var eb = new EmbedBuilder()
|
||||
.Title($"Current autoproxy status (for {ctx.Guild.Name.EscapeMarkdown()})");
|
||||
|
||||
var fronters = ctx.MessageContext.LastSwitchMembers;
|
||||
var sw = await ctx.Repository.GetLatestSwitch(ctx.System.Id);
|
||||
var fronters = await ctx.Database.Execute(c => ctx.Repository.GetSwitchMembers(c, sw.Id)).ToListAsync();
|
||||
|
||||
var relevantMember = settings.AutoproxyMode switch
|
||||
{
|
||||
AutoproxyMode.Front => fronters.Length > 0 ? await ctx.Repository.GetMember(fronters[0]) : null,
|
||||
AutoproxyMode.Front => fronters.Count > 0 ? fronters[0] : null,
|
||||
AutoproxyMode.Member when settings.AutoproxyMember.HasValue => await ctx.Repository.GetMember(settings.AutoproxyMember.Value),
|
||||
_ => null
|
||||
};
|
||||
@@ -104,7 +106,7 @@ public class Autoproxy
|
||||
break;
|
||||
case AutoproxyMode.Front:
|
||||
{
|
||||
if (fronters.Length == 0)
|
||||
if (fronters.Count == 0)
|
||||
{
|
||||
eb.Description("Autoproxy is currently set to **front mode** in this server, but there are currently no fronters registered. Use the `pk;switch` command to log a switch.");
|
||||
}
|
||||
@@ -135,7 +137,8 @@ public class Autoproxy
|
||||
default: throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
if (!ctx.MessageContext.AllowAutoproxy)
|
||||
var allowAutoproxy = await ctx.Repository.GetAutoproxyEnabled(ctx.Author.Id);
|
||||
if (!allowAutoproxy)
|
||||
eb.Field(new Embed.Field("\u200b", $"{Emojis.Note} Autoproxy is currently **disabled** for your account (<@{ctx.Author.Id}>). To enable it, use `pk;autoproxy account enable`."));
|
||||
|
||||
return eb.Build();
|
||||
|
@@ -17,10 +17,12 @@ public class Config
|
||||
{
|
||||
var items = new List<PaginatedConfigItem>();
|
||||
|
||||
var allowAutoproxy = await ctx.Repository.GetAutoproxyEnabled(ctx.Author.Id);
|
||||
|
||||
items.Add(new(
|
||||
"autoproxy account",
|
||||
"Whether autoproxy is enabled for the current account",
|
||||
EnabledDisabled(ctx.MessageContext.AllowAutoproxy),
|
||||
EnabledDisabled(allowAutoproxy),
|
||||
"enabled"
|
||||
));
|
||||
|
||||
@@ -122,16 +124,18 @@ public class Config
|
||||
|
||||
public async Task AutoproxyAccount(Context ctx)
|
||||
{
|
||||
var allowAutoproxy = await ctx.Repository.GetAutoproxyEnabled(ctx.Author.Id);
|
||||
|
||||
if (!ctx.HasNext())
|
||||
{
|
||||
await ctx.Reply($"Autoproxy is currently **{EnabledDisabled(ctx.MessageContext.AllowAutoproxy)}** for account <@{ctx.Author.Id}>.");
|
||||
await ctx.Reply($"Autoproxy is currently **{EnabledDisabled(allowAutoproxy)}** for account <@{ctx.Author.Id}>.");
|
||||
return;
|
||||
}
|
||||
|
||||
var allow = ctx.MatchToggle(true);
|
||||
|
||||
var statusString = EnabledDisabled(allow);
|
||||
if (ctx.MessageContext.AllowAutoproxy == allow)
|
||||
if (allowAutoproxy == allow)
|
||||
{
|
||||
await ctx.Reply($"{Emojis.Note} Autoproxy is already {statusString} for account <@{ctx.Author.Id}>.");
|
||||
return;
|
||||
|
@@ -126,8 +126,7 @@ public class ProxiedMessage
|
||||
if ((await ctx.BotPermissions).HasFlag(PermissionSet.ManageMessages))
|
||||
await _rest.DeleteMessage(ctx.Channel.Id, ctx.Message.Id);
|
||||
|
||||
await _logChannel.LogMessage(ctx.MessageContext, msg.Message, ctx.Message, editedMsg,
|
||||
originalMsg!.Content!);
|
||||
await _logChannel.LogMessage(msg.Message, ctx.Message, editedMsg, originalMsg!.Content!);
|
||||
}
|
||||
catch (NotFoundException)
|
||||
{
|
||||
|
@@ -277,7 +277,7 @@ public class SystemEdit
|
||||
await ctx.Reply(
|
||||
$"{Emojis.Success} System server tag changed. Member names will now end with {newTag.AsCode()} when proxied in the current server '{ctx.Guild.Name}'.");
|
||||
|
||||
if (!ctx.MessageContext.TagEnabled)
|
||||
if (!settings.TagEnabled)
|
||||
await ctx.Reply(setDisabledWarning);
|
||||
}
|
||||
|
||||
@@ -288,7 +288,7 @@ public class SystemEdit
|
||||
await ctx.Reply(
|
||||
$"{Emojis.Success} System server tag cleared. Member names will now end with the global system tag, if there is one set.");
|
||||
|
||||
if (!ctx.MessageContext.TagEnabled)
|
||||
if (!settings.TagEnabled)
|
||||
await ctx.Reply(setDisabledWarning);
|
||||
}
|
||||
|
||||
@@ -297,7 +297,7 @@ public class SystemEdit
|
||||
await ctx.Repository.UpdateSystemGuild(target.Id, ctx.Guild.Id,
|
||||
new SystemGuildPatch { TagEnabled = newValue });
|
||||
|
||||
await ctx.Reply(PrintEnableDisableResult(newValue, newValue != ctx.MessageContext.TagEnabled));
|
||||
await ctx.Reply(PrintEnableDisableResult(newValue, newValue != settings.TagEnabled));
|
||||
}
|
||||
|
||||
string PrintEnableDisableResult(bool newValue, bool changedValue)
|
||||
@@ -312,20 +312,20 @@ public class SystemEdit
|
||||
|
||||
if (newValue)
|
||||
{
|
||||
if (ctx.MessageContext.TagEnabled)
|
||||
if (settings.TagEnabled)
|
||||
{
|
||||
if (ctx.MessageContext.SystemGuildTag == null)
|
||||
if (settings.Tag == null)
|
||||
str +=
|
||||
" However, you do not have a system tag specific to this server. Messages will be proxied using your global system tag, if there is one set.";
|
||||
else
|
||||
str +=
|
||||
$" Your current system tag in '{ctx.Guild.Name}' is {ctx.MessageContext.SystemGuildTag.AsCode()}.";
|
||||
$" Your current system tag in '{ctx.Guild.Name}' is {settings.Tag.AsCode()}.";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ctx.MessageContext.SystemGuildTag != null)
|
||||
if (settings.Tag != null)
|
||||
str +=
|
||||
$" Member names will now end with the server-specific tag {ctx.MessageContext.SystemGuildTag.AsCode()} when proxied in the current server '{ctx.Guild.Name}'.";
|
||||
$" Member names will now end with the server-specific tag {settings.Tag.AsCode()} when proxied in the current server '{ctx.Guild.Name}'.";
|
||||
else
|
||||
str +=
|
||||
" Member names will now end with the global system tag when proxied in the current server, if there is one set.";
|
||||
|
Reference in New Issue
Block a user