Invalidate proxy caches on more editing commands

This commit is contained in:
Ske 2019-08-12 17:49:07 +02:00
parent d8503001eb
commit fb7f31d42d
2 changed files with 23 additions and 1 deletions

View File

@ -48,6 +48,8 @@ namespace PluralKit.Bot.Commands
// Send confirmation and space hint // Send confirmation and space hint
await Context.Channel.SendMessageAsync($"{Emojis.Success} Member \"{memberName.Sanitize()}\" (`{member.Hid}`) registered! See the user guide for commands for editing this member: https://pluralkit.me/guide#member-management"); await Context.Channel.SendMessageAsync($"{Emojis.Success} Member \"{memberName.Sanitize()}\" (`{member.Hid}`) registered! See the user guide for commands for editing this member: https://pluralkit.me/guide#member-management");
if (memberName.Contains(" ")) await Context.Channel.SendMessageAsync($"{Emojis.Note} Note that this member's name contains spaces. You will need to surround it with \"double quotes\" when using commands referring to it, or just use the member's 5-character ID (which is `{member.Hid}`)."); if (memberName.Contains(" ")) await Context.Channel.SendMessageAsync($"{Emojis.Note} Note that this member's name contains spaces. You will need to surround it with \"double quotes\" when using commands referring to it, or just use the member's 5-character ID (which is `{member.Hid}`).");
await ProxyCache.InvalidateResultsForSystem(Context.SenderSystem);
} }
[Command("rename")] [Command("rename")]
@ -80,6 +82,8 @@ namespace PluralKit.Bot.Commands
await Context.Channel.SendMessageAsync($"{Emojis.Success} Member renamed."); await Context.Channel.SendMessageAsync($"{Emojis.Success} Member renamed.");
if (newName.Contains(" ")) await Context.Channel.SendMessageAsync($"{Emojis.Note} Note that this member's name now contains spaces. You will need to surround it with \"double quotes\" when using commands referring to it."); if (newName.Contains(" ")) await Context.Channel.SendMessageAsync($"{Emojis.Note} Note that this member's name now contains spaces. You will need to surround it with \"double quotes\" when using commands referring to it.");
if (ContextEntity.DisplayName != null) await Context.Channel.SendMessageAsync($"{Emojis.Note} Note that this member has a display name set (`{ContextEntity.DisplayName}`), and will be proxied using that name instead."); if (ContextEntity.DisplayName != null) await Context.Channel.SendMessageAsync($"{Emojis.Note} Note that this member has a display name set (`{ContextEntity.DisplayName}`), and will be proxied using that name instead.");
await ProxyCache.InvalidateResultsForSystem(Context.SenderSystem);
} }
[Command("description")] [Command("description")]
@ -173,7 +177,7 @@ namespace PluralKit.Bot.Commands
await Members.Save(ContextEntity); await Members.Save(ContextEntity);
await Context.Channel.SendMessageAsync($"{Emojis.Success} Member proxy tags changed to `{ContextEntity.ProxyString.Sanitize()}`. Try proxying now!"); await Context.Channel.SendMessageAsync($"{Emojis.Success} Member proxy tags changed to `{ContextEntity.ProxyString.Sanitize()}`. Try proxying now!");
ProxyCache.InvalidateResultsForSystem(Context.SenderSystem); await ProxyCache.InvalidateResultsForSystem(Context.SenderSystem);
} }
[Command("delete")] [Command("delete")]
@ -186,6 +190,8 @@ namespace PluralKit.Bot.Commands
if (!await Context.ConfirmWithReply(ContextEntity.Hid)) throw Errors.MemberDeleteCancelled; if (!await Context.ConfirmWithReply(ContextEntity.Hid)) throw Errors.MemberDeleteCancelled;
await Members.Delete(ContextEntity); await Members.Delete(ContextEntity);
await Context.Channel.SendMessageAsync($"{Emojis.Success} Member deleted."); await Context.Channel.SendMessageAsync($"{Emojis.Success} Member deleted.");
await ProxyCache.InvalidateResultsForSystem(Context.SenderSystem);
} }
[Command("avatar")] [Command("avatar")]
@ -201,6 +207,8 @@ namespace PluralKit.Bot.Commands
var embed = new EmbedBuilder().WithImageUrl(ContextEntity.AvatarUrl).Build(); var embed = new EmbedBuilder().WithImageUrl(ContextEntity.AvatarUrl).Build();
await Context.Channel.SendMessageAsync( await Context.Channel.SendMessageAsync(
$"{Emojis.Success} Member avatar changed to {member.Username}'s avatar! {Emojis.Warn} Please note that if {member.Username} changes their avatar, the webhook's avatar will need to be re-set.", embed: embed); $"{Emojis.Success} Member avatar changed to {member.Username}'s avatar! {Emojis.Warn} Please note that if {member.Username} changes their avatar, the webhook's avatar will need to be re-set.", embed: embed);
await ProxyCache.InvalidateResultsForSystem(Context.SenderSystem);
} }
[Command("avatar")] [Command("avatar")]
@ -217,6 +225,8 @@ namespace PluralKit.Bot.Commands
var embed = url != null ? new EmbedBuilder().WithImageUrl(url).Build() : null; var embed = url != null ? new EmbedBuilder().WithImageUrl(url).Build() : null;
await Context.Channel.SendMessageAsync($"{Emojis.Success} Member avatar {(url == null ? "cleared" : "changed")}.", embed: embed); await Context.Channel.SendMessageAsync($"{Emojis.Success} Member avatar {(url == null ? "cleared" : "changed")}.", embed: embed);
await ProxyCache.InvalidateResultsForSystem(Context.SenderSystem);
} }
[Command("displayname")] [Command("displayname")]
@ -250,6 +260,8 @@ namespace PluralKit.Bot.Commands
successStr += $"This member will now be proxied using their member name `{ContextEntity.Name}."; successStr += $"This member will now be proxied using their member name `{ContextEntity.Name}.";
} }
await Context.Channel.SendMessageAsync(successStr); await Context.Channel.SendMessageAsync(successStr);
await ProxyCache.InvalidateResultsForSystem(Context.SenderSystem);
} }
[Command] [Command]

