├── .dockerignore
├── .gitattributes
├── .gitignore
├── Dockerfile
├── LICENSE
├── README.md
├── WanBot.Api
├── BasePlugin.cs
├── Event
│ ├── AtAttribute.cs
│ ├── AtEventArgs.cs
│ ├── BlockableEventArgs.cs
│ ├── CommandAttribute.cs
│ ├── CommandEventArgs.cs
│ ├── EventAttribute.cs
│ ├── MiraiEventAttribute.cs
│ ├── NudgeAttribute.cs
│ ├── NudgeEventArgs.cs
│ ├── Priority.cs
│ ├── RegexAttribute.cs
│ ├── RegexEventArgs.cs
│ ├── SimpleEventsPlugin.cs
│ ├── WanBotEventEvent.cs
│ └── WanBotEventHandler.cs
├── Hook
│ ├── HookExtension.cs
│ ├── HookTable.cs
│ └── HookType.cs
├── IApplication.cs
├── IBotManager.cs
├── ILogger.cs
├── IPermissionService.cs
├── IPluginManager.cs
├── ISender.cs
├── Message
│ ├── ForwardMessageBuilder.cs
│ ├── FriendSender.cs
│ ├── GroupSender.cs
│ ├── IMessageBuilder.cs
│ ├── MessageBuilder.cs
│ ├── MessageChainDivider.cs
│ ├── MessageChainExtension.cs
│ ├── MessageType.cs
│ ├── MiraiImage.cs
│ └── StrangerSender.cs
├── Mirai
│ ├── Adapter
│ │ ├── HttpAdapter.cs
│ │ ├── IAdapter.cs
│ │ └── WebsocketAdapter.cs
│ ├── Client.cs
│ ├── Event
│ │ ├── BaseMiraiEvent.cs
│ │ ├── BotGroupPermissionChangeEvent.cs
│ │ ├── BotInvitedJoinGroupRequestEvent.cs
│ │ ├── BotJoinGroupEvent.cs
│ │ ├── BotLeaveEventActive.cs
│ │ ├── BotLeaveEventKick.cs
│ │ ├── BotMuteEvent.cs
│ │ ├── BotOfflineEventActive.cs
│ │ ├── BotOfflineEventDropped.cs
│ │ ├── BotOfflineEventForce.cs
│ │ ├── BotOnlineEvent.cs
│ │ ├── BotReloginEvent.cs
│ │ ├── BotUnmuteEvent.cs
│ │ ├── CommandExecutedEvent.cs
│ │ ├── FriendInputStatusChangedEvent.cs
│ │ ├── FriendMessage.cs
│ │ ├── FriendNickChangedEvent.cs
│ │ ├── FriendRecallEvent.cs
│ │ ├── FriendSyncMessage.cs
│ │ ├── GroupAllowAnonymousChatEvent.cs
│ │ ├── GroupAllowConfessTalkEvent.cs
│ │ ├── GroupAllowMemberInviteEvent.cs
│ │ ├── GroupEntranceAnnouncementChangeEvent.cs
│ │ ├── GroupMessage.cs
│ │ ├── GroupMuteAllEvent.cs
│ │ ├── GroupNameChangeEvent.cs
│ │ ├── GroupRecallEvent.cs
│ │ ├── GroupSyncMessage.cs
│ │ ├── MemberCardChangeEvent.cs
│ │ ├── MemberHonorChangeEvent.cs
│ │ ├── MemberJoinEvent.cs
│ │ ├── MemberJoinRequestEvent.cs
│ │ ├── MemberLeaveEventKick.cs
│ │ ├── MemberLeaveEventQuit.cs
│ │ ├── MemberMuteEvent.cs
│ │ ├── MemberPermissionChangeEvent.cs
│ │ ├── MemberSpecialTitleChangeEvent.cs
│ │ ├── MemberUnmuteEvent.cs
│ │ ├── NewFriendRequestEvent.cs
│ │ ├── NudgeEvent.cs
│ │ ├── OtherClientMessage.cs
│ │ ├── OtherClientOfflineEvent.cs
│ │ ├── OtherClientOnlineEvent.cs
│ │ ├── StrangerMessage.cs
│ │ ├── StrangerSyncMessage.cs
│ │ ├── TempMessage.cs
│ │ └── TempSyncMessage.cs
│ ├── Friend.cs
│ ├── Group.cs
│ ├── Member.cs
│ ├── Message
│ │ ├── App.cs
│ │ ├── At.cs
│ │ ├── AtAll.cs
│ │ ├── BaseChain.cs
│ │ ├── Dice.cs
│ │ ├── Face.cs
│ │ ├── File.cs
│ │ ├── FlashImage.cs
│ │ ├── Forward.cs
│ │ ├── Image.cs
│ │ ├── Json.cs
│ │ ├── MarketFace.cs
│ │ ├── MessageChain.cs
│ │ ├── MiraiCode.cs
│ │ ├── MusicShare.cs
│ │ ├── Plain.cs
│ │ ├── Poke.cs
│ │ ├── Quote.cs
│ │ ├── Source.cs
│ │ ├── Voice.cs
│ │ └── Xml.cs
│ ├── MiraiBot.ApiCall.cs
│ ├── MiraiBot.cs
│ ├── MiraiBotException.cs
│ ├── MiraiConfig.cs
│ ├── Network
│ │ ├── HttpRequestHelper.cs
│ │ ├── Request.cs
│ │ ├── Response.cs
│ │ ├── SimpleWebSocketClient.cs
│ │ └── WsAdapterRequest.cs
│ ├── Payload
│ │ ├── About.cs
│ │ ├── BotProfile.cs
│ │ ├── FriendList.cs
│ │ ├── FriendProfile.cs
│ │ ├── GroupList.cs
│ │ ├── MemberList.cs
│ │ ├── MemberProfile.cs
│ │ ├── MessageFromId.cs
│ │ ├── Quit.cs
│ │ ├── Recall.cs
│ │ ├── ResponseBotInvitedJoinGroupRequestEvent.cs
│ │ ├── SendFriendMessage.cs
│ │ ├── SendGroupMessage.cs
│ │ ├── SendNudge.cs
│ │ ├── SendTempMessage.cs
│ │ ├── UploadImage.cs
│ │ ├── UserProfile.cs
│ │ └── Verify.cs
│ └── Profile.cs
├── Util
│ ├── CommandDispatcher.cs
│ ├── MessageChainJsonConverter.cs
│ ├── MiraiJsonContext.cs
│ └── SyncIdHelper.cs
├── WanBot.Api.csproj
├── WanBotApi.cs
└── WanBotPlugin.cs
├── WanBot.Graphic.Example
├── Program.cs
└── WanBot.Graphic.Example.csproj
├── WanBot.Graphic
├── Fonts.cs
├── Template
│ └── Box.cs
├── UI
│ ├── ImageBox.cs
│ ├── Layout
│ │ ├── Alignment.cs
│ │ ├── Grid.cs
│ │ ├── HorizontalLayout.cs
│ │ └── VerticalLayout.cs
│ ├── Margin.cs
│ ├── Rectangle.cs
│ ├── TextBox.cs
│ ├── UIContainer.cs
│ └── UIElement.cs
├── UIRenderer.cs
├── Util
│ └── VerticalHelper.cs
├── VkContext.cs
└── WanBot.Graphic.csproj
├── WanBot.Plugin.AI
├── AIAdapter
│ └── TongYi.cs
├── AIConfig.cs
├── AIPlugin.cs
├── ChatHistory.cs
├── IAIAdapter.cs
└── WanBot.Plugin.AI.csproj
├── WanBot.Plugin.Core
├── CorePlugin.cs
└── WanBot.Plugin.Core.csproj
├── WanBot.Plugin.Essential
├── EncryptCommandPlugin.cs
├── EssAttribute
│ ├── DbEssAttributeUser.cs
│ ├── EssAttrUser.cs
│ ├── EssAttrUserFactory.cs
│ ├── EssAttributeDatabaseContext.cs
│ ├── EssAttributePlugin.cs
│ └── WanBotPluginExtension.cs
├── ExceptionLogPlugin.cs
├── Extension
│ ├── BotHelp.cs
│ ├── ExtensionPlugin.cs
│ ├── HelpCategory.cs
│ ├── HelpCommand.cs
│ ├── HelpInfo.cs
│ ├── IHelp.cs
│ ├── ISenderExtension.cs
│ ├── Scheduler.cs
│ └── WanBotPluginExtension.cs
├── Graphic
│ ├── Avatar.cs
│ ├── GraphicConfig.cs
│ ├── GraphicPlugin.Example.cs
│ └── GraphicPlugin.cs
├── InvitationPlugin.cs
├── Migrations
│ ├── 20220819153046_InitialCreate.Designer.cs
│ ├── 20220819153046_InitialCreate.cs
│ └── EssAttributeDatabaseContextModelSnapshot.cs
├── Permission
│ ├── ISenderExtension.cs
│ ├── Permission.cs
│ ├── PermissionConfig.cs
│ ├── PermissionDatabase.cs
│ ├── PermissionException.cs
│ └── PermissionPlugin.cs
├── SaveQPlugin.cs
└── WanBot.Plugin.Essential.csproj
├── WanBot.Plugin.HelloWorld
├── HelloWorldPlugin.cs
├── JrrpAddition.cs
└── WanBot.Plugin.HelloWorld.csproj
├── WanBot.Plugin.HotSpot
├── HotSpot.cs
├── WanBot.Plugin.HotSpot.csproj
└── WeiboUtil.cs
├── WanBot.Plugin.JavaScript
├── JavaScriptPlugin.cs
├── JsEnv.cs
└── WanBot.Plugin.JavaScript.csproj
├── WanBot.Plugin.JobAndLife
├── JobAndLifePlugin.cs
├── JrrpAddition.cs
└── WanBot.Plugin.JobAndLife.csproj
├── WanBot.Plugin.Jrrp
├── JrrpConfig.cs
├── JrrpDatabaseContext.cs
├── JrrpPlugin.cs
├── JrrpUser.cs
├── Migrations
│ ├── 20220806155035_InitialCreate.Designer.cs
│ ├── 20220806155035_InitialCreate.cs
│ ├── 20220819170410_AddCanDoAndCantDo.Designer.cs
│ ├── 20220819170410_AddCanDoAndCantDo.cs
│ └── JrrpDatabaseContextModelSnapshot.cs
└── WanBot.Plugin.Jrrp.csproj
├── WanBot.Plugin.Kemono
├── KemonoPlugin.cs
└── WanBot.Plugin.Kemono.csproj
├── WanBot.Plugin.LuaScript
├── LuaCancellableApi.cs
├── LuaDebugger.cs
├── LuaEnv.cs
├── LuaScrpitPlugin.cs
└── WanBot.Plugin.LuaScript.csproj
├── WanBot.Plugin.Pokemon
├── PokemonDatabase.cs
├── PokemonPlugin.cs
├── Tools
│ ├── convert.ipynb
│ └── map.csv
└── WanBot.Plugin.Pokemon.csproj
├── WanBot.Plugin.RandomStuff
├── Food
│ ├── CookMethod.cs
│ ├── FoodStructure.cs
│ ├── IFoodGenerator.cs
│ ├── Ingredients.cs
│ └── RandomFoodGenerator.cs
├── RandomStuffConfig.cs
├── RandomStuffPlugin.cs
└── WanBot.Plugin.RandomStuff.csproj
├── WanBot.Plugin.WanCoin
├── JrrpAddition.cs
├── Migrations
│ ├── 20221009071933_InitialCreate.Designer.cs
│ ├── 20221009071933_InitialCreate.cs
│ ├── 20221022055158_AddTrade.Designer.cs
│ ├── 20221022055158_AddTrade.cs
│ └── WanCoinDatabaseModelSnapshot.cs
├── WanBot.Plugin.WanCoin.csproj
├── WanCoinDatabase.cs
├── WanCoinHash.cs
├── WanCoinPlugin.cs
├── WanCoinTrade.cs
└── WanCoinUser.cs
├── WanBot.Plugin.YGO
├── CardEnum
│ ├── CardAttribute.cs
│ ├── CardLimitOt.cs
│ ├── CardLinkMarker.cs
│ ├── CardLocation.cs
│ ├── CardPosition.cs
│ ├── CardRace.cs
│ └── CardType.cs
├── CardRenderer.cs
├── WanBot.Plugin.YGO.csproj
├── YGOPlugin.cs
├── YgoCard.cs
├── YgoCardImage.cs
├── YgoDatabase.cs
└── YgoFilter.cs
├── WanBot.Test
├── EventBotSerializeTest.cs
├── EventFriendSerializeTest.cs
├── EventGroupSerializeTest.cs
├── EventMessageSerializeTest.cs
├── EventOtherSerializeTest.cs
├── EventRequestSerializeTest.cs
├── MessageChainSerializeTest.cs
├── Usings.cs
├── Util
│ └── JsonHelper.cs
└── WanBot.Test.csproj
├── WanBot.sln
└── WanBot
├── Application.cs
├── BotDomain.cs
├── BotManager.cs
├── Logger.cs
├── PluginChangeListener.cs
├── PluginManager.cs
├── Program.cs
├── Properties
└── launchSettings.json
├── Util
└── ConfigHelper.cs
├── WanBot.cs
├── WanBot.csproj
└── WanBotConfig.cs
/.dockerignore:
--------------------------------------------------------------------------------
1 | **/bin
2 | **/obj
3 | **/.vs
4 | .git
5 | Bin
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env
2 | WORKDIR /App
3 |
4 | # Copy csproject
5 | COPY ./*.sln ./
6 | COPY ./**/*.csproj ./
7 | RUN for file in $(ls *.csproj); do mkdir -p ./${file%.*}/ && mv $file ./${file%.*}/; done
8 |
9 | # Restore
10 | RUN dotnet restore
11 |
12 | # Copy other files
13 | COPY . ./
14 |
15 | # Build release
16 | ARG BUILD_NUMBER=0
17 | RUN dotnet publish -c Release --os linux --version-suffix $BUILD_NUMBER
18 |
19 | # Build runtime image
20 | FROM mcr.microsoft.com/dotnet/runtime:8.0
21 | WORKDIR /App
22 |
23 | # Install vulkan
24 | RUN apt-get update && \
25 | apt-get install -y libvulkan1 libc6-dev && \
26 | apt-get clean
27 |
28 | # Create dir
29 | VOLUME [ "/data" ]
30 | RUN mkdir Plugin
31 |
32 | # Set timezone
33 | ENV TZ=Asia/Shanghai
34 |
35 | COPY --from=build-env /App/WanBot/bin/Release/net8.0/linux-x64/publish/ .
36 | COPY --from=build-env /App/Bin/Plugin/Release/net8.0/linux-x64/publish/ ./Plugin/
37 |
38 | # Entry point
39 | ENTRYPOINT ["dotnet", "WanBot.dll", "-config", "/data"]
40 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # WanBot
2 | MOVE TO [ProjectWanBot/WanBot](https://github.com/ProjectWanBot/WanBot)
3 |
4 | An open source chatbot framework by c# for QQ based on mirai. Provide a plugin support.
5 | ## Plugin list
6 | 1. WanBot.Plugin.Core
7 | 1. WanBot.Plugin.Essential
8 | Provide base extension methods such as command permission and graphic support.
9 | 1. WanBot.Plugin.HelloWorld
10 | An example WanBot plugin
11 | 1. WanBot.Plugin.HotSpot
12 | Show current hot spot based on sina api
13 | 1. WanBot.Plugin.JobAndLife
14 | 1. WanBot.Plugin.Jrrp
15 | 1. WanBot.Plugin.LuaScript
16 | Add lua support for WanBot. User can run lua script and add custom commands.
17 | 1. WanBot.Plugin.Pokemon
18 | Find and display a pokemon(or a fusion pokemon)
19 | 1. WanBot.Plugin.RandomStuff
20 | 1. WanBot.Plugin.WanCoin
21 | 1. WanBot.Plugin.YGO
22 | ## How to use
23 | ### Docker
24 | Run command ``docker build -t wanbot/wanbot .``
25 | ### Other
26 | Clone the repo and open the solution. Select WanBot and just build it.
27 | ## Custom plugin
28 | Follow the instruction in WanBot.Plugin.HelloWorld
29 | ## Contact
30 | QQ group: 207276833
31 |
--------------------------------------------------------------------------------
/WanBot.Api/Event/AtAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace WanBot.Api.Event
8 | {
9 | [AttributeUsage(AttributeTargets.Method)]
10 | public class AtAttribute : EventAttribute
11 | {
12 | public int Priority { get; }
13 |
14 | public AtAttribute(int priority = 0)
15 | {
16 | Priority = priority;
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/WanBot.Api/Event/AtEventArgs.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using WanBot.Api.Mirai.Message;
7 |
8 | namespace WanBot.Api.Event
9 | {
10 | public class AtEventArgs : BlockableEventArgs
11 | {
12 | public ISender Sender { get; }
13 |
14 | public MessageChain Chain { get; }
15 |
16 | public AtEventArgs(ISender sender, MessageChain chain)
17 | {
18 | Sender = sender;
19 | Chain = chain;
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/WanBot.Api/Event/BlockableEventArgs.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Text.Json.Serialization;
6 | using System.Threading.Tasks;
7 |
8 | namespace WanBot.Api.Event
9 | {
10 | ///
11 | /// 可阻塞的事件
12 | ///
13 | public class BlockableEventArgs
14 | {
15 | ///
16 | /// 是否取消事件的传递
17 | ///
18 | [JsonIgnore]
19 | public bool Blocked { get; set; }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/WanBot.Api/Event/CommandAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace WanBot.Api.Event
8 | {
9 | ///
10 | /// 命令
11 | ///
12 | [AttributeUsage(AttributeTargets.Method)]
13 | public class CommandAttribute : EventAttribute
14 | {
15 | public string[] Commands { get; }
16 |
17 | public int Priority { get; }
18 |
19 | public CommandAttribute(string command, int priority = 0)
20 | {
21 | Commands = new[] { command };
22 | Priority = priority;
23 | }
24 |
25 | public CommandAttribute(IEnumerable commands, int priority = 0)
26 | {
27 | Commands = commands.ToArray();
28 | Priority = priority;
29 | }
30 |
31 | public CommandAttribute(params string[] commands)
32 | {
33 | Commands = commands;
34 | Priority = 0;
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/WanBot.Api/Event/EventAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace WanBot.Api.Event
8 | {
9 | [AttributeUsage(AttributeTargets.Method)]
10 | public class EventAttribute : Attribute
11 | {
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/WanBot.Api/Event/MiraiEventAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using WanBot.Api.Mirai.Event;
7 |
8 | namespace WanBot.Api.Event
9 | {
10 | [AttributeUsage(AttributeTargets.Method)]
11 | public class MiraiEventAttribute : MiraiEventAttribute where T : BaseMiraiEvent
12 | {
13 | public MiraiEventAttribute(int priority = 0) : base(priority, typeof(T)) { }
14 | }
15 |
16 | [AttributeUsage(AttributeTargets.Method)]
17 | public class MiraiEventAttribute : EventAttribute
18 | {
19 | public int Priority { get; }
20 |
21 | public Type EventType { get; }
22 |
23 | public MiraiEventAttribute(int priority, Type type)
24 | {
25 | Priority = priority;
26 | EventType = type;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/WanBot.Api/Event/NudgeAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace WanBot.Api.Event
8 | {
9 | [AttributeUsage(AttributeTargets.Method)]
10 | public class NudgeAttribute : EventAttribute
11 | {
12 | public int Priority { get; }
13 |
14 | public NudgeAttribute(int priority = 0)
15 | {
16 | Priority = priority;
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/WanBot.Api/Event/NudgeEventArgs.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace WanBot.Api.Event
8 | {
9 | public class NudgeEventArgs : BlockableEventArgs
10 | {
11 | public ISender Sender { get; }
12 |
13 | public NudgeEventArgs(ISender sender)
14 | {
15 | Sender = sender;
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/WanBot.Api/Event/Priority.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace WanBot.Api.Event
8 | {
9 | public static class Priority
10 | {
11 | public const int BottomMost = int.MinValue;
12 | public const int Lowest = -10000;
13 | public const int Lower = -1000;
14 | public const int Low = -100;
15 | public const int Default = 0;
16 | public const int High = 100;
17 | public const int Higher = 1000;
18 | public const int Highest = 10000;
19 | public const int TopMost = int.MaxValue;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/WanBot.Api/Event/RegexAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Text.RegularExpressions;
6 | using System.Threading.Tasks;
7 |
8 | namespace WanBot.Api.Event
9 | {
10 | [AttributeUsage(AttributeTargets.Method)]
11 | public class RegexAttribute : EventAttribute
12 | {
13 | public Regex Regex { get; }
14 |
15 | public int Priority { get; }
16 |
17 | public RegexAttribute(string regex, int priority = 0)
18 | {
19 | Regex = new Regex(regex, RegexOptions.Compiled);
20 | Priority = priority;
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/WanBot.Api/Event/RegexEventArgs.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Text.RegularExpressions;
6 | using System.Threading.Tasks;
7 | using WanBot.Api.Mirai.Message;
8 |
9 | namespace WanBot.Api.Event
10 | {
11 | public class RegexEventArgs : BlockableEventArgs
12 | {
13 | public ISender Sender { get; }
14 |
15 | public MessageChain Chain { get; }
16 |
17 | public Regex Regex { get; }
18 |
19 | public RegexEventArgs(ISender sender, MessageChain chain, Regex regex)
20 | {
21 | Sender = sender;
22 | Regex = regex;
23 | Chain = chain;
24 | }
25 |
26 | public string GetEventName()
27 | {
28 | return GetEventName(Regex);
29 | }
30 |
31 | public static string GetEventName(Regex regex)
32 | {
33 | return $"{typeof(RegexEventArgs).Name}.{regex}";
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/WanBot.Api/Event/WanBotEventEvent.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using WanBot.Api.Mirai;
7 |
8 | namespace WanBot.Api.Event
9 | {
10 | ///
11 | /// 事件
12 | ///
13 | public class WanBotEventEvent
14 | {
15 | private List _handlers = new();
16 |
17 | ///
18 | /// 插入事件处理器,并保持顺序
19 | ///
20 | ///
21 | public void Add(WanBotEventHandler handler)
22 | {
23 | if (_handlers.Count == 0)
24 | _handlers.Add(handler);
25 | else
26 | {
27 | for (var i = 0; i < _handlers.Count; i++)
28 | {
29 | if (_handlers[i].Priority > handler.Priority)
30 | continue;
31 | _handlers.Insert(i, handler);
32 | return;
33 | }
34 | _handlers.Insert(_handlers.Count, handler);
35 | }
36 | }
37 |
38 | public async Task InvokeAsync(MiraiBot sender, BlockableEventArgs e)
39 | {
40 | foreach (var handler in _handlers)
41 | {
42 | await handler.Handler.Invoke(sender, e);
43 | if (e.Blocked)
44 | break;
45 | }
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/WanBot.Api/Event/WanBotEventHandler.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using WanBot.Api.Mirai;
7 |
8 | namespace WanBot.Api.Event
9 | {
10 | ///
11 | /// 事件处理器
12 | ///
13 | public class WanBotEventHandler
14 | {
15 | public int Priority { get; }
16 |
17 | public WanBotEventHandler(int priority, Func handler)
18 | {
19 | Priority = priority;
20 | Handler = handler;
21 | }
22 |
23 | public Func Handler { get; }
24 | }
25 |
26 | ///
27 | /// 泛形事件处理器
28 | ///
29 | ///
30 | public class MiraiEventHandler : WanBotEventHandler where T : BlockableEventArgs
31 | {
32 | public MiraiEventHandler(int priority, Func handler)
33 | : base(priority, (s, e) => handler(s, (T)e)) { }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/WanBot.Api/Hook/HookExtension.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using WanBot.Api.Event;
7 | using WanBot.Api.Mirai;
8 |
9 | namespace WanBot.Api.Hook
10 | {
11 | internal static class HookExtension
12 | {
13 | public async static Task HookAsync(this T obj, MiraiBot bot, HookType type)
14 | {
15 | switch (type)
16 | {
17 | case HookType.Event:
18 | return (T?)(object?)await HookEventAsync((BlockableEventArgs)(object)obj!, bot);
19 | case HookType.Exception:
20 | return ((T?)(object?)await HookExceptionAsync((Exception)(object)obj!, bot))!;
21 | case HookType.Api:
22 | return (T?)await HookApiAsync(obj!, bot);
23 | }
24 | return obj;
25 | }
26 |
27 | private async static Task