From 032b6bfd57261072b70943d6ffbe84217382582b Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sun, 15 Jan 2023 04:15:51 +0100 Subject: [PATCH] Added Bot propety for easy access to the ISelfUser to all medusa *Context types --- src/Nadeko.Medusa/Context/AnyContext.cs | 5 +++++ src/NadekoBot/Common/Medusa/Adapters/DmContextAdapter.cs | 3 +++ src/NadekoBot/Common/Medusa/Adapters/GuildContextAdapter.cs | 2 ++ 3 files changed, 10 insertions(+) diff --git a/src/Nadeko.Medusa/Context/AnyContext.cs b/src/Nadeko.Medusa/Context/AnyContext.cs index 964001a4b..9b3426730 100644 --- a/src/Nadeko.Medusa/Context/AnyContext.cs +++ b/src/Nadeko.Medusa/Context/AnyContext.cs @@ -22,6 +22,11 @@ public abstract class AnyContext /// The user who invoked the command /// public abstract IUser User { get; } + + /// + /// Bot user + /// + public abstract ISelfUser Bot { get; } /// /// Provides access to strings used by this medusa diff --git a/src/NadekoBot/Common/Medusa/Adapters/DmContextAdapter.cs b/src/NadekoBot/Common/Medusa/Adapters/DmContextAdapter.cs index 89fdaa370..80cb115b0 100644 --- a/src/NadekoBot/Common/Medusa/Adapters/DmContextAdapter.cs +++ b/src/NadekoBot/Common/Medusa/Adapters/DmContextAdapter.cs @@ -5,9 +5,11 @@ public sealed class DmContextAdapter : DmContext public override IMedusaStrings Strings { get; } public override IDMChannel Channel { get; } public override IUserMessage Message { get; } + public override ISelfUser Bot { get; } public override IUser User => Message.Author; + private readonly IServiceProvider _services; private readonly Lazy _ebs; private readonly Lazy _botStrings; @@ -26,6 +28,7 @@ public sealed class DmContextAdapter : DmContext Channel = ch; Message = ctx.Message; + Bot = ctx.Client.CurrentUser; _ebs = new(_services.GetRequiredService()); diff --git a/src/NadekoBot/Common/Medusa/Adapters/GuildContextAdapter.cs b/src/NadekoBot/Common/Medusa/Adapters/GuildContextAdapter.cs index 87b22923a..25f56329f 100644 --- a/src/NadekoBot/Common/Medusa/Adapters/GuildContextAdapter.cs +++ b/src/NadekoBot/Common/Medusa/Adapters/GuildContextAdapter.cs @@ -11,6 +11,7 @@ public sealed class GuildContextAdapter : GuildContext public override IMedusaStrings Strings { get; } public override IGuild Guild { get; } public override ITextChannel Channel { get; } + public override ISelfUser Bot { get; } public override IUserMessage Message => _ctx.Message; @@ -28,6 +29,7 @@ public sealed class GuildContextAdapter : GuildContext Strings = strings; User = (IGuildUser)ctx.User; + Bot = ctx.Client.CurrentUser; _services = services; _ebs = new(_services.GetRequiredService());