diff --git a/src/Nadeko.Medusa/Nadeko.Medusa.csproj b/src/Nadeko.Medusa/Nadeko.Medusa.csproj index b21da76eb..0104e1a35 100644 --- a/src/Nadeko.Medusa/Nadeko.Medusa.csproj +++ b/src/Nadeko.Medusa/Nadeko.Medusa.csproj @@ -12,7 +12,7 @@ - + diff --git a/src/NadekoBot/Modules/Administration/Self/DoAsUserMessage.cs b/src/NadekoBot/Modules/Administration/Self/DoAsUserMessage.cs index 86d5ad2f2..5eebaa1cb 100644 --- a/src/NadekoBot/Modules/Administration/Self/DoAsUserMessage.cs +++ b/src/NadekoBot/Modules/Administration/Self/DoAsUserMessage.cs @@ -146,4 +146,5 @@ public sealed class DoAsUserMessage : IUserMessage public MessageResolvedData ResolvedData => _msg.ResolvedData; public IUserMessage ReferencedMessage => _msg.ReferencedMessage; + public IMessageInteractionMetadata InteractionMetadata { get; } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Administration/Self/SelfCommands.cs b/src/NadekoBot/Modules/Administration/Self/SelfCommands.cs index e76c49ba9..3e3113241 100644 --- a/src/NadekoBot/Modules/Administration/Self/SelfCommands.cs +++ b/src/NadekoBot/Modules/Administration/Self/SelfCommands.cs @@ -501,6 +501,16 @@ public partial class Administration if (success) await ReplyConfirmLocalizedAsync(strs.set_avatar); } + + [Cmd] + [OwnerOnly] + public async Task SetBanner([Leftover] string img = null) + { + var success = await _service.SetBanner(img); + + if (success) + await ReplyConfirmLocalizedAsync(strs.set_banner); + } [Cmd] [OwnerOnly] diff --git a/src/NadekoBot/Modules/Administration/Self/SelfService.cs b/src/NadekoBot/Modules/Administration/Self/SelfService.cs index fa8a70ca0..a23bd95ed 100644 --- a/src/NadekoBot/Modules/Administration/Self/SelfService.cs +++ b/src/NadekoBot/Modules/Administration/Self/SelfService.cs @@ -3,7 +3,6 @@ using Microsoft.EntityFrameworkCore; using NadekoBot.Common.ModuleBehaviors; using NadekoBot.Services.Database.Models; using System.Collections.Immutable; -using Nadeko.Common; namespace NadekoBot.Modules.Administration.Services; @@ -321,6 +320,40 @@ public sealed class SelfService : IExecNoCommand, IReadyExecutor, INService return true; } + public async Task SetBanner(string img) + { + if (string.IsNullOrWhiteSpace(img)) + { + return false; + } + + if (!Uri.IsWellFormedUriString(img, UriKind.Absolute)) + { + return false; + } + + var uri = new Uri(img); + + using var http = _httpFactory.CreateClient(); + using var sr = await http.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead); + + if (!sr.IsImage()) + { + return false; + } + + if (sr.GetContentLength() > 8.Megabytes().Bytes) + { + return false; + } + + await using var imageStream = await sr.Content.ReadAsStreamAsync(); + + await _client.CurrentUser.ModifyAsync(x => x.Banner = new Image(imageStream)); + return true; + } + + public void ClearStartupCommands() { using var uow = _db.GetDbContext(); diff --git a/src/NadekoBot/NadekoBot.csproj b/src/NadekoBot/NadekoBot.csproj index fdd220e1a..a22f2f9fe 100644 --- a/src/NadekoBot/NadekoBot.csproj +++ b/src/NadekoBot/NadekoBot.csproj @@ -27,7 +27,7 @@ - + diff --git a/src/NadekoBot/data/aliases.yml b/src/NadekoBot/data/aliases.yml index 85157bcf2..fceb0065e 100644 --- a/src/NadekoBot/data/aliases.yml +++ b/src/NadekoBot/data/aliases.yml @@ -195,6 +195,8 @@ setnick: setavatar: - setavatar - setav +setbanner: + - setbanner setgame: - setgame send: diff --git a/src/NadekoBot/data/strings/commands/commands.en-US.yml b/src/NadekoBot/data/strings/commands/commands.en-US.yml index 8023f3180..ff41fc473 100644 --- a/src/NadekoBot/data/strings/commands/commands.en-US.yml +++ b/src/NadekoBot/data/strings/commands/commands.en-US.yml @@ -402,6 +402,10 @@ setavatar: desc: "Sets a new avatar image for the NadekoBot. Parameter is a direct link to an image." args: - "https://i.imgur.com/xTG3a1I.jpg" +setbanner: + desc: "Sets a new banner image for the NadekoBot. Parameter is a direct link to an image. Supports gifs." + args: + - "https://i.imgur.com/xTG3a1I.jpg" setgame: desc: "Sets the bots game status to either Playing, Listening, or Watching." args: diff --git a/src/NadekoBot/data/strings/responses/responses.en-US.json b/src/NadekoBot/data/strings/responses/responses.en-US.json index 6767d3053..b59843409 100644 --- a/src/NadekoBot/data/strings/responses/responses.en-US.json +++ b/src/NadekoBot/data/strings/responses/responses.en-US.json @@ -184,6 +184,7 @@ "setrole": "Successfully added role {0} to user {1}", "setrole_err": "Failed to add role. I have insufficient permissions.", "set_avatar": "New avatar set!", + "set_banner": "New banner set!", "set_channel_name": "New channel name set.", "set_game": "New game set!", "set_stream": "New stream set!",