View File

@ -24,6 +24,8 @@ namespace PluralKit.Bot.Commands
public SwitchStore Switches {get; set;} public SwitchStore Switches {get; set;}
public EmbedService EmbedService {get; set;} public EmbedService EmbedService {get; set;}
public ProxyCacheService ProxyCache { get; set; }
[Command] [Command]
[Remarks("system <name>")] [Remarks("system <name>")]
@ -94,6 +96,8 @@ namespace PluralKit.Bot.Commands
await Systems.Save(Context.SenderSystem); await Systems.Save(Context.SenderSystem);
await Context.Channel.SendMessageAsync($"{Emojis.Success} System tag {(newTag != null ? "changed" : "cleared")}."); await Context.Channel.SendMessageAsync($"{Emojis.Success} System tag {(newTag != null ? "changed" : "cleared")}.");
await ProxyCache.InvalidateResultsForSystem(Context.SenderSystem);
} }
[Command("avatar")] [Command("avatar")]
@ -109,6 +113,8 @@ namespace PluralKit.Bot.Commands
var embed = new EmbedBuilder().WithImageUrl(Context.SenderSystem.AvatarUrl).Build(); var embed = new EmbedBuilder().WithImageUrl(Context.SenderSystem.AvatarUrl).Build();
await Context.Channel.SendMessageAsync( await Context.Channel.SendMessageAsync(
$"{Emojis.Success} System avatar changed to {member.Username}'s avatar! {Emojis.Warn} Please note that if {member.Username} changes their avatar, the system's avatar will need to be re-set.", embed: embed); $"{Emojis.Success} System avatar changed to {member.Username}'s avatar! {Emojis.Warn} Please note that if {member.Username} changes their avatar, the system's avatar will need to be re-set.", embed: embed);
await ProxyCache.InvalidateResultsForSystem(Context.SenderSystem);
} }
[Command("avatar")] [Command("avatar")]
@ -125,6 +131,8 @@ namespace PluralKit.Bot.Commands
var embed = url != null ? new EmbedBuilder().WithImageUrl(url).Build() : null; var embed = url != null ? new EmbedBuilder().WithImageUrl(url).Build() : null;
await Context.Channel.SendMessageAsync($"{Emojis.Success} System avatar {(url == null ? "cleared" : "changed")}.", embed: embed); await Context.Channel.SendMessageAsync($"{Emojis.Success} System avatar {(url == null ? "cleared" : "changed")}.", embed: embed);
await ProxyCache.InvalidateResultsForSystem(Context.SenderSystem);
} }
[Command("delete")] [Command("delete")]
@ -138,6 +146,8 @@ namespace PluralKit.Bot.Commands
await Systems.Delete(Context.SenderSystem); await Systems.Delete(Context.SenderSystem);
await Context.Channel.SendMessageAsync($"{Emojis.Success} System deleted."); await Context.Channel.SendMessageAsync($"{Emojis.Success} System deleted.");
await ProxyCache.InvalidateResultsForSystem(Context.SenderSystem);
} }
[Group("list")] [Group("list")]