diff --git a/PluralKit.Bot/Commands/Groups.cs b/PluralKit.Bot/Commands/Groups.cs index cbe128dc..837e2d9e 100644 --- a/PluralKit.Bot/Commands/Groups.cs +++ b/PluralKit.Bot/Commands/Groups.cs @@ -263,7 +263,7 @@ public class Groups { ctx.CheckOwnGroup(target); - img = await _avatarHosting.TryRehostImage(img, AvatarHostingService.RehostedImageType.Avatar, ctx.Author.Id); + img = await _avatarHosting.TryRehostImage(img, AvatarHostingService.RehostedImageType.Avatar, ctx.Author.Id, ctx.System); await AvatarUtils.VerifyAvatarOrThrow(_client, img.Url); await ctx.Repository.UpdateGroup(target.Id, new GroupPatch { Icon = img.CleanUrl ?? img.Url }); @@ -330,7 +330,7 @@ public class Groups { ctx.CheckOwnGroup(target); - img = await _avatarHosting.TryRehostImage(img, AvatarHostingService.RehostedImageType.Banner, ctx.Author.Id); + img = await _avatarHosting.TryRehostImage(img, AvatarHostingService.RehostedImageType.Banner, ctx.Author.Id, ctx.System); await AvatarUtils.VerifyAvatarOrThrow(_client, img.Url, true); await ctx.Repository.UpdateGroup(target.Id, new GroupPatch { BannerImage = img.CleanUrl ?? img.Url }); diff --git a/PluralKit.Bot/Commands/Member.cs b/PluralKit.Bot/Commands/Member.cs index 14055127..d07b91cf 100644 --- a/PluralKit.Bot/Commands/Member.cs +++ b/PluralKit.Bot/Commands/Member.cs @@ -81,7 +81,7 @@ public class Member uriBuilder.Query = ""; img.CleanUrl = uriBuilder.Uri.AbsoluteUri; - img = await _avatarHosting.TryRehostImage(img, AvatarHostingService.RehostedImageType.Avatar, ctx.Author.Id); + img = await _avatarHosting.TryRehostImage(img, AvatarHostingService.RehostedImageType.Avatar, ctx.Author.Id, ctx.System); await AvatarUtils.VerifyAvatarOrThrow(_client, img.Url); await ctx.Repository.UpdateMember(member.Id, new MemberPatch { AvatarUrl = img.CleanUrl ?? img.Url }, conn); diff --git a/PluralKit.Bot/Commands/MemberAvatar.cs b/PluralKit.Bot/Commands/MemberAvatar.cs index f1e012b8..e626944e 100644 --- a/PluralKit.Bot/Commands/MemberAvatar.cs +++ b/PluralKit.Bot/Commands/MemberAvatar.cs @@ -141,7 +141,7 @@ public class MemberAvatar ctx.CheckSystem().CheckOwnMember(target); - avatarArg = await _avatarHosting.TryRehostImage(avatarArg.Value, AvatarHostingService.RehostedImageType.Avatar, ctx.Author.Id); + avatarArg = await _avatarHosting.TryRehostImage(avatarArg.Value, AvatarHostingService.RehostedImageType.Avatar, ctx.Author.Id, ctx.System); await AvatarUtils.VerifyAvatarOrThrow(_client, avatarArg.Value.Url); await UpdateAvatar(location, ctx, target, avatarArg.Value.CleanUrl ?? avatarArg.Value.Url); await PrintResponse(location, ctx, target, avatarArg.Value, guildData); diff --git a/PluralKit.Bot/Commands/MemberEdit.cs b/PluralKit.Bot/Commands/MemberEdit.cs index 328fdc74..be08c55a 100644 --- a/PluralKit.Bot/Commands/MemberEdit.cs +++ b/PluralKit.Bot/Commands/MemberEdit.cs @@ -182,7 +182,7 @@ public class MemberEdit async Task SetBannerImage(ParsedImage img) { - img = await _avatarHosting.TryRehostImage(img, AvatarHostingService.RehostedImageType.Banner, ctx.Author.Id); + img = await _avatarHosting.TryRehostImage(img, AvatarHostingService.RehostedImageType.Banner, ctx.Author.Id, ctx.System); await AvatarUtils.VerifyAvatarOrThrow(_client, img.Url, true); await ctx.Repository.UpdateMember(target.Id, new MemberPatch { BannerImage = img.CleanUrl ?? img.Url }); diff --git a/PluralKit.Bot/Commands/SystemEdit.cs b/PluralKit.Bot/Commands/SystemEdit.cs index 30617f64..c8c501c1 100644 --- a/PluralKit.Bot/Commands/SystemEdit.cs +++ b/PluralKit.Bot/Commands/SystemEdit.cs @@ -475,7 +475,7 @@ public class SystemEdit { ctx.CheckOwnSystem(target); - img = await _avatarHosting.TryRehostImage(img, AvatarHostingService.RehostedImageType.Avatar, ctx.Author.Id); + img = await _avatarHosting.TryRehostImage(img, AvatarHostingService.RehostedImageType.Avatar, ctx.Author.Id, ctx.System); await AvatarUtils.VerifyAvatarOrThrow(_client, img.Url); await ctx.Repository.UpdateSystem(target.Id, new SystemPatch { AvatarUrl = img.CleanUrl ?? img.Url }); @@ -545,7 +545,7 @@ public class SystemEdit { ctx.CheckOwnSystem(target); - img = await _avatarHosting.TryRehostImage(img, AvatarHostingService.RehostedImageType.Avatar, ctx.Author.Id); + img = await _avatarHosting.TryRehostImage(img, AvatarHostingService.RehostedImageType.Avatar, ctx.Author.Id, ctx.System); await AvatarUtils.VerifyAvatarOrThrow(_client, img.Url); await ctx.Repository.UpdateSystemGuild(target.Id, ctx.Guild.Id, new SystemGuildPatch { AvatarUrl = img.CleanUrl ?? img.Url }); @@ -644,7 +644,7 @@ public class SystemEdit else if (await ctx.MatchImage() is { } img) { - img = await _avatarHosting.TryRehostImage(img, AvatarHostingService.RehostedImageType.Banner, ctx.Author.Id); + img = await _avatarHosting.TryRehostImage(img, AvatarHostingService.RehostedImageType.Banner, ctx.Author.Id, ctx.System); await AvatarUtils.VerifyAvatarOrThrow(_client, img.Url, true); await ctx.Repository.UpdateSystem(target.Id, new SystemPatch { BannerImage = img.CleanUrl ?? img.Url }); diff --git a/PluralKit.Bot/Services/AvatarHostingService.cs b/PluralKit.Bot/Services/AvatarHostingService.cs index 799b5eb1..a080bae8 100644 --- a/PluralKit.Bot/Services/AvatarHostingService.cs +++ b/PluralKit.Bot/Services/AvatarHostingService.cs @@ -1,3 +1,4 @@ +using PluralKit.Core; using System.Net; using System.Net.Http.Json; @@ -14,9 +15,9 @@ public class AvatarHostingService _client = client; } - public async Task TryRehostImage(ParsedImage input, RehostedImageType type, ulong userId) + public async Task TryRehostImage(ParsedImage input, RehostedImageType type, ulong userId, PKSystem? system) { - var uploaded = await TryUploadAvatar(input.Url, type, userId); + var uploaded = await TryUploadAvatar(input.Url, type, userId, system); if (uploaded != null) { // todo: make new image type called Cdn? @@ -26,7 +27,7 @@ public class AvatarHostingService return input; } - public async Task TryUploadAvatar(string? avatarUrl, RehostedImageType type, ulong userId) + public async Task TryUploadAvatar(string? avatarUrl, RehostedImageType type, ulong userId, PKSystem? system) { if (!AvatarUtils.IsDiscordCdnUrl(avatarUrl)) return null; @@ -42,7 +43,7 @@ public class AvatarHostingService }; var response = await _client.PostAsJsonAsync(_config.AvatarServiceUrl + "/pull", - new { url = avatarUrl, kind, uploaded_by = userId }); + new { url = avatarUrl, kind, uploaded_by = userId, system_id = system?.Uuid.ToString() }); if (response.StatusCode != HttpStatusCode.OK) { var error = await response.Content.ReadFromJsonAsync();