diff --git a/src/Nadeko.Medusa/Attributes/MedusaPermAttribute.cs b/src/Nadeko.Medusa/Attributes/MedusaPermAttribute.cs
new file mode 100644
index 000000000..becdfc37b
--- /dev/null
+++ b/src/Nadeko.Medusa/Attributes/MedusaPermAttribute.cs
@@ -0,0 +1,10 @@
+namespace Nadeko.Snake;
+
+///
+/// Used as a marker class for bot_perm and user_perm Attributes
+/// Has no functionality.
+///
+public abstract class MedusaPermAttribute : Attribute
+{
+
+}
\ No newline at end of file
diff --git a/src/Nadeko.Medusa/Attributes/bot_permAttribute.cs b/src/Nadeko.Medusa/Attributes/bot_permAttribute.cs
new file mode 100644
index 000000000..c65fd223f
--- /dev/null
+++ b/src/Nadeko.Medusa/Attributes/bot_permAttribute.cs
@@ -0,0 +1,23 @@
+using Discord;
+
+namespace Nadeko.Snake;
+
+[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
+public sealed class bot_permAttribute : MedusaPermAttribute
+{
+ public GuildPermission? GuildPerm { get; }
+ public ChannelPermission? ChannelPerm { get; }
+
+
+ public bot_permAttribute(GuildPermission perm)
+ {
+ GuildPerm = perm;
+ ChannelPerm = null;
+ }
+
+ public bot_permAttribute(ChannelPermission perm)
+ {
+ ChannelPerm = perm;
+ GuildPerm = null;
+ }
+}
\ No newline at end of file
diff --git a/src/Nadeko.Medusa/Attributes/user_permAttribute.cs b/src/Nadeko.Medusa/Attributes/user_permAttribute.cs
index 1d7e96099..34d82deb4 100644
--- a/src/Nadeko.Medusa/Attributes/user_permAttribute.cs
+++ b/src/Nadeko.Medusa/Attributes/user_permAttribute.cs
@@ -3,12 +3,11 @@
namespace Nadeko.Snake;
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
-public sealed class user_permAttribute : Attribute
+public sealed class user_permAttribute : MedusaPermAttribute
{
public GuildPermission? GuildPerm { get; }
public ChannelPermission? ChannelPerm { get; }
-
public user_permAttribute(GuildPermission perm)
{
GuildPerm = perm;
@@ -21,4 +20,3 @@ public sealed class user_permAttribute : Attribute
GuildPerm = null;
}
}
-
diff --git a/src/NadekoBot/Common/Medusa/MedusaLoaderService.cs b/src/NadekoBot/Common/Medusa/MedusaLoaderService.cs
index c7d2c4c23..f7ee6a98e 100644
--- a/src/NadekoBot/Common/Medusa/MedusaLoaderService.cs
+++ b/src/NadekoBot/Common/Medusa/MedusaLoaderService.cs
@@ -418,12 +418,22 @@ public sealed class MedusaLoaderService : IMedusaLoaderService, IReadyExecutor,
foreach (var f in cmd.Filters)
cb.AddPrecondition(new FilterAdapter(f, strings));
- foreach (var up in cmd.UserPerms)
+ foreach (var ubp in cmd.UserAndBotPerms)
{
- if (up.GuildPerm is { } gp)
- cb.AddPrecondition(new UserPermAttribute(gp));
- else if (up.ChannelPerm is { } cp)
- cb.AddPrecondition(new UserPermAttribute(cp));
+ if (ubp is user_permAttribute up)
+ {
+ if (up.GuildPerm is { } gp)
+ cb.AddPrecondition(new UserPermAttribute(gp));
+ else if (up.ChannelPerm is { } cp)
+ cb.AddPrecondition(new UserPermAttribute(cp));
+ }
+ else if (ubp is bot_permAttribute bp)
+ {
+ if (bp.GuildPerm is { } gp)
+ cb.AddPrecondition(new BotPermAttribute(gp));
+ else if (bp.ChannelPerm is { } cp)
+ cb.AddPrecondition(new BotPermAttribute(cp));
+ }
}
cb.WithPriority(cmd.Priority);
@@ -768,7 +778,8 @@ public sealed class MedusaLoaderService : IMedusaLoaderService, IReadyExecutor,
foreach (var method in methodInfos)
{
var filters = method.GetCustomAttributes(true).ToArray();
- var userPerms = method.GetCustomAttributes(false).ToArray();
+ var userAndBotPerms = method.GetCustomAttributes(true)
+ .ToArray();
var prio = method.GetCustomAttribute(true)?.Priority ?? 0;
var paramInfos = method.GetParameters();
@@ -856,7 +867,7 @@ public sealed class MedusaLoaderService : IMedusaLoaderService, IReadyExecutor,
method,
instance,
filters,
- userPerms,
+ userAndBotPerms,
cmdContext,
diParams,
cmdParams,
diff --git a/src/NadekoBot/Common/Medusa/Models/SnekCommandData.cs b/src/NadekoBot/Common/Medusa/Models/SnekCommandData.cs
index 2dc4afae4..c1c3be3d5 100644
--- a/src/NadekoBot/Common/Medusa/Models/SnekCommandData.cs
+++ b/src/NadekoBot/Common/Medusa/Models/SnekCommandData.cs
@@ -11,7 +11,7 @@ public sealed class SnekCommandData
MethodInfo methodInfo,
Snek module,
FilterAttribute[] filters,
- user_permAttribute[] userPerms,
+ MedusaPermAttribute[] userAndBotPerms,
CommandContextType contextType,
IReadOnlyList injectedParams,
IReadOnlyList parameters,
@@ -22,7 +22,7 @@ public sealed class SnekCommandData
MethodInfo = methodInfo;
Module = module;
Filters = filters;
- UserPerms = userPerms;
+ UserAndBotPerms = userAndBotPerms;
ContextType = contextType;
InjectedParams = injectedParams;
Parameters = parameters;
@@ -30,7 +30,7 @@ public sealed class SnekCommandData
OptionalStrings = strings;
}
- public user_permAttribute[] UserPerms { get; set; }
+ public MedusaPermAttribute[] UserAndBotPerms { get; set; }
public CommandStrings OptionalStrings { get; set; }