mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
Added [user_perm()] support to medusa system
This commit is contained in:
24
src/Nadeko.Medusa/Attributes/user_permAttribute.cs
Normal file
24
src/Nadeko.Medusa/Attributes/user_permAttribute.cs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
using Discord;
|
||||||
|
|
||||||
|
namespace Nadeko.Snake;
|
||||||
|
|
||||||
|
[AttributeUsage(AttributeTargets.Method)]
|
||||||
|
public sealed class user_permAttribute : Attribute
|
||||||
|
{
|
||||||
|
public GuildPermission? GuildPerm { get; }
|
||||||
|
public ChannelPermission? ChannelPerm { get; }
|
||||||
|
|
||||||
|
|
||||||
|
public user_permAttribute(GuildPermission perm)
|
||||||
|
{
|
||||||
|
GuildPerm = perm;
|
||||||
|
ChannelPerm = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public user_permAttribute(ChannelPermission perm)
|
||||||
|
{
|
||||||
|
ChannelPerm = perm;
|
||||||
|
GuildPerm = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@@ -418,6 +418,14 @@ public sealed class MedusaLoaderService : IMedusaLoaderService, IReadyExecutor,
|
|||||||
foreach (var f in cmd.Filters)
|
foreach (var f in cmd.Filters)
|
||||||
cb.AddPrecondition(new FilterAdapter(f, strings));
|
cb.AddPrecondition(new FilterAdapter(f, strings));
|
||||||
|
|
||||||
|
foreach (var up in cmd.UserPerms)
|
||||||
|
{
|
||||||
|
if (up.GuildPerm is { } gp)
|
||||||
|
cb.AddPrecondition(new UserPermAttribute(gp));
|
||||||
|
else if (up.ChannelPerm is { } cp)
|
||||||
|
cb.AddPrecondition(new UserPermAttribute(cp));
|
||||||
|
}
|
||||||
|
|
||||||
cb.WithPriority(cmd.Priority);
|
cb.WithPriority(cmd.Priority);
|
||||||
|
|
||||||
// using summary to save method name
|
// using summary to save method name
|
||||||
@@ -760,6 +768,7 @@ public sealed class MedusaLoaderService : IMedusaLoaderService, IReadyExecutor,
|
|||||||
foreach (var method in methodInfos)
|
foreach (var method in methodInfos)
|
||||||
{
|
{
|
||||||
var filters = method.GetCustomAttributes<FilterAttribute>(true).ToArray();
|
var filters = method.GetCustomAttributes<FilterAttribute>(true).ToArray();
|
||||||
|
var userPerms = method.GetCustomAttributes<user_permAttribute>(false).ToArray();
|
||||||
var prio = method.GetCustomAttribute<prioAttribute>(true)?.Priority ?? 0;
|
var prio = method.GetCustomAttribute<prioAttribute>(true)?.Priority ?? 0;
|
||||||
|
|
||||||
var paramInfos = method.GetParameters();
|
var paramInfos = method.GetParameters();
|
||||||
@@ -847,6 +856,7 @@ public sealed class MedusaLoaderService : IMedusaLoaderService, IReadyExecutor,
|
|||||||
method,
|
method,
|
||||||
instance,
|
instance,
|
||||||
filters,
|
filters,
|
||||||
|
userPerms,
|
||||||
cmdContext,
|
cmdContext,
|
||||||
diParams,
|
diParams,
|
||||||
cmdParams,
|
cmdParams,
|
||||||
|
@@ -11,6 +11,7 @@ public sealed class SnekCommandData
|
|||||||
MethodInfo methodInfo,
|
MethodInfo methodInfo,
|
||||||
Snek module,
|
Snek module,
|
||||||
FilterAttribute[] filters,
|
FilterAttribute[] filters,
|
||||||
|
user_permAttribute[] userPerms,
|
||||||
CommandContextType contextType,
|
CommandContextType contextType,
|
||||||
IReadOnlyList<Type> injectedParams,
|
IReadOnlyList<Type> injectedParams,
|
||||||
IReadOnlyList<ParamData> parameters,
|
IReadOnlyList<ParamData> parameters,
|
||||||
@@ -21,6 +22,7 @@ public sealed class SnekCommandData
|
|||||||
MethodInfo = methodInfo;
|
MethodInfo = methodInfo;
|
||||||
Module = module;
|
Module = module;
|
||||||
Filters = filters;
|
Filters = filters;
|
||||||
|
UserPerms = userPerms;
|
||||||
ContextType = contextType;
|
ContextType = contextType;
|
||||||
InjectedParams = injectedParams;
|
InjectedParams = injectedParams;
|
||||||
Parameters = parameters;
|
Parameters = parameters;
|
||||||
@@ -28,6 +30,8 @@ public sealed class SnekCommandData
|
|||||||
OptionalStrings = strings;
|
OptionalStrings = strings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public user_permAttribute[] UserPerms { get; set; }
|
||||||
|
|
||||||
public CommandStrings OptionalStrings { get; set; }
|
public CommandStrings OptionalStrings { get; set; }
|
||||||
|
|
||||||
public IReadOnlyCollection<string> Aliases { get; }
|
public IReadOnlyCollection<string> Aliases { get; }
|
||||||
|
Reference in New Issue
Block a user