Skip to content

Commit

Permalink
修改了命令注册
Browse files Browse the repository at this point in the history
  • Loading branch information
Qianyiovo committed Mar 6, 2023
1 parent 75b213d commit 7567e13
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 12 deletions.
6 changes: 5 additions & 1 deletion PrismBot.SDK/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
namespace PrismBot.SDK;
using PrismBot.SDK.Interfaces;

namespace PrismBot.SDK;

public abstract class Plugin
{
public List<IGroupCommand> RegisteredGroupCommands { get; } = new();
public List<IPrivateCommand> RegisteredPrivateCommands { get; } = new();
public abstract string GetPluginName();
public abstract string GetVersion();
public abstract string GetAuthor();
Expand Down
6 changes: 4 additions & 2 deletions PrismBot.SDK/Static/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ public static class CommandManager
/// 注册群命令
/// </summary>
/// <param name="command">需要注册的对象</param>
public static void RegisterGroupCommand(IGroupCommand command)
public static void RegisterGroupCommand(Plugin plugin, IGroupCommand command)
{
plugin.RegisteredGroupCommands.Add(command);
RegisteredGroupCommands.Add(command);
}

/// <summary>
/// 注册私聊命令
/// </summary>
/// <param name="command">需要注册的对象</param>
public static void RegisterPrivateCommand(IPrivateCommand command)
public static void RegisterPrivateCommand(Plugin plugin,IPrivateCommand command)
{
plugin.RegisteredPrivateCommands.Add(command);
RegisteredPrivateCommands.Add(command);
}

Expand Down
4 changes: 2 additions & 2 deletions PrismBot/InternalPlugins/MenuHelper/MenuHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public override string GetDescription()

public override void OnLoad()
{
CommandManager.RegisterPrivateCommand(new PrivateMenu());
CommandManager.RegisterGroupCommand(new GroupMenu());
CommandManager.RegisterPrivateCommand(this, new PrivateMenu());
CommandManager.RegisterGroupCommand(this, new GroupMenu());
}
}
4 changes: 2 additions & 2 deletions PrismBot/InternalPlugins/MessageLogger/MessageLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public override string GetDescription()

public override void OnLoad()
{
CommandManager.RegisterGroupCommand(new GroupMessageLogger());
CommandManager.RegisterPrivateCommand(new PrivateMessageLogger());
CommandManager.RegisterGroupCommand(this, new GroupMessageLogger());
CommandManager.RegisterPrivateCommand(this, new PrivateMessageLogger());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task OnPermissionGrantedAsync(string type, GroupMessageEventArgs ev
}
foreach (var plugin in plugins)
{
await eventArgs.SourceGroup.SendGroupMessage($"插件名称:{plugin.GetPluginName()}\n插件作者:{plugin.GetAuthor()}\n插件版本:{plugin.GetVersion()}\n插件描述:{plugin.GetDescription()}");
await eventArgs.SourceGroup.SendGroupMessage($"插件名称:{plugin.GetPluginName()}\n插件作者:{plugin.GetAuthor()}\n插件版本:{plugin.GetVersion()}\n插件描述:{plugin.GetDescription()}\n已注册的群命令:{string.Join(", ", plugin.RegisteredGroupCommands.Select(x => $"{x.GetCommand()}({x.GetPermission()})"))}\n已注册的私聊命令:{string.Join(", ", plugin.RegisteredPrivateCommands.Select(x => $"{x.GetCommand()}({x.GetPermission()})"))}");
}
}
}
4 changes: 2 additions & 2 deletions PrismBot/InternalPlugins/PlugMan/PlugMan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public override string GetDescription()

public override void OnLoad()
{
CommandManager.RegisterGroupCommand(new PluginList());
CommandManager.RegisterGroupCommand(new PluginInfo());
CommandManager.RegisterGroupCommand(this, new PluginList());
CommandManager.RegisterGroupCommand(this, new PluginInfo());
}
}
4 changes: 2 additions & 2 deletions PrismBotPluginDemo/HelloWorldPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class HelloWorldPlugin : Plugin
{
public override string GetPluginName()
{
return "Hello World";
return "HelloWorld";
}

public override string GetVersion()
Expand All @@ -30,7 +30,7 @@ public override string GetDescription()

public override void OnLoad()
{
CommandManager.RegisterPrivateCommand(new HelloWorldReplyer());
CommandManager.RegisterPrivateCommand(this, new HelloWorldReplyer());
}
}

Expand Down

0 comments on commit 7567e13

Please sign in to comment.