├── .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 HookApiAsync(object obj, MiraiBot bot) 28 | { 29 | if (HookTable.Instance.ApiHook == null) 30 | return obj; 31 | return await HookTable.Instance.ApiHook.Invoke(bot, obj); 32 | } 33 | 34 | private async static Task HookExceptionAsync(Exception e, MiraiBot bot) 35 | { 36 | if (HookTable.Instance.ExceptionHook == null) 37 | return e; 38 | return await HookTable.Instance.ExceptionHook.Invoke(bot, e); 39 | } 40 | 41 | private async static Task HookEventAsync(BlockableEventArgs e, MiraiBot bot) 42 | { 43 | if (HookTable.Instance.EventHook == null) 44 | return e; 45 | return await HookTable.Instance.EventHook.Invoke(bot, e); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /WanBot.Api/Hook/HookTable.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 | /// 12 | /// Hook表 13 | /// 14 | public class HookTable 15 | { 16 | /// 17 | /// 全局Hook Table 18 | /// 19 | public static HookTable Instance { get; } = new(); 20 | 21 | /// 22 | /// 异常hook 23 | /// 24 | public Func>? ExceptionHook { get; set; } 25 | 26 | /// 27 | /// 事件Hook 28 | /// 29 | public Func>? EventHook { get; set; } 30 | 31 | /// 32 | /// Api Hook 33 | /// 34 | public Func>? ApiHook { get; set; } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /WanBot.Api/Hook/HookType.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.Hook 8 | { 9 | internal enum HookType 10 | { 11 | Event, Api, Exception 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /WanBot.Api/IApplication.cs: -------------------------------------------------------------------------------- 1 | namespace WanBot.Api 2 | { 3 | /// 4 | /// 应用程序 5 | /// 6 | public interface IApplication 7 | { 8 | IBotManager BotManager { get; } 9 | 10 | IPluginManager PluginManager { get; } 11 | 12 | /// 13 | /// 读取配置 14 | /// 15 | /// 16 | /// 17 | T ReadConfig(string pluginName) where T : new(); 18 | 19 | /// 20 | /// 获取配置目录 21 | /// 22 | /// 23 | /// 24 | string GetConfigPath(string pluginName); 25 | } 26 | } -------------------------------------------------------------------------------- /WanBot.Api/IBotManager.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 10 | { 11 | public interface IBotManager 12 | { 13 | /// 14 | /// 订阅事件 15 | /// 16 | /// 17 | /// 18 | /// 19 | /// 20 | WanBotEventHandler Subscript(int priority, Func func) 21 | where T : BlockableEventArgs; 22 | 23 | /// 24 | /// 订阅事件 25 | /// 26 | /// 27 | /// 28 | /// 29 | /// 30 | WanBotEventHandler Subscript(Type type, int priority, Func func); 31 | 32 | /// 33 | /// 订阅事件 34 | /// 35 | /// 36 | /// 37 | /// 38 | /// 39 | WanBotEventHandler Subscript(string eventName, int priority, Func func); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /WanBot.Api/ILogger.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 8 | { 9 | /// 10 | /// 日志 11 | /// 12 | public interface ILogger 13 | { 14 | public void Info(string message, params object?[]? args); 15 | public void Warn(string message, params object?[]? args); 16 | public void Error(string message, params object?[]? args); 17 | public void Fatal(string message, params object?[]? args); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /WanBot.Api/IPermissionService.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 8 | { 9 | /// 10 | /// 权限 11 | /// 12 | public interface IPermissionService 13 | { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /WanBot.Api/IPluginManager.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 8 | { 9 | /// 10 | /// 插件管理器接口 11 | /// 12 | public interface IPluginManager 13 | { 14 | /// 15 | /// 获取指定的插件 16 | /// 17 | /// 18 | /// 19 | T? GetPlugin() where T : BasePlugin; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /WanBot.Api/ISender.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.Message; 7 | using WanBot.Api.Mirai; 8 | using WanBot.Api.Mirai.Message; 9 | 10 | namespace WanBot.Api 11 | { 12 | /// 13 | /// 消息发送者接口 14 | /// 15 | public interface ISender 16 | { 17 | /// 18 | /// Sender所在的bot 19 | /// 20 | public MiraiBot Bot { get; } 21 | 22 | /// 23 | /// 内部名称 24 | /// 25 | public string InternalName { get; } 26 | 27 | /// 28 | /// 昵称 29 | /// 30 | public string DisplayName { get; } 31 | 32 | /// 33 | /// 消息发送源的QQ号 34 | /// 35 | public long Id { get; } 36 | 37 | /// 38 | /// 回复消息 39 | /// 40 | /// 41 | Task ReplyAsync(MessageChain messageChain); 42 | 43 | /// 44 | /// 回复消息 45 | /// 46 | /// 47 | Task ReplyAsync(string message, int? replyId = null); 48 | 49 | /// 50 | /// 回复消息 51 | /// 52 | /// 53 | Task ReplyAsync(IMessageBuilder messageBuilder, int? replyId = null); 54 | 55 | /// 56 | /// 戳一戳对方 57 | /// 58 | /// 59 | Task NudgeAsync(); 60 | 61 | /// 62 | /// 获取发送者信息 63 | /// 64 | /// 65 | Task GetProfileAsync(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /WanBot.Api/Message/ForwardMessageBuilder.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 | using WanBot.Api.Mirai.Message; 8 | 9 | namespace WanBot.Api.Message 10 | { 11 | public class ForwardMessageBuilder : IMessageBuilder 12 | { 13 | private List> _nodeListFactory = new(); 14 | 15 | /// 16 | /// 创建转发消息 17 | /// 18 | /// 19 | public ForwardMessageBuilder Forward(long target, string senderName, IMessageBuilder msg) 20 | { 21 | _nodeListFactory.Add((bot, msgType) => new Forward.ForwardNode 22 | { 23 | MessageChain = new MessageChain(msg.Build(bot, msgType)), 24 | SenderId = target, 25 | SenderName = senderName, 26 | Time = (int)DateTime.Now.Ticks, 27 | MessageId = null 28 | }); 29 | return this; 30 | } 31 | 32 | public IEnumerable Build(MiraiBot bot, MessageType messageType) 33 | { 34 | yield return new Forward 35 | { 36 | NodeList = BuildNodeList(bot, messageType).ToList() 37 | }; 38 | } 39 | 40 | private IEnumerable BuildNodeList(MiraiBot bot, MessageType messageType) 41 | { 42 | foreach (var obj in _nodeListFactory) 43 | yield return obj.Invoke(bot, messageType); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /WanBot.Api/Message/FriendSender.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 | using WanBot.Api.Mirai.Message; 8 | 9 | namespace WanBot.Api.Message 10 | { 11 | public class FriendSender : ISender 12 | { 13 | public MiraiBot Bot { get; } 14 | public long Id { get; } 15 | 16 | public string InternalName { get; } 17 | public string DisplayName { get; } 18 | 19 | public FriendSender(MiraiBot bot, string internalName, string displayName, long qqId) 20 | { 21 | InternalName = internalName; 22 | DisplayName = displayName; 23 | Id = qqId; 24 | Bot = bot; 25 | } 26 | 27 | public async Task ReplyAsync(MessageChain messageChain) 28 | { 29 | await Bot.SendFriendMessageAsync(Id, null, messageChain); 30 | } 31 | 32 | public async Task ReplyAsync(string message, int? replyId = null) 33 | { 34 | await Bot.SendFriendMessageAsync(Id, replyId, message); 35 | } 36 | 37 | public async Task ReplyAsync(IMessageBuilder messageBuilder, int? replyId = null) 38 | { 39 | await Bot.SendFriendMessageAsync(Id, replyId, messageBuilder); 40 | } 41 | 42 | public async Task NudgeAsync() 43 | { 44 | await Bot.SendFriendNudgeAsync(Id); 45 | } 46 | 47 | public async Task GetProfileAsync() 48 | { 49 | return await Bot.FriendProfileAsync(Id); 50 | } 51 | 52 | public override int GetHashCode() 53 | { 54 | return Id.GetHashCode(); 55 | } 56 | 57 | public override bool Equals(object? obj) 58 | { 59 | if (obj is not FriendSender friendSender) 60 | return false; 61 | return 62 | friendSender.Id == Id; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /WanBot.Api/Message/IMessageBuilder.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 | using WanBot.Api.Mirai.Message; 8 | 9 | namespace WanBot.Api.Message 10 | { 11 | public interface IMessageBuilder 12 | { 13 | public IEnumerable Build(MiraiBot bot, MessageType messageType); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /WanBot.Api/Message/MessageType.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.Message 8 | { 9 | public enum MessageType 10 | { 11 | Friend = 0, 12 | Group = 1, 13 | Temp = 2 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /WanBot.Api/Message/MiraiImage.cs: -------------------------------------------------------------------------------- 1 | using SkiaSharp; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Drawing; 5 | using System.Drawing.Imaging; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using WanBot.Api.Mirai; 10 | 11 | namespace WanBot.Api.Message 12 | { 13 | /// 14 | /// Mirai图像 15 | /// 16 | public class MiraiImage : IDisposable 17 | { 18 | private MiraiBot _bot; 19 | private SKImage _image; 20 | private (string url, string id)[] _imageId = new (string url, string id)[3]; 21 | 22 | private bool _disposeImage; 23 | 24 | public MiraiImage(MiraiBot bot, SKImage image, bool disposeImage = true) 25 | { 26 | _bot = bot; 27 | _image = image; 28 | _disposeImage = disposeImage; 29 | } 30 | 31 | /// 32 | /// 获取图像Url 33 | /// 34 | /// 35 | public async Task<(string url, string id)> SendImageAsync(MessageType imageType) 36 | { 37 | if (!string.IsNullOrEmpty(_imageId[(int)imageType].id)) 38 | return _imageId[(int)imageType]; 39 | 40 | var type = imageType.ToString().ToLower(); 41 | using var data = _image.Encode(SKEncodedImageFormat.Jpeg, 80); 42 | var uploadImageResponse = await _bot.UploadImageAsync(type, data.AsStream()); 43 | 44 | _imageId[(int)imageType].id = uploadImageResponse.ImageId; 45 | _imageId[(int)imageType].url = uploadImageResponse.Url; 46 | 47 | return _imageId[(int)imageType]; 48 | } 49 | 50 | public void Dispose() 51 | { 52 | if (_disposeImage) 53 | _image?.Dispose(); 54 | GC.SuppressFinalize(this); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Adapter/IAdapter.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.Network; 7 | 8 | namespace WanBot.Api.Mirai.Adapter 9 | { 10 | /// 11 | /// 适配器通用接口 12 | /// 13 | public interface IAdapter : IDisposable 14 | { 15 | public string BaseUrl { get; } 16 | 17 | public string VerifyKey { get; } 18 | 19 | public long QQ { get; } 20 | 21 | public bool IsConnected { get; } 22 | 23 | /// 24 | /// 执行 25 | /// 26 | /// 27 | /// 28 | /// 29 | /// 30 | public Task SendAsync(RequestPayload? request) 31 | where RequestPayload : IRequest 32 | where ResponsePayload : IResponse; 33 | 34 | /// 35 | /// 异步连接 36 | /// 37 | /// 38 | public Task ConnectAsync(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Client.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.Mirai 8 | { 9 | /// 10 | /// 客户端消息 11 | /// 12 | public struct Client 13 | { 14 | public Client() 15 | { 16 | } 17 | 18 | /// 19 | /// 客户端Id 20 | /// 21 | public long Id { get; set; } = 0; 22 | 23 | /// 24 | /// 客户端平台 25 | /// 26 | public string Platform { get; set; } = string.Empty; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/BotGroupPermissionChangeEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// Bot在群里的权限被改变. 操作人一定是群主 11 | /// 12 | public class BotGroupPermissionChangeEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// Bot的原权限,OWNER、ADMINISTRATOR或MEMBER 16 | /// 17 | public string Origin { get; set; } = string.Empty; 18 | 19 | /// 20 | /// Bot的新权限,OWNER、ADMINISTRATOR或MEMBER 21 | /// 22 | public string Current { get; set; } = string.Empty; 23 | 24 | /// 25 | /// 权限改变所在的群信息 26 | /// 27 | public Group Group { get; set; } = new(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/BotInvitedJoinGroupRequestEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// Bot被邀请入群申请 11 | /// 12 | public class BotInvitedJoinGroupRequestEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// 事件标识,响应该事件时的标识 16 | /// 17 | public long EventId { get; set; } 18 | 19 | /// 20 | /// 邀请人(好友)的QQ号 21 | /// 22 | public long FromId { get; set; } 23 | 24 | /// 25 | /// 被邀请进入群的群号 26 | /// 27 | public long GroupId { get; set; } 28 | 29 | /// 30 | /// 被邀请进入群的群名称 31 | /// 32 | public string GroupName { get; set; } = string.Empty; 33 | 34 | /// 35 | /// 邀请人(好友)的昵称 36 | /// 37 | public string Nick { get; set; } = string.Empty; 38 | 39 | /// 40 | /// 邀请消息 41 | /// 42 | public string Message { get; set; } = string.Empty; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/BotJoinGroupEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// Bot加入了一个新群 11 | /// 12 | public class BotJoinGroupEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// Bot新加入群的信息 16 | /// 17 | public Group Group { get; set; } = new(); 18 | 19 | /// 20 | /// 如果被邀请入群的话,则为邀请人的 Member 对象 21 | /// 22 | public Member? Invitor { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/BotLeaveEventActive.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.Mirai.Event 8 | { 9 | /// 10 | /// Bot主动退出一个群 11 | /// 12 | public class BotLeaveEventActive : BaseMiraiEvent 13 | { 14 | /// 15 | /// Bot退出的群的信息 16 | /// 17 | public Group Group { get; set; } = new(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/BotLeaveEventKick.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.Mirai.Event 8 | { 9 | /// 10 | /// Bot被踢出一个群 11 | /// 12 | public class BotLeaveEventKick : BaseMiraiEvent 13 | { 14 | /// 15 | /// Bot被踢出的群的信息 16 | /// 17 | public Group Group { get; set; } = new(); 18 | 19 | /// 20 | /// Bot被踢后获取操作人的 Member 对象 21 | /// 22 | public Member? Operator { get; set; } = new(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/BotMuteEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// Bot被禁言 11 | /// 12 | public class BotMuteEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// 禁言时长,单位为秒 16 | /// 17 | public int DurationSeconds { get; set; } 18 | 19 | /// 20 | /// 操作的管理员或群主信息 21 | /// 22 | public Member Operator { get; set; } = new(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/BotOfflineEventActive.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.Mirai.Event 8 | { 9 | /// 10 | /// Bot主动离线 11 | /// 12 | public class BotOfflineEventActive : BaseMiraiEvent 13 | { 14 | /// 15 | /// 主动离线的Bot的QQ号 16 | /// 17 | public long QQ { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/BotOfflineEventDropped.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.Mirai.Event 8 | { 9 | /// 10 | /// Bot被服务器断开或因网络问题而掉线 11 | /// 12 | public class BotOfflineEventDropped : BaseMiraiEvent 13 | { 14 | /// 15 | /// 被服务器断开或因网络问题而掉线的Bot的QQ号 16 | /// 17 | public long QQ { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/BotOfflineEventForce.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.Mirai.Event 8 | { 9 | /// 10 | /// Bot被挤下线 11 | /// 12 | public class BotOfflineEventForce : BaseMiraiEvent 13 | { 14 | /// 15 | /// 被挤下线的Bot的QQ号 16 | /// 17 | public long QQ { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/BotOnlineEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// Bot登录成功 11 | /// 12 | public class BotOnlineEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// 登录成功的Bot的QQ号 16 | /// 17 | public long QQ { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/BotReloginEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// Bot主动重新登录 11 | /// 12 | public class BotReloginEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// 主动重新登录的Bot的QQ号 16 | /// 17 | public long QQ { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/BotUnmuteEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// Bot被取消禁言 11 | /// 12 | public class BotUnmuteEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// 操作的管理员或群主信息 16 | /// 17 | public Member Operator { get; set; } = new(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/CommandExecutedEvent.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.Mirai.Event 9 | { 10 | /// 11 | /// 命令被执行 12 | /// 13 | public class CommandExecutedEvent : BaseMiraiEvent 14 | { 15 | /// 16 | /// 其他客户端 17 | /// 18 | public string Name { get; set; } = string.Empty; 19 | 20 | /// 21 | /// 发送命令的好友, 从控制台发送为 null 22 | /// 23 | public Friend? Friend { get; set; } 24 | 25 | /// 26 | /// 发送命令的好友, 从控制台发送为 null 27 | /// 28 | public Member? Member { get; set; } 29 | 30 | /// 31 | /// 指令的参数, 以消息类型传递 32 | /// 33 | public MessageChain? Args { get; set; } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/FriendInputStatusChangedEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// 好友输入状态改变 11 | /// 12 | public class FriendInputStatusChangedEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// 好友 16 | /// 17 | public Friend Friend { get; set; } = new(); 18 | 19 | /// 20 | /// 当前输出状态是否正在输入 21 | /// 22 | public bool Inputting { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/FriendMessage.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.Mirai.Event 9 | { 10 | /// 11 | /// 好友消息 12 | /// 13 | public class FriendMessage : BaseMiraiEvent 14 | { 15 | /// 16 | /// 发送者 17 | /// 18 | public Friend Sender { get; set; } = new(); 19 | 20 | /// 21 | /// 消息链 22 | /// 23 | public MessageChain MessageChain { get; set; } = new(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/FriendNickChangedEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// 好友昵称改变 11 | /// 12 | public class FriendNickChangedEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// 好友 16 | /// 17 | public Friend Friend { get; set; } = new(); 18 | 19 | /// 20 | /// 原昵称 21 | /// 22 | public string From { get; set; } = string.Empty; 23 | 24 | /// 25 | /// 新昵称 26 | /// 27 | public string To { get; set; } = string.Empty; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/FriendRecallEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// 好友消息撤回 11 | /// 12 | public class FriendRecallEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// 原消息发送者的QQ号 16 | /// 17 | public long AuthorId { get; set; } 18 | 19 | /// 20 | /// 原消息messageId 21 | /// 22 | public int MessageId { get; set; } 23 | 24 | /// 25 | /// 原消息发送时间 26 | /// 27 | public int Time { get; set; } 28 | 29 | /// 30 | /// 好友QQ号或BotQQ号 31 | /// 32 | public long Operator { get; set; } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/FriendSyncMessage.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.Mirai.Event 9 | { 10 | /// 11 | /// 同步好友消息 12 | /// 13 | public class FriendSyncMessage : BaseMiraiEvent 14 | { 15 | /// 16 | /// 发送者 17 | /// 18 | public Friend Subject { get; set; } = new(); 19 | 20 | /// 21 | /// 消息链 22 | /// 23 | public MessageChain MessageChain { get; set; } = new(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/GroupAllowAnonymousChatEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// 匿名聊天 11 | /// 12 | public class GroupAllowAnonymousChatEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// 原本匿名聊天是否开启 16 | /// 17 | public bool Origin { get; set; } 18 | 19 | /// 20 | /// 现在匿名聊天是否开启 21 | /// 22 | public bool Current { get; set; } 23 | 24 | /// 25 | /// 匿名聊天状态改变的群信息 26 | /// 27 | public Group Group { get; set; } = new(); 28 | 29 | /// 30 | /// 操作的管理员或群主信息,当null时为Bot操作 31 | /// 32 | public Member? Operator { get; set; } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/GroupAllowConfessTalkEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// 坦白说 11 | /// 12 | public class GroupAllowConfessTalkEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// 原本坦白说是否开启 16 | /// 17 | public bool Origin { get; set; } 18 | 19 | /// 20 | /// 现在坦白说是否开启 21 | /// 22 | public bool Current { get; set; } 23 | 24 | /// 25 | /// 坦白说状态改变的群信息 26 | /// 27 | public Group Group { get; set; } = new(); 28 | 29 | /// 30 | /// 是否Bot进行该操作 31 | /// 32 | public bool IsByBot { get; set; } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/GroupAllowMemberInviteEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// 允许群员邀请好友加群 11 | /// 12 | public class GroupAllowMemberInviteEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// 原本是否允许群员邀请好友加群 16 | /// 17 | public bool Origin { get; set; } 18 | 19 | /// 20 | /// 现在是否允许群员邀请好友加群 21 | /// 22 | public bool Current { get; set; } 23 | 24 | /// 25 | /// 允许群员邀请好友加群状态改变的群信息 26 | /// 27 | public Group Group { get; set; } = new(); 28 | 29 | /// 30 | /// 操作的管理员或群主信息,当null时为Bot操作 31 | /// 32 | public Member? Operator { get; set; } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/GroupEntranceAnnouncementChangeEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// 某群入群公告改变 11 | /// 12 | public class GroupEntranceAnnouncementChangeEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// 原公告 16 | /// 17 | public string Origin { get; set; } = string.Empty; 18 | 19 | /// 20 | /// 新公告 21 | /// 22 | public string Current { get; set; } = string.Empty; 23 | 24 | /// 25 | /// 公告改变的群信息 26 | /// 27 | public Group Group { get; set; } = new(); 28 | 29 | /// 30 | /// 操作的管理员或群主信息,当null时为Bot操作 31 | /// 32 | public Member? Operator { get; set; } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/GroupMessage.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.Mirai.Event 9 | { 10 | /// 11 | /// 群消息 12 | /// 13 | public class GroupMessage : BaseMiraiEvent 14 | { 15 | /// 16 | /// 发送者 17 | /// 18 | public Member Sender { get; set; } = new(); 19 | 20 | /// 21 | /// 消息链 22 | /// 23 | public MessageChain MessageChain { get; set; } = new(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/GroupMuteAllEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// 全员禁言 11 | /// 12 | public class GroupMuteAllEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// 原本是否处于全员禁言 16 | /// 17 | public bool Origin { get; set; } 18 | 19 | /// 20 | /// 现在是否处于全员禁言 21 | /// 22 | public bool Current { get; set; } 23 | 24 | /// 25 | /// 全员禁言的群信息 26 | /// 27 | public Group Group { get; set; } = new(); 28 | 29 | /// 30 | /// 操作的管理员或群主信息,当null时为Bot操作 31 | /// 32 | public Member? Operator { get; set; } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/GroupNameChangeEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// 某个群名改变 11 | /// 12 | public class GroupNameChangeEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// 原群名 16 | /// 17 | public string Origin { get; set; } = string.Empty; 18 | 19 | /// 20 | /// 新群名 21 | /// 22 | public string Current { get; set; } = string.Empty; 23 | 24 | /// 25 | /// 群名改名的群信息 26 | /// 27 | public Group Group { get; set; } = new(); 28 | 29 | /// 30 | /// 操作的管理员或群主信息,当null时为Bot操作 31 | /// 32 | public Member? Operator { get; set; } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/GroupRecallEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// 群消息撤回 11 | /// 12 | public class GroupRecallEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// 原消息发送者的QQ号 16 | /// 17 | public long AuthorId { get; set; } 18 | 19 | /// 20 | /// 原消息messageId 21 | /// 22 | public int MessageId { get; set; } 23 | 24 | /// 25 | /// 原消息发送时间 26 | /// 27 | public int Time { get; set; } 28 | 29 | /// 30 | /// 消息撤回所在的群 31 | /// 32 | public Group Group { get; set; } = new(); 33 | 34 | /// 35 | /// 撤回消息的操作人,当null时为bot操作 36 | /// 37 | public Member? Operator { get; set; } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/GroupSyncMessage.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.Mirai.Event 9 | { 10 | /// 11 | /// 同步群消息 12 | /// 13 | public class GroupSyncMessage : BaseMiraiEvent 14 | { 15 | /// 16 | /// 发送者 17 | /// 18 | public Member Subject { get; set; } = new(); 19 | 20 | /// 21 | /// 消息链 22 | /// 23 | public MessageChain MessageChain { get; set; } = new(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/MemberCardChangeEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// 群名片改动 11 | /// 12 | public class MemberCardChangeEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// 原本名片 16 | /// 17 | public string Origin { get; set; } = string.Empty; 18 | 19 | /// 20 | /// 现在名片 21 | /// 22 | public string Current { get; set; } = string.Empty; 23 | 24 | /// 25 | /// 名片改动的群员的信息 26 | /// 27 | public Member Member { get; set; } = new(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/MemberHonorChangeEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// 群员称号改变 11 | /// 12 | public class MemberHonorChangeEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// 称号发生变化的群员的信息 16 | /// 17 | public Member Member { get; set; } = new(); 18 | 19 | /// 20 | /// 称号变化行为:achieve获得称号,lose失去称号 21 | /// 22 | public string Action { get; set; } = string.Empty; 23 | 24 | /// 25 | /// 称号名称 26 | /// 27 | public string Honor { get; set; } = string.Empty; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/MemberJoinEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// 新人入群的事件 11 | /// 12 | public class MemberJoinEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// 新人信息 16 | /// 17 | public Member Member { get; set; } = new(); 18 | 19 | /// 20 | /// 如果被要求入群的话,则为邀请人的 Member 对象 21 | /// 22 | public Member? Invitor { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/MemberJoinRequestEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// 用户入群申请(Bot需要有管理员权限) 11 | /// 12 | public class MemberJoinRequestEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// 事件标识,响应该事件时的标识 16 | /// 17 | public long EventId { get; set; } 18 | 19 | /// 20 | /// 申请人QQ号 21 | /// 22 | public long FromId { get; set; } 23 | 24 | /// 25 | /// 申请人如果通过某个群添加好友,该项为该群群号;否则为0 26 | /// 27 | public long GroupId { get; set; } 28 | 29 | /// 30 | /// 申请人申请入群的群名称 31 | /// 32 | public string GroupName { get; set; } = string.Empty; 33 | 34 | /// 35 | /// 申请人的昵称或群名片 36 | /// 37 | public string Nick { get; set; } = string.Empty; 38 | 39 | /// 40 | /// 申请消息 41 | /// 42 | public string Message { get; set; } = string.Empty; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/MemberLeaveEventKick.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.Mirai.Event 8 | { 9 | /// 10 | /// 成员被踢出群(该成员不是Bot) 11 | /// 12 | public class MemberLeaveEventKick : BaseMiraiEvent 13 | { 14 | /// 15 | /// 被踢者的信息 16 | /// 17 | public Member Member { get; set; } = new(); 18 | 19 | /// 20 | /// 操作的管理员或群主信息,当null时为Bot操作 21 | /// 22 | public Member? Operator { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/MemberLeaveEventQuit.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.Mirai.Event 8 | { 9 | /// 10 | /// 成员主动离群(该成员不是Bot) 11 | /// 12 | public class MemberLeaveEventQuit : BaseMiraiEvent 13 | { 14 | /// 15 | /// 被踢者的信息 16 | /// 17 | public Member Member { get; set; } = new(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/MemberMuteEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// 群成员被禁言事件(该成员不是Bot) 11 | /// 12 | public class MemberMuteEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// 禁言时长,单位为秒 16 | /// 17 | public long DurationSeconds { get; set; } 18 | 19 | /// 20 | /// 被禁言的群员的信息 21 | /// 22 | public Member Member { get; set; } = new(); 23 | 24 | /// 25 | /// 操作者的信息,当null时为Bot操作 26 | /// 27 | public Member? Operator { get; set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/MemberPermissionChangeEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// 成员权限改变的事件(该成员不是Bot) 11 | /// 12 | public class MemberPermissionChangeEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// 原权限 16 | /// 17 | public string Origin { get; set; } = string.Empty; 18 | 19 | /// 20 | /// 现权限 21 | /// 22 | public string Current { get; set; } = string.Empty; 23 | 24 | /// 25 | /// 权限改动的群员的信息 26 | /// 27 | public Member Member { get; set; } = new(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/MemberSpecialTitleChangeEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// 群头衔改动(只有群主有操作限权) 11 | /// 12 | public class MemberSpecialTitleChangeEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// 原头衔 16 | /// 17 | public string Origin { get; set; } = string.Empty; 18 | 19 | /// 20 | /// 现头衔 21 | /// 22 | public string Current { get; set; } = string.Empty; 23 | 24 | /// 25 | /// 头衔改动的群员的信息 26 | /// 27 | public Member Member { get; set; } = new(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/MemberUnmuteEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// 群成员被取消禁言事件(该成员不是Bot) 11 | /// 12 | public class MemberUnmuteEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// 被取消禁言的群员的信息 16 | /// 17 | public Member Member { get; set; } = new(); 18 | 19 | /// 20 | /// 操作者的信息,当null时为Bot操作 21 | /// 22 | public Member? Operator { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/NewFriendRequestEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// 添加好友申请 11 | /// 12 | public class NewFriendRequestEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// 事件标识,响应该事件时的标识 16 | /// 17 | public long EventId { get; set; } 18 | 19 | /// 20 | /// 申请人QQ号 21 | /// 22 | public long FromId { get; set; } 23 | 24 | /// 25 | /// 申请人如果通过某个群添加好友,该项为该群群号;否则为0 26 | /// 27 | public long GroupId { get; set; } 28 | 29 | /// 30 | /// 申请人的昵称或群名片 31 | /// 32 | public string Nick { get; set; } = string.Empty; 33 | 34 | /// 35 | /// 申请消息 36 | /// 37 | public string Message { get; set; } = string.Empty; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/NudgeEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// 戳一戳事件 11 | /// 12 | public class NudgeEvent : BaseMiraiEvent 13 | { 14 | public class NugetSource 15 | { 16 | /// 17 | /// 来源的QQ号(好友)或群号 18 | /// 19 | public long Id { get; set; } 20 | 21 | /// 22 | /// 来源的类型,"Friend"或"Group" 23 | /// 24 | public string Kind { get; set; } = string.Empty; 25 | } 26 | 27 | /// 28 | /// 动作发出者的QQ号 29 | /// 30 | public long FromId { get; set; } 31 | 32 | /// 33 | /// 来源 34 | /// 35 | public NugetSource Subject { get; set; } = new(); 36 | 37 | /// 38 | /// 动作类型 39 | /// 40 | public string Action { get; set; } = string.Empty; 41 | 42 | /// 43 | /// 自定义动作内容 44 | /// 45 | public string Suffix { get; set; } = string.Empty; 46 | 47 | /// 48 | /// 动作目标的QQ号 49 | /// 50 | public long Target { get; set; } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/OtherClientMessage.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.Mirai.Event 9 | { 10 | /// 11 | /// 其他设备消息 12 | /// 13 | public class OtherClientMessage : BaseMiraiEvent 14 | { 15 | /// 16 | /// 其他客户端 17 | /// 18 | public Client Sender { get; set; } = new(); 19 | 20 | /// 21 | /// 消息链 22 | /// 23 | public MessageChain MessageChain { get; set; } = new(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/OtherClientOfflineEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// 其他客户端下线 11 | /// 12 | public class OtherClientOfflineEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// 其他客户端 16 | /// 17 | public Client Client { get; set; } = new(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/OtherClientOnlineEvent.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.Mirai.Event 8 | { 9 | /// 10 | /// 其他客户端上线 11 | /// 12 | public class OtherClientOnlineEvent : BaseMiraiEvent 13 | { 14 | /// 15 | /// 其他客户端 16 | /// 17 | public Client Client { get; set; } = new(); 18 | 19 | /// 20 | /// 详细设备类型 21 | /// 22 | public long? Kind { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/StrangerMessage.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.Mirai.Event 9 | { 10 | /// 11 | /// 陌生人消息 12 | /// 13 | public class StrangerMessage : BaseMiraiEvent 14 | { 15 | /// 16 | /// 发送者 17 | /// 18 | public Friend Sender { get; set; } = new(); 19 | 20 | /// 21 | /// 消息链 22 | /// 23 | public MessageChain MessageChain { get; set; } = new(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/StrangerSyncMessage.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.Mirai.Event 9 | { 10 | /// 11 | /// 同步陌生人消息 12 | /// 13 | public class StrangerSyncMessage : BaseMiraiEvent 14 | { 15 | /// 16 | /// 发送者 17 | /// 18 | public Friend Subject { get; set; } = new(); 19 | 20 | /// 21 | /// 消息链 22 | /// 23 | public MessageChain MessageChain { get; set; } = new(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/TempMessage.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.Mirai.Event 9 | { 10 | /// 11 | /// 群临时消息 12 | /// 13 | public class TempMessage : BaseMiraiEvent 14 | { 15 | /// 16 | /// 发送者 17 | /// 18 | public Member Sender { get; set; } = new(); 19 | 20 | /// 21 | /// 消息链 22 | /// 23 | public MessageChain MessageChain { get; set; } = new(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Event/TempSyncMessage.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.Mirai.Event 9 | { 10 | /// 11 | /// 同步群临时消息 12 | /// 13 | public class TempSyncMessage : BaseMiraiEvent 14 | { 15 | /// 16 | /// 发送者 17 | /// 18 | public Member Subject { get; set; } = new(); 19 | 20 | /// 21 | /// 消息链 22 | /// 23 | public MessageChain MessageChain { get; set; } = new(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Friend.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.Mirai 8 | { 9 | /// 10 | /// 好友 11 | /// 12 | public struct Friend 13 | { 14 | public Friend() 15 | { 16 | } 17 | 18 | /// 19 | /// QQ号 20 | /// 21 | public long Id { get; set; } = 0; 22 | 23 | /// 24 | /// 昵称 25 | /// 26 | public string Nickname { get; set; } = string.Empty; 27 | 28 | /// 29 | /// 备注 30 | /// 31 | public string Remark { get; set; } = string.Empty; 32 | 33 | public string GetFormatedName() 34 | { 35 | return $"{Nickname}({Id})"; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Group.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.Mirai 8 | { 9 | /// 10 | /// 群组 11 | /// 12 | public struct Group 13 | { 14 | public Group() 15 | { 16 | } 17 | 18 | /// 19 | /// 群号 20 | /// 21 | public long Id { get; set; } = 0; 22 | 23 | /// 24 | /// 群名称 25 | /// 26 | public string Name { get; set; } = string.Empty; 27 | 28 | /// 29 | /// Bot在群内的权限 30 | /// 31 | public string Permission { get; set; } = string.Empty; 32 | 33 | public string GetFormatedName() 34 | { 35 | return $"[{Name}({Id})]"; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Member.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.Mirai 8 | { 9 | /// 10 | /// 群成员 11 | /// 12 | public struct Member 13 | { 14 | public Member() 15 | { 16 | } 17 | 18 | /// 19 | /// 成员QQ Id 20 | /// 21 | public long Id { get; set; } = 0; 22 | 23 | /// 24 | /// 成员名称 25 | /// 26 | public string MemberName { get; set; } = string.Empty; 27 | 28 | /// 29 | /// 成员头衔 30 | /// 31 | public string SpecialTitle { get; set; } = string.Empty; 32 | 33 | /// 34 | /// 成员群内权限 35 | /// 36 | public string Permission { get; set; } = string.Empty; 37 | 38 | /// 39 | /// 加入时间 40 | /// 41 | public int JoinTimestamp { get; set; } = 0; 42 | 43 | /// 44 | /// 上次发言时间 45 | /// 46 | public int LastSpeakTimestamp { get; set; } = 0; 47 | 48 | /// 49 | /// 禁言剩余时间 50 | /// 51 | public int MuteTimeRemaining { get; set; } = 0; 52 | 53 | /// 54 | /// 所在群组 55 | /// 56 | public Group Group { get; set; } = new(); 57 | 58 | public string GetFormatedName() 59 | { 60 | return $"{Group.GetFormatedName()} {MemberName}({Id})"; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Message/App.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.Mirai.Message 9 | { 10 | /// 11 | /// App消息 12 | /// 13 | public class App : BaseChain 14 | { 15 | /// 16 | /// App 17 | /// 18 | public string Content { get; set; } = string.Empty; 19 | 20 | public override int GetHashCode() 21 | { 22 | return Content.GetHashCode(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Message/At.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection.Metadata; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace WanBot.Api.Mirai.Message 9 | { 10 | /// 11 | /// At 12 | /// 13 | public class At : BaseChain 14 | { 15 | /// 16 | /// 群员QQ号 17 | /// 18 | public long Target { get; set; } = 0; 19 | 20 | /// 21 | /// At时显示的文字,发送消息时无效,自动使用群名片 22 | /// 23 | public string Display { get; set; } = string.Empty; 24 | 25 | public override int GetHashCode() 26 | { 27 | return Target.GetHashCode(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Message/AtAll.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection.Metadata; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace WanBot.Api.Mirai.Message 9 | { 10 | /// 11 | /// AtAll 12 | /// 13 | public class AtAll : BaseChain 14 | { 15 | public override int GetHashCode() 16 | { 17 | return 0; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Message/BaseChain.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 | using WanBot.Api.Util; 8 | 9 | namespace WanBot.Api.Mirai.Message 10 | { 11 | [JsonDerivedType(typeof(App), nameof(App))] 12 | [JsonDerivedType(typeof(At), nameof(At))] 13 | [JsonDerivedType(typeof(AtAll), nameof(AtAll))] 14 | [JsonDerivedType(typeof(BaseChain), nameof(BaseChain))] 15 | [JsonDerivedType(typeof(Dice), nameof(Dice))] 16 | [JsonDerivedType(typeof(Face), nameof(Face))] 17 | [JsonDerivedType(typeof(File), nameof(File))] 18 | [JsonDerivedType(typeof(FlashImage), nameof(FlashImage))] 19 | [JsonDerivedType(typeof(Forward), nameof(Forward))] 20 | [JsonDerivedType(typeof(Image), nameof(Image))] 21 | [JsonDerivedType(typeof(Json), nameof(Json))] 22 | [JsonDerivedType(typeof(MarketFace), nameof(MarketFace))] 23 | [JsonDerivedType(typeof(MiraiCode), nameof(MiraiCode))] 24 | [JsonDerivedType(typeof(MusicShare), nameof(MusicShare))] 25 | [JsonDerivedType(typeof(Plain), nameof(Plain))] 26 | [JsonDerivedType(typeof(Poke), nameof(Poke))] 27 | [JsonDerivedType(typeof(Quote), nameof(Quote))] 28 | [JsonDerivedType(typeof(Source), nameof(Source))] 29 | [JsonDerivedType(typeof(Voice), nameof(Voice))] 30 | [JsonDerivedType(typeof(Xml), nameof(Xml))] 31 | [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] 32 | public class BaseChain 33 | { 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Message/Dice.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection.Metadata; 5 | using System.Text; 6 | using System.Text.Json.Serialization; 7 | using System.Threading.Tasks; 8 | 9 | namespace WanBot.Api.Mirai.Message 10 | { 11 | /// 12 | /// 骰子 13 | /// 14 | public class Dice : BaseChain 15 | { 16 | /// 17 | /// 点数 18 | /// 19 | public int Value { get; set; } 20 | 21 | public override int GetHashCode() 22 | { 23 | return Value; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Message/Face.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection.Metadata; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace WanBot.Api.Mirai.Message 9 | { 10 | /// 11 | /// 表情消息 12 | /// 13 | public class Face : BaseChain 14 | { 15 | /// 16 | /// QQ表情编号,可选,优先高于name 17 | /// 18 | public int FaceId { get; set; } 19 | 20 | /// 21 | /// QQ表情拼音,可选 22 | /// 23 | public string? Name { get; set; } = null; 24 | 25 | public override int GetHashCode() 26 | { 27 | return FaceId.GetHashCode(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Message/File.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection.Metadata; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace WanBot.Api.Mirai.Message 9 | { 10 | /// 11 | /// 文件消息 12 | /// 13 | public class File : BaseChain 14 | { 15 | /// 16 | /// 文件识别id 17 | /// 18 | public string Id { get; set; } = string.Empty; 19 | 20 | /// 21 | /// 文件名 22 | /// 23 | public string Name { get; set; } = string.Empty; 24 | 25 | /// 26 | /// 文件大小 27 | /// 28 | public long Size { get; set; } 29 | 30 | public override int GetHashCode() 31 | { 32 | return Id.GetHashCode(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Message/FlashImage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection.Metadata; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace WanBot.Api.Mirai.Message 9 | { 10 | /// 11 | /// 闪照消息,三个参数任选其一,出现多个参数时,按照imageId > url > path > base64的优先级 12 | /// 13 | public class FlashImage : BaseChain 14 | { 15 | /// 16 | /// 图片的imageId,群图片与好友图片格式不同。不为空时将忽略url属性 17 | /// 18 | public string? ImageId { get; set; } = null; 19 | 20 | /// 21 | /// 图片的URL,发送时可作网络图片的链接;接收时为腾讯图片服务器的链接,可用于图片下载 22 | /// 23 | public string? Url { get; set; } = null; 24 | 25 | /// 26 | /// 图片的路径,发送本地图片,路径相对于 JVM 工作路径(默认是当前路径,可通过 -Duser.dir=...指定),也可传入绝对路径。 27 | /// 28 | public string? Path { get; set; } = null; 29 | 30 | /// 31 | /// 图片的 Base64 编码 32 | /// 33 | public string? Base64 { get; set; } = null; 34 | 35 | public override int GetHashCode() 36 | { 37 | return 38 | ImageId?.GetHashCode() ?? 39 | Url?.GetHashCode() ?? 40 | Path?.GetHashCode() ?? 41 | Base64?.GetHashCode() ?? 0; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Message/Forward.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Buffers.Text; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using static System.Net.Mime.MediaTypeNames; 8 | 9 | namespace WanBot.Api.Mirai.Message 10 | { 11 | /// 12 | /// 转发消息 13 | /// 14 | public class Forward : BaseChain 15 | { 16 | /// 17 | /// 消息节点 18 | /// 19 | public class ForwardNode 20 | { 21 | /// 22 | /// 发送人QQ号 23 | /// 24 | public long SenderId { get; set; } 25 | 26 | /// 27 | /// 发送时间 28 | /// 29 | public int Time { get; set; } 30 | 31 | /// 32 | /// 显示名称 33 | /// 34 | public string SenderName { get; set; } = string.Empty; 35 | 36 | /// 37 | /// 消息链 38 | /// 39 | public MessageChain? MessageChain { get; set; } 40 | 41 | /// 42 | /// 可以只使用消息messageId,从缓存中读取一条消息作为节点 43 | /// 44 | public int? MessageId { get; set; } 45 | 46 | public override int GetHashCode() 47 | { 48 | return 49 | SenderId.GetHashCode() ^ 50 | Time.GetHashCode() ^ 51 | MessageId.GetHashCode() ^ 52 | (MessageChain?.GetHashCode() ?? 0); 53 | } 54 | } 55 | 56 | /// 57 | /// 消息节点 58 | /// 59 | public List? NodeList { get; set; } = null; 60 | 61 | public override int GetHashCode() 62 | { 63 | var hashCode = 0; 64 | if (NodeList != null) 65 | foreach (var node in NodeList) 66 | hashCode ^= node.GetHashCode(); 67 | return hashCode; 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Message/Image.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.Mirai.Message 8 | { 9 | /// 10 | /// 图像消息,三个参数任选其一,出现多个参数时,按照imageId > url > path > base64的优先级 11 | /// 12 | public class Image : BaseChain 13 | { 14 | /// 15 | /// 图片的imageId,群图片与好友图片格式不同。不为空时将忽略url属性 16 | /// 17 | public string? ImageId { get; set; } = null; 18 | 19 | /// 20 | /// 图片的URL,发送时可作网络图片的链接;接收时为腾讯图片服务器的链接,可用于图片下载 21 | /// 22 | public string? Url { get; set; } = null; 23 | 24 | /// 25 | /// 图片的路径,发送本地图片,路径相对于 JVM 工作路径(默认是当前路径,可通过 -Duser.dir=...指定),也可传入绝对路径。 26 | /// 27 | public string? Path { get; set; } = null; 28 | 29 | /// 30 | /// 图片的 Base64 编码 31 | /// 32 | public string? Base64 { get; set; } = null; 33 | 34 | public override int GetHashCode() 35 | { 36 | return 37 | ImageId?.GetHashCode() ?? 38 | Url?.GetHashCode() ?? 39 | Path?.GetHashCode() ?? 40 | Base64?.GetHashCode() ?? 0; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Message/Json.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Buffers.Text; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Text.Json.Serialization; 7 | using System.Threading.Tasks; 8 | using static System.Net.Mime.MediaTypeNames; 9 | 10 | namespace WanBot.Api.Mirai.Message 11 | { 12 | /// 13 | /// Json消息 14 | /// 15 | public class Json : BaseChain 16 | { 17 | /// 18 | /// Json 19 | /// 20 | [JsonPropertyName("json")] 21 | public string Content { get; set; } = string.Empty; 22 | 23 | public override int GetHashCode() 24 | { 25 | return Content.GetHashCode(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Message/MarketFace.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection.Metadata; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace WanBot.Api.Mirai.Message 9 | { 10 | /// 11 | /// 商城表情消息,目前商城表情仅支持接收和转发,不支持构造发送 12 | /// 13 | public class MarketFace : BaseChain 14 | { 15 | /// 16 | /// 商城表情唯一标识 17 | /// 18 | public int Id { get; set; } 19 | 20 | /// 21 | /// 表情显示名称 22 | /// 23 | public string? Name { get; set; } = null; 24 | 25 | public override int GetHashCode() 26 | { 27 | return Id; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Message/MessageChain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Text.Json.Serialization; 7 | using System.Threading.Tasks; 8 | using WanBot.Api.Util; 9 | 10 | namespace WanBot.Api.Mirai.Message 11 | { 12 | /// 13 | /// 消息链 14 | /// 15 | [JsonConverter(typeof(MessageChainJsonConverter))] 16 | public class MessageChain : IEnumerable 17 | { 18 | /// 19 | /// 消息Id 20 | /// 21 | public int? MessageId 22 | { 23 | get 24 | { 25 | if (Chain.FirstOrDefault() is Source source) 26 | return source.Id; 27 | return null; 28 | } 29 | } 30 | 31 | internal IEnumerable Chain { get; } 32 | 33 | public MessageChain(IEnumerable chain) 34 | { 35 | Chain = chain.ToArray(); 36 | } 37 | 38 | public MessageChain() 39 | { 40 | Chain = Array.Empty(); 41 | } 42 | 43 | public IEnumerator GetEnumerator() 44 | { 45 | return Chain.GetEnumerator(); 46 | } 47 | 48 | IEnumerator IEnumerable.GetEnumerator() 49 | { 50 | return Chain.GetEnumerator(); 51 | } 52 | 53 | public override int GetHashCode() 54 | { 55 | var hashCode = 0; 56 | if (Chain != null) 57 | foreach (var node in Chain) 58 | hashCode ^= node.GetHashCode(); 59 | return hashCode; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Message/MiraiCode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection.Metadata; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace WanBot.Api.Mirai.Message 9 | { 10 | /// 11 | /// Mirai Code 12 | /// 13 | public class MiraiCode : BaseChain 14 | { 15 | /// 16 | /// Mirai Code 17 | /// 18 | public string Code { get; set; } = string.Empty; 19 | 20 | public override int GetHashCode() 21 | { 22 | return Code.GetHashCode(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Message/MusicShare.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using static WanBot.Api.Mirai.Message.Forward; 7 | 8 | namespace WanBot.Api.Mirai.Message 9 | { 10 | /// 11 | /// 音乐分享 12 | /// 13 | public class MusicShare : BaseChain 14 | { 15 | /// 16 | /// 类型 17 | /// 18 | public string Kind { get; set; } = string.Empty; 19 | 20 | /// 21 | /// 标题 22 | /// 23 | public string Title { get; set; } = string.Empty; 24 | 25 | /// 26 | /// 概括 27 | /// 28 | public string Summary { get; set; } = string.Empty; 29 | 30 | /// 31 | /// 跳转路径 32 | /// 33 | public string JumpUrl { get; set; } = string.Empty; 34 | 35 | /// 36 | /// 封面路径 37 | /// 38 | public string PictureUrl { get; set; } = string.Empty; 39 | 40 | /// 41 | /// 音源路径 42 | /// 43 | public string MusicUrl { get; set; } = string.Empty; 44 | 45 | /// 46 | /// 简介 47 | /// 48 | public string Brief { get; set; } = string.Empty; 49 | 50 | public override int GetHashCode() 51 | { 52 | return 53 | Kind.GetHashCode() ^ 54 | Title.GetHashCode() ^ 55 | Summary.GetHashCode() ^ 56 | JumpUrl.GetHashCode() ^ 57 | PictureUrl.GetHashCode() ^ 58 | Brief.GetHashCode(); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Message/Plain.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.Mirai.Message 8 | { 9 | /// 10 | /// 文本消息 11 | /// 12 | public class Plain : BaseChain 13 | { 14 | /// 15 | /// 文字消息 16 | /// 17 | public string Text { get; set; } = string.Empty; 18 | 19 | public override int GetHashCode() 20 | { 21 | return Text.GetHashCode(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Message/Poke.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 | using static System.Net.Mime.MediaTypeNames; 8 | 9 | namespace WanBot.Api.Mirai.Message 10 | { 11 | /// 12 | /// 戳一戳消息 13 | /// 14 | public class Poke : BaseChain 15 | { 16 | /// 17 | /// 戳一戳的类型 18 | /// 19 | public string Name { get; set; } = string.Empty; 20 | 21 | public override int GetHashCode() 22 | { 23 | return Name.GetHashCode(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Message/Quote.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Xml.Linq; 7 | 8 | namespace WanBot.Api.Mirai.Message 9 | { 10 | /// 11 | /// 引用回复消息 12 | /// 13 | public class Quote : BaseChain 14 | { 15 | /// 16 | /// 被引用回复的原消息的messageId 17 | /// 18 | public int Id { get; set; } = 0; 19 | 20 | /// 21 | /// 被引用回复的原消息所接收的群号,当为好友消息时为0 22 | /// 23 | public long GroupId { get; set; } = 0; 24 | 25 | /// 26 | /// 被引用回复的原消息的发送者的QQ号 27 | /// 28 | public long SenderId { get; set; } = 0; 29 | 30 | /// 31 | /// 被引用回复的原消息的接收者者的QQ号(或群号) 32 | /// 33 | public long TargetId { get; set; } = 0; 34 | 35 | /// 36 | /// 被引用回复的原消息的消息链对象 37 | /// 38 | public MessageChain? Origin { get; set; } = null; 39 | 40 | public override int GetHashCode() 41 | { 42 | return 43 | Id.GetHashCode() ^ 44 | GroupId.GetHashCode() ^ 45 | SenderId.GetHashCode() ^ 46 | TargetId.GetHashCode() ^ 47 | (Origin?.GetHashCode() ?? 0); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Message/Source.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.Mirai.Message 9 | { 10 | /// 11 | /// 消息源 12 | /// 13 | public class Source : BaseChain 14 | { 15 | /// 16 | /// 消息的识别号,用于引用回复(Source类型永远为chain的第一个元素) 17 | /// 18 | public int Id { get; set; } = 0; 19 | 20 | /// 21 | /// 时间戳 22 | /// 23 | public int Time { get; set; } = 0; 24 | 25 | public override int GetHashCode() 26 | { 27 | return 28 | Id.GetHashCode() ^ 29 | Time.GetHashCode(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Message/Voice.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using static System.Net.Mime.MediaTypeNames; 7 | 8 | namespace WanBot.Api.Mirai.Message 9 | { 10 | /// 11 | /// 图像消息,三个参数任选其一,出现多个参数时,按照imageId > url > path > base64的优先级 12 | /// 13 | public class Voice : BaseChain 14 | { 15 | /// 16 | /// 语音的imageId,群图片与好友图片格式不同。不为空时将忽略url属性 17 | /// 18 | public string? VoiceId { get; set; } = null; 19 | 20 | /// 21 | /// 语音的URL,发送时可作网络图片的链接;接收时为腾讯图片服务器的链接,可用于图片下载 22 | /// 23 | public string? Url { get; set; } = null; 24 | 25 | /// 26 | /// 语音的路径,发送本地图片,路径相对于 JVM 工作路径(默认是当前路径,可通过 -Duser.dir=...指定),也可传入绝对路径。 27 | /// 28 | public string? Path { get; set; } = null; 29 | 30 | /// 31 | /// 语音的 Base64 编码 32 | /// 33 | public string? Base64 { get; set; } = null; 34 | 35 | /// 36 | /// 返回的语音长度, 发送消息时可以不传 37 | /// 38 | public long Length { get; set; } 39 | 40 | public override int GetHashCode() 41 | { 42 | return 43 | VoiceId?.GetHashCode() ?? 44 | Url?.GetHashCode() ?? 45 | Path?.GetHashCode() ?? 46 | Base64?.GetHashCode() ?? 47 | Length.GetHashCode(); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Message/Xml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Buffers.Text; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Text.Json.Serialization; 7 | using System.Threading.Tasks; 8 | 9 | namespace WanBot.Api.Mirai.Message 10 | { 11 | /// 12 | /// Xml消息 13 | /// 14 | public class Xml : BaseChain 15 | { 16 | /// 17 | /// Xml 18 | /// 19 | [JsonPropertyName("xml")] 20 | public string Content { get; set; } = string.Empty; 21 | 22 | public override int GetHashCode() 23 | { 24 | return Content.GetHashCode(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/MiraiBotException.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.Mirai 9 | { 10 | /// 11 | /// MiraiBot报错 12 | /// 13 | public class MiraiBotEventException : Exception 14 | { 15 | public string Payload { get; } 16 | 17 | public BaseMiraiEvent Event { get; } 18 | 19 | public MiraiBot Bot { get; } 20 | public MiraiBotEventException(MiraiBot bot, string payload, string message, BaseMiraiEvent e, Exception inner) 21 | : base(message, inner) 22 | { 23 | Payload = payload; 24 | Event = e; 25 | Bot = bot; 26 | } 27 | 28 | public override string ToString() 29 | { 30 | var msg = $"{base.ToString()}\nPayload: {Payload}"; 31 | return msg.Replace(Bot.SessionKey, new string('*', Bot.SessionKey.Length)); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/MiraiConfig.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.Mirai 8 | { 9 | /// 10 | /// Mirai配置 11 | /// 12 | public class MiraiConfig 13 | { 14 | /// 15 | /// 绑定的QQ号 16 | /// 17 | public long QQ { get; set; } = 123456789; 18 | 19 | /// 20 | /// host 21 | /// 22 | public string Host { get; set; } = "localhost"; 23 | 24 | /// 25 | /// 端口 26 | /// 27 | public ushort Port { get; set; } = 8080; 28 | 29 | /// 30 | /// 事件同步Id 31 | /// 32 | public string EventSyncId { get; set; } = "-1"; 33 | 34 | /// 35 | /// 验证Key 36 | /// 37 | public string VerifyKey { get; set; } = "YourVerifyKey"; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Network/Request.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.Mirai.Network 8 | { 9 | public abstract class Request : IRequest 10 | { 11 | } 12 | 13 | public interface IRequest 14 | { 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Network/Response.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.Mirai.Network 8 | { 9 | public class WsAdapterResponse : WsAdapterResponse 10 | { 11 | public T? Data { get; set; } 12 | } 13 | 14 | public class WsAdapterResponse 15 | { 16 | public string SyncId { get; set; } = string.Empty; 17 | } 18 | 19 | public class Response : Response 20 | { 21 | public ResponseContent? Data { get; set; } 22 | } 23 | 24 | public abstract class Response : IResponse 25 | { 26 | public int Code { get; set; } = -1; 27 | public string Msg { get; set; } = string.Empty; 28 | } 29 | 30 | public interface IResponse 31 | { 32 | } 33 | 34 | /// 35 | /// 响应码 36 | /// 37 | public static class ResponseCode 38 | { 39 | private static Dictionary _responseDict = new() 40 | { 41 | { 0, "正常" }, 42 | { 1, "错误的verify key" }, 43 | { 2, "指定的Bot不存在" }, 44 | { 3, "Session失效或不存在" }, 45 | { 4, "Session未认证(未激活)" }, 46 | { 5, "发送消息目标不存在(指定对象不存在)" }, 47 | { 6, "指定文件不存在,出现于发送本地图片" }, 48 | { 10, "无操作权限,指Bot没有对应操作的限权" }, 49 | { 20, "Bot被禁言,指Bot当前无法向指定群发送消息" }, 50 | { 30, "消息过长" }, 51 | { 400, "错误的访问,如参数错误等" } 52 | }; 53 | 54 | /// 55 | /// 正常 56 | /// 57 | public const int Ok = 0; 58 | 59 | /// 60 | /// 原因 61 | /// 62 | /// 63 | /// 64 | public static string Reason(int id) 65 | { 66 | if (_responseDict.TryGetValue(id, out var reason)) 67 | return reason; 68 | return "未知错误"; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Network/WsAdapterRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using WanBot.Api.Mirai.Adapter; 8 | 9 | namespace WanBot.Api.Mirai.Network 10 | { 11 | /// 12 | /// Ws适配器请求 13 | /// 14 | /// 15 | internal class WsAdapterRequest 16 | { 17 | private static string _command { get; set; } 18 | private static string _subCommand { get; set; } 19 | 20 | static WsAdapterRequest() 21 | { 22 | var apiAttr = typeof(T).GetCustomAttribute(); 23 | 24 | if (apiAttr == null) 25 | throw new Exception($"{typeof(T)} is not a ws api payload"); 26 | 27 | _command = apiAttr.Command; 28 | _subCommand = apiAttr.SubCommand; 29 | } 30 | 31 | public string SyncId { get; set; } 32 | public string Command => _command; 33 | public string SubCommand => _subCommand; 34 | public T? Content { get; set; } 35 | 36 | public WsAdapterRequest(string syncId, T? content) 37 | { 38 | SyncId = syncId; 39 | Content = content; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Payload/About.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.Adapter; 7 | using WanBot.Api.Mirai.Network; 8 | 9 | namespace WanBot.Api.Mirai.Payload 10 | { 11 | [HttpApi("about")] 12 | [WsApi("about")] 13 | public class AboutRequest : Request 14 | { 15 | } 16 | 17 | public class AboutResponse : Response 18 | { 19 | } 20 | 21 | public class AboutResponseContent 22 | { 23 | public string Version { get; set; } = string.Empty; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Payload/BotProfile.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.Adapter; 7 | using WanBot.Api.Mirai.Network; 8 | 9 | namespace WanBot.Api.Mirai.Payload 10 | { 11 | [HttpApi("botProfile")] 12 | [WsApi("botProfile")] 13 | public class BotProfileRequest : Request 14 | { 15 | public string SessionKey { get; set; } = string.Empty; 16 | } 17 | 18 | public class BotProfileResponse : Profile, IResponse 19 | { 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Payload/FriendList.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.Adapter; 7 | using WanBot.Api.Mirai.Network; 8 | 9 | namespace WanBot.Api.Mirai.Payload 10 | { 11 | [HttpApi("friendList")] 12 | [WsApi("friendList")] 13 | public class FriendListRequest : Request 14 | { 15 | public string SessionKey { get; set; } = string.Empty; 16 | } 17 | 18 | public class FriendListResponse : Response> 19 | { 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Payload/FriendProfile.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.Adapter; 7 | using WanBot.Api.Mirai.Network; 8 | 9 | namespace WanBot.Api.Mirai.Payload 10 | { 11 | [HttpApi("friendProfile")] 12 | [WsApi("friendProfile")] 13 | public class FriendProfileRequest : Request 14 | { 15 | public string SessionKey { get; set; } = string.Empty; 16 | public long Target { get; set; } 17 | } 18 | 19 | public class FriendProfileResponse : Profile, IResponse 20 | { 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Payload/GroupList.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.Adapter; 7 | using WanBot.Api.Mirai.Network; 8 | 9 | namespace WanBot.Api.Mirai.Payload 10 | { 11 | [HttpApi("groupList")] 12 | [WsApi("groupList")] 13 | public class GroupListRequest : Request 14 | { 15 | public string SessionKey { get; set; } = string.Empty; 16 | } 17 | 18 | public class GroupListResponse : Response> 19 | { 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Payload/MemberList.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.Adapter; 7 | using WanBot.Api.Mirai.Network; 8 | 9 | namespace WanBot.Api.Mirai.Payload 10 | { 11 | [HttpApi("memberList")] 12 | [WsApi("memberList")] 13 | public class MemberListRequest : Request 14 | { 15 | public string SessionKey { get; set; } = string.Empty; 16 | public long Target { get; set; } 17 | } 18 | 19 | public class MemberListResponse : Response> 20 | { 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Payload/MemberProfile.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.Adapter; 7 | using WanBot.Api.Mirai.Network; 8 | 9 | namespace WanBot.Api.Mirai.Payload 10 | { 11 | [HttpApi("memberProfile")] 12 | [WsApi("memberProfile")] 13 | public class MemberProfileRequest : Request 14 | { 15 | public string SessionKey { get; set; } = string.Empty; 16 | public long Target { get; set; } 17 | public long MemberId { get; set; } 18 | } 19 | 20 | public class MemberProfileResponse : Profile, IResponse 21 | { 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Payload/MessageFromId.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.Adapter; 7 | using WanBot.Api.Mirai.Event; 8 | using WanBot.Api.Mirai.Message; 9 | using WanBot.Api.Mirai.Network; 10 | 11 | namespace WanBot.Api.Mirai.Payload 12 | { 13 | [HttpApi("messageFromId")] 14 | [WsApi("messageFromId")] 15 | public class MessageFromIdRequest : Request 16 | { 17 | public string SessionKey { get; set; } = string.Empty; 18 | 19 | public int Id { get; set; } 20 | } 21 | 22 | public class MessageFromIdResponse : Response 23 | { 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Payload/Quit.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.Adapter; 7 | using WanBot.Api.Mirai.Network; 8 | 9 | namespace WanBot.Api.Mirai.Payload 10 | { 11 | [HttpApi("quit", HttpAdapterMethod.PostJson)] 12 | [WsApi("quit")] 13 | public class QuitRequest : Request 14 | { 15 | public string SessionKey { get; set; } = string.Empty; 16 | public long Target { get; set; } 17 | } 18 | 19 | public class QuitResponse : Response 20 | { 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Payload/Recall.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.Adapter; 7 | using WanBot.Api.Mirai.Message; 8 | using WanBot.Api.Mirai.Network; 9 | 10 | namespace WanBot.Api.Mirai.Payload 11 | { 12 | /// 13 | /// 撤回 14 | /// 15 | [HttpApi("recall", HttpAdapterMethod.PostJson)] 16 | [WsApi("recall")] 17 | public class RecallRequest : Request 18 | { 19 | /// 20 | /// 已经激活的Session 21 | /// 22 | public string SessionKey { get; set; } = string.Empty; 23 | 24 | /// 25 | /// 需要撤回的消息的messageId 26 | /// 27 | public int Target { get; set; } 28 | } 29 | 30 | public class RecallResponse : Response 31 | { 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Payload/ResponseBotInvitedJoinGroupRequestEvent.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.Adapter; 7 | using WanBot.Api.Mirai.Network; 8 | 9 | namespace WanBot.Api.Mirai.Payload 10 | { 11 | /// 12 | /// 撤回 13 | /// 14 | [HttpApi("resp/botInvitedJoinGroupRequestEvent", HttpAdapterMethod.PostJson)] 15 | [WsApi("resp_botInvitedJoinGroupRequestEvent")] 16 | public class ResponseBotInvitedJoinGroupRequestEventRequest : Request 17 | { 18 | /// 19 | /// 已经激活的Session 20 | /// 21 | public string SessionKey { get; set; } = string.Empty; 22 | 23 | /// 24 | /// 事件标识 25 | /// 26 | public long EventId { get; set; } 27 | 28 | /// 29 | /// 邀请人(好友)的QQ号 30 | /// 31 | public long FromId { get; set; } 32 | 33 | /// 34 | /// 被邀请进入群的群号 35 | /// 36 | public long GroupId { get; set; } 37 | 38 | /// 39 | /// 响应的操作类型 40 | /// 41 | public int Operate { get; set; } 42 | 43 | /// 44 | /// 回复的信息 45 | /// 46 | public string Message { get; set; } = string.Empty; 47 | } 48 | 49 | public class ResponseBotInvitedJoinGroupRequestEventResponse : Response 50 | { 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Payload/SendFriendMessage.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.Adapter; 7 | using WanBot.Api.Mirai.Message; 8 | using WanBot.Api.Mirai.Network; 9 | 10 | namespace WanBot.Api.Mirai.Payload 11 | { 12 | /// 13 | /// 发送好友消息 14 | /// 15 | [HttpApi("sendFriendMessage", HttpAdapterMethod.PostJson)] 16 | [WsApi("sendFriendMessage")] 17 | public class SendFriendMessageRequest : Request 18 | { 19 | /// 20 | /// 已经激活的Session 21 | /// 22 | public string SessionKey { get; set; } = string.Empty; 23 | 24 | /// 25 | /// 发送消息目标好友的QQ号 26 | /// 27 | public long Target { get; set; } 28 | 29 | /// 30 | /// 引用一条消息的messageId进行回复 31 | /// 32 | public int? Quote { get; set; } 33 | 34 | public MessageChain? MessageChain { get; set; } 35 | } 36 | 37 | public class SendFriendMessageResponse : Response 38 | { 39 | public int MessageId { get; set; } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Payload/SendGroupMessage.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.Adapter; 7 | using WanBot.Api.Mirai.Message; 8 | using WanBot.Api.Mirai.Network; 9 | 10 | namespace WanBot.Api.Mirai.Payload 11 | { 12 | /// 13 | /// 发送群消息 14 | /// 15 | [HttpApi("sendGroupMessage", HttpAdapterMethod.PostJson)] 16 | [WsApi("sendGroupMessage")] 17 | public class SendGroupMessageRequest : Request 18 | { 19 | /// 20 | /// 已经激活的Session 21 | /// 22 | public string SessionKey { get; set; } = string.Empty; 23 | 24 | /// 25 | /// 发送消息目标群的群号 26 | /// 27 | public long Target { get; set; } 28 | 29 | /// 30 | /// 引用一条消息的messageId进行回复 31 | /// 32 | public int? Quote { get; set; } 33 | 34 | public MessageChain? MessageChain { get; set; } 35 | } 36 | 37 | public class SendGroupMessageResponse : Response 38 | { 39 | public int MessageId { get; set; } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Payload/SendNudge.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.Adapter; 7 | using WanBot.Api.Mirai.Message; 8 | using WanBot.Api.Mirai.Network; 9 | 10 | namespace WanBot.Api.Mirai.Payload 11 | { 12 | /// 13 | /// 发送群消息 14 | /// 15 | [HttpApi("sendNudge", HttpAdapterMethod.PostJson)] 16 | [WsApi("sendNudge")] 17 | public class SendNudgeRequest : Request 18 | { 19 | /// 20 | /// 已经激活的Session 21 | /// 22 | public string SessionKey { get; set; } = string.Empty; 23 | 24 | /// 25 | /// 戳一戳的目标, QQ号, 可以为 bot QQ号 26 | /// 27 | public long Target { get; set; } 28 | 29 | /// 30 | /// 戳一戳接受主体(上下文), 戳一戳信息会发送至该主体, 为群号/好友QQ号 31 | /// 32 | public long Subject { get; set; } 33 | 34 | /// 35 | /// 上下文类型, 可选值 Friend, Group, Stranger 36 | /// 37 | public string Kind { get; set; } = string.Empty; 38 | } 39 | 40 | public class SendNudgeResponse : Response 41 | { 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Payload/SendTempMessage.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.Adapter; 7 | using WanBot.Api.Mirai.Message; 8 | using WanBot.Api.Mirai.Network; 9 | 10 | namespace WanBot.Api.Mirai.Payload 11 | { 12 | /// 13 | /// 发送好友消息 14 | /// 15 | [HttpApi("sendTempMessage", HttpAdapterMethod.PostJson)] 16 | [WsApi("sendTempMessage")] 17 | public class SendTempMessageRequest : Request 18 | { 19 | /// 20 | /// 已经激活的Session 21 | /// 22 | public string SessionKey { get; set; } = string.Empty; 23 | 24 | /// 25 | /// 临时会话对象QQ号 26 | /// 27 | public long QQ { get; set; } 28 | 29 | /// 30 | /// 临时会话群号 31 | /// 32 | public long Group { get; set; } 33 | 34 | /// 35 | /// 引用一条消息的messageId进行回复 36 | /// 37 | public int? Quote { get; set; } 38 | 39 | public MessageChain? MessageChain { get; set; } 40 | } 41 | 42 | public class SendTempMessageResponse : Response 43 | { 44 | public int MessageId { get; set; } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Payload/UploadImage.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.Adapter; 7 | using WanBot.Api.Mirai.Network; 8 | 9 | namespace WanBot.Api.Mirai.Payload 10 | { 11 | [HttpApi("uploadImage", HttpAdapterMethod.PostMultipart)] 12 | public class UploadImageRequest : Request 13 | { 14 | public string SessionKey { get; set; } = string.Empty; 15 | 16 | /// 17 | /// friend或group或temp 18 | /// 19 | public string Type { get; set; } = string.Empty; 20 | 21 | public Stream Img { get; set; } = null!; 22 | } 23 | 24 | public class UploadImageResponse : IResponse 25 | { 26 | public string ImageId { get; set; } = string.Empty; 27 | 28 | public string Url { get; set; } = string.Empty; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Payload/UserProfile.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.Adapter; 7 | using WanBot.Api.Mirai.Network; 8 | 9 | namespace WanBot.Api.Mirai.Payload 10 | { 11 | [HttpApi("userProfile")] 12 | [WsApi("userProfile")] 13 | public class UserProfileRequest : Request 14 | { 15 | public string SessionKey { get; set; } = string.Empty; 16 | public long Target { get; set; } 17 | } 18 | 19 | public class UserProfileResponse : Profile, IResponse 20 | { 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Payload/Verify.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.Adapter; 7 | using WanBot.Api.Mirai.Network; 8 | 9 | namespace WanBot.Api.Mirai.Payload 10 | { 11 | [HttpApi("verify")] 12 | public class VerifyRequest : Request 13 | { 14 | public int Code { get; set; } 15 | public string Session { get; set; } = string.Empty; 16 | } 17 | 18 | public class VerifyResponse : IResponse 19 | { 20 | public int Code { get; set; } 21 | public string Session { get; set; } = string.Empty; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /WanBot.Api/Mirai/Profile.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.Mirai 8 | { 9 | public class Profile 10 | { 11 | public string Nickname { get; set; } = string.Empty; 12 | public string Email { get; set; } = string.Empty; 13 | public int Age { get; set; } 14 | public int Level { get; set; } 15 | public string Sign { get; set; } = string.Empty; 16 | public string Sex { get; set; } = string.Empty; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /WanBot.Api/Util/MessageChainJsonConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Text.Json; 7 | using System.Text.Json.Serialization; 8 | using System.Threading.Tasks; 9 | using WanBot.Api.Mirai.Message; 10 | 11 | namespace WanBot.Api.Util 12 | { 13 | /// 14 | /// 消息链序列化 15 | /// 16 | internal class MessageChainJsonConverter : JsonConverter 17 | { 18 | public override MessageChain? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) 19 | { 20 | var messageChainArray = JsonSerializer.Deserialize>(ref reader, options); 21 | if (messageChainArray == null) 22 | return null; 23 | return new MessageChain(messageChainArray); 24 | } 25 | 26 | public override void Write(Utf8JsonWriter writer, MessageChain value, JsonSerializerOptions options) 27 | { 28 | JsonSerializer.Serialize(writer, value.Chain, options); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /WanBot.Api/Util/MiraiJsonContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Text.Json.Serialization; 7 | using System.Threading.Tasks; 8 | using WanBot.Api.Mirai; 9 | using WanBot.Api.Mirai.Event; 10 | using WanBot.Api.Mirai.Message; 11 | using WanBot.Api.Mirai.Network; 12 | 13 | namespace WanBot.Api.Util 14 | { 15 | [JsonSourceGenerationOptions( 16 | PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] 17 | [JsonSerializable(typeof(MessageChain))] 18 | [JsonSerializable(typeof(IEnumerable))] 19 | [JsonSerializable(typeof(BaseChain))] 20 | [JsonSerializable(typeof(BaseMiraiEvent))] 21 | public partial class MiraiJsonContext : JsonSerializerContext 22 | { 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /WanBot.Api/Util/SyncIdHelper.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.Util 8 | { 9 | /// 10 | /// 生成同步Id 11 | /// 12 | internal static class SyncIdHelper 13 | { 14 | private static uint _offset; 15 | 16 | public static string Next() 17 | { 18 | ++_offset; 19 | return $"{DateTime.Now.ToFileTimeUtc()}{_offset}"; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WanBot.Api/WanBot.Api.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | preview 11 | 12 | 13 | 14 | preview 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /WanBot.Api/WanBotApi.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 8 | { 9 | public class WanBotApi : WanBotPlugin 10 | { 11 | public override string PluginName => "WanBot.Api"; 12 | 13 | public override string PluginAuthor => "WanNeng"; 14 | 15 | public override string PluginDescription => "完犊子Api,提供通用化的QQ机器人接口与mirai http协议的实现"; 16 | 17 | public override Version PluginVersion => GetType().Assembly.GetName().Version ?? Version.Parse("1.0.0"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /WanBot.Graphic.Example/WanBot.Graphic.Example.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /WanBot.Graphic/Fonts.cs: -------------------------------------------------------------------------------- 1 | using SkiaSharp; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace WanBot.Graphic 9 | { 10 | public static class Fonts 11 | { 12 | public static SKTypeface Default { get; set; } = SKTypeface.Default; 13 | 14 | public static void LoadDefault(string path) 15 | { 16 | var font = SKTypeface.FromFile(path); 17 | 18 | if (Default != SKTypeface.Default) 19 | Default.Dispose(); 20 | Default = font; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /WanBot.Graphic/Template/Box.cs: -------------------------------------------------------------------------------- 1 | using SkiaSharp; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using WanBot.Graphic.UI; 8 | using WanBot.Graphic.UI.Layout; 9 | 10 | namespace WanBot.Graphic.Template 11 | { 12 | /// 13 | /// 消息盒 14 | /// 15 | public class Box : Grid 16 | { 17 | public Rectangle Background; 18 | public TextBox TextBox; 19 | 20 | public Box(string text, float fontSize, SKColor fontColor, SKColor bgColor, SKTextAlign alignment, float margin = 0, float radiusX = 15, float radiusY = 15) 21 | { 22 | Background = new(); 23 | Background.Paint.Color = bgColor; 24 | Background.Radius = new SKSize(radiusX, radiusY); 25 | 26 | TextBox = new(); 27 | TextBox.Text = text; 28 | TextBox.FontPaint.TextAlign = alignment; 29 | TextBox.FontPaint.TextSize = fontSize; 30 | TextBox.FontPaint.Color = fontColor; 31 | TextBox.Margin = new Margin(margin, margin, margin, margin); 32 | Children.Add(Background); 33 | Children.Add(TextBox); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /WanBot.Graphic/UI/ImageBox.cs: -------------------------------------------------------------------------------- 1 | using SkiaSharp; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace WanBot.Graphic.UI 9 | { 10 | public class ImageBox : UIElement 11 | { 12 | public static SKPaint Empty { get; set; } = new() 13 | { 14 | Color = SKColors.White 15 | }; 16 | 17 | /// 18 | /// 图像 19 | /// 20 | public SKImage? Image { get; set; } 21 | 22 | public override void Draw(SKCanvas canvas) 23 | { 24 | if (Image == null) 25 | canvas.DrawRect(RenderRect, Empty); 26 | else 27 | canvas.DrawImage(Image, RenderRect); 28 | } 29 | 30 | public override SKRect UpdateLayout(SKRect rect) 31 | { 32 | return base.UpdateLayout(rect); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /WanBot.Graphic/UI/Layout/Alignment.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.Graphic.UI.Layout 8 | { 9 | public enum TextVerticalAlignment 10 | { 11 | Top, Center, Bottom 12 | } 13 | 14 | public enum HorizontalAlignment 15 | { 16 | Left, Center, Right 17 | } 18 | 19 | public enum VerticalAlignment 20 | { 21 | Top, Center, Bottom 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /WanBot.Graphic/UI/Layout/Grid.cs: -------------------------------------------------------------------------------- 1 | using SkiaSharp; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace WanBot.Graphic.UI.Layout 9 | { 10 | public class Grid : UIContainer 11 | { 12 | public override SKRect UpdateLayout(SKRect rect) 13 | { 14 | var result = base.UpdateLayout(rect); 15 | var right = result.Right; 16 | var bottom = result.Bottom; 17 | 18 | // 测量布局 19 | foreach (var child in Children) 20 | { 21 | var childRect = child.UpdateLayout(RenderRect); 22 | right = Math.Max(childRect.Right, right); 23 | bottom = Math.Max(childRect.Bottom, bottom); 24 | } 25 | 26 | var oldWidth = Width; 27 | var oldHeight = Height; 28 | Width = right - result.Left; 29 | Height = bottom - result.Top; 30 | 31 | result = base.UpdateLayout(rect); 32 | Width = oldWidth; 33 | Height = oldHeight; 34 | 35 | // 布局 36 | foreach (var child in Children) 37 | child.UpdateLayout(RenderRect); 38 | 39 | return result; 40 | } 41 | public override void DrawDebug(SKCanvas canvas) 42 | { 43 | base.DrawDebug(canvas); 44 | foreach (var child in Children) 45 | child.DrawDebug(canvas); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /WanBot.Graphic/UI/Margin.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.Graphic.UI 8 | { 9 | public struct Margin 10 | { 11 | public float? Left { get; set; } 12 | public float? Top { get; set; } 13 | public float? Right { get; set; } 14 | public float? Bottom { get; set; } 15 | 16 | public Margin(float left, float top) 17 | { 18 | Left = left; 19 | Right = null; 20 | Top = top; 21 | Bottom = null; 22 | } 23 | 24 | public Margin(float? left, float? top, float? right, float? bottom) 25 | { 26 | Left = left; 27 | Top = top; 28 | Right = right; 29 | Bottom = bottom; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /WanBot.Graphic/UI/Rectangle.cs: -------------------------------------------------------------------------------- 1 | using SkiaSharp; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace WanBot.Graphic.UI 9 | { 10 | public class Rectangle : UIElement 11 | { 12 | /// 13 | /// 边框圆角 14 | /// 15 | public SKSize Radius { get; set; } = new() 16 | { 17 | Height = 10, 18 | Width = 10 19 | }; 20 | 21 | /// 22 | /// 边框 23 | /// 24 | public float Border { get; set; } 25 | 26 | public SKPaint Paint { get; set; } = new() 27 | { 28 | Color = SKColors.White, 29 | IsAntialias = true 30 | }; 31 | 32 | public override void Draw(SKCanvas canvas) 33 | { 34 | canvas.DrawRoundRect(RenderRect, Radius, Paint); 35 | } 36 | 37 | public override void DrawDebug(SKCanvas canvas) 38 | { 39 | base.DrawDebug(canvas); 40 | } 41 | 42 | public override void Dispose() 43 | { 44 | base.Dispose(); 45 | Paint.Dispose(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /WanBot.Graphic/UI/UIContainer.cs: -------------------------------------------------------------------------------- 1 | using SkiaSharp; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace WanBot.Graphic.UI 9 | { 10 | /// 11 | /// UI容器,根据内容自适应大小 12 | /// 13 | public abstract class UIContainer : UIElement 14 | { 15 | /// 16 | /// 子元素 17 | /// 18 | public List Children { get; } = new(); 19 | 20 | public override void Draw(SKCanvas canvas) 21 | { 22 | foreach (var child in Children) 23 | child.Draw(canvas); 24 | } 25 | 26 | public override void Dispose() 27 | { 28 | base.Dispose(); 29 | foreach (var child in Children) 30 | child.Dispose(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /WanBot.Graphic/Util/VerticalHelper.cs: -------------------------------------------------------------------------------- 1 | using SkiaSharp; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using WanBot.Graphic.Template; 8 | using WanBot.Graphic.UI; 9 | using WanBot.Graphic.UI.Layout; 10 | 11 | namespace WanBot.Graphic.Util 12 | { 13 | /// 14 | /// 垂直布局助手 15 | /// 16 | public class VerticalHelper 17 | { 18 | public VerticalLayout VerticalLayout = new(); 19 | 20 | public VerticalHelper Add(UIElement element) 21 | { 22 | VerticalLayout.Children.Add(element); 23 | return this; 24 | } 25 | 26 | public VerticalHelper Box( 27 | string text, 28 | float fontSize = 32, 29 | float margin = 0, 30 | float radius = 0, 31 | SKTextAlign textAlignment = SKTextAlign.Center) 32 | { 33 | return Add(new Box(text, fontSize, SKColors.Black, SKColors.LightGray, textAlignment, margin, radius, radius)); 34 | } 35 | 36 | public VerticalHelper Box( 37 | string text, 38 | SKColor bgColor, 39 | SKColor fontColor, 40 | float fontSize = 32, 41 | float margin = 0, 42 | float radius = 0, 43 | SKTextAlign textAlignment = SKTextAlign.Center) 44 | { 45 | return Add(new Box(text, fontSize, fontColor, bgColor, textAlignment, margin, radius, radius)); 46 | } 47 | 48 | public VerticalHelper Width(float width) 49 | { 50 | VerticalLayout.Width = width; 51 | return this; 52 | } 53 | 54 | public VerticalHelper Space(float space) 55 | { 56 | VerticalLayout.Space = space; 57 | 58 | return this; 59 | } 60 | 61 | public VerticalHelper Center() 62 | { 63 | VerticalLayout.HorizontalAlignment = HorizontalAlignment.Center; 64 | return this; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /WanBot.Graphic/WanBot.Graphic.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | True 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /WanBot.Plugin.AI/AIConfig.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.Plugin.AI 8 | { 9 | internal class AIConfig 10 | { 11 | public string TongYiApiKey { get; set; } = string.Empty; 12 | public string TongYiModel { get; set; } = string.Empty; 13 | public string SystemPrompt { get; set; } = string.Empty; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /WanBot.Plugin.AI/ChatHistory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using WanBot.Api.Mirai.Message; 8 | 9 | namespace WanBot.Plugin.AI 10 | { 11 | public class ChatHistoryDictionary 12 | { 13 | private ConcurrentDictionary _chatDict = new(); 14 | 15 | public void LogChat(long groupId, string chatStr, bool isBot) 16 | { 17 | if (!_chatDict.TryGetValue(groupId, out var chatHistory)) 18 | { 19 | chatHistory = new GroupChatHistory(); 20 | _chatDict[groupId] = chatHistory; 21 | } 22 | lock (chatHistory.Chats) 23 | { 24 | chatHistory.Chats.Add(new(chatStr, isBot)); 25 | if (chatHistory.Chats.Count > 15) 26 | chatHistory.Chats.RemoveAt(0); 27 | } 28 | } 29 | 30 | public GroupChat[] GetChatHistory(long groupId) 31 | { 32 | if (!_chatDict.TryGetValue(groupId, out var chatHistory)) 33 | return Array.Empty(); 34 | lock (chatHistory.Chats) 35 | { 36 | return chatHistory.Chats.ToArray(); 37 | } 38 | } 39 | } 40 | 41 | public record struct GroupChat(string Content, bool IsBotMessage); 42 | public class GroupChatHistory 43 | { 44 | public List Chats = new(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /WanBot.Plugin.AI/IAIAdapter.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.Plugin.AI 8 | { 9 | internal interface IAIAdapter 10 | { 11 | public Task ProcessAsync(string systemMessage, IEnumerable chats); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /WanBot.Plugin.AI/WanBot.Plugin.AI.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | $(SolutionDir)Bin/Plugin/ 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /WanBot.Plugin.Core/WanBot.Plugin.Core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | $(SolutionDir)Bin/Plugin/ 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /WanBot.Plugin.Essential/EssAttribute/DbEssAttributeUser.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.Plugin.Essential.EssAttribute 8 | { 9 | public class DbEssAttributeUser 10 | { 11 | /// 12 | /// QQ号 13 | /// 14 | public long Id { get; internal set; } 15 | 16 | /// 17 | /// 钱 18 | /// 19 | public string Money { get; set; } = "0"; 20 | 21 | /// 22 | /// 最大精力上限,默认100 23 | /// 24 | public int EnergyMax { get; set; } = 100; 25 | 26 | /// 27 | /// 当前精力 28 | /// 29 | public int Energy { get; set; } 30 | 31 | /// 32 | /// 上一次查询能量的时间 33 | /// 34 | public DateTime LastTimeCheckEnergy { get; set; } 35 | 36 | /// 37 | /// 额外攻击力 38 | /// 39 | public int AttactAddition { get; set; } 40 | 41 | /// 42 | /// 额外防御力 43 | /// 44 | public int DefenceAddition { get; set; } 45 | 46 | /// 47 | /// 额外特攻 48 | /// 49 | public int SpAttactAddition { get; set; } 50 | 51 | /// 52 | /// 额外特防 53 | /// 54 | public int SpDefenceAddition { get; set; } 55 | 56 | /// 57 | /// 额外血量 58 | /// 59 | public int HpAddition { get; set; } 60 | 61 | /// 62 | /// 额外魔力值 63 | /// 64 | public int MagicAddition { get; set; } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /WanBot.Plugin.Essential/EssAttribute/EssAttrUserFactory.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using WanBot.Api; 8 | 9 | namespace WanBot.Plugin.Essential.EssAttribute 10 | { 11 | public class EssAttrUserFactory : IDisposable 12 | { 13 | private string _dbPath; 14 | 15 | private EssAttributeDatabaseContext _db; 16 | 17 | public EssAttrUserFactory(string dbPath) 18 | { 19 | _dbPath = dbPath; 20 | _db = new EssAttributeDatabaseContext(_dbPath); 21 | } 22 | 23 | public void Dispose() 24 | { 25 | _db.Dispose(); 26 | } 27 | 28 | public EssAttrUser FromSender(ISender sender) 29 | { 30 | return new EssAttrUser(sender.Id, _db); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /WanBot.Plugin.Essential/EssAttribute/EssAttributeDatabaseContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace WanBot.Plugin.Essential.EssAttribute 9 | { 10 | public class EssAttributeDatabaseContext : DbContext 11 | { 12 | public DbSet Users { get; set; } = null!; 13 | 14 | public string DbPath { get; } 15 | 16 | public EssAttributeDatabaseContext(string dbPath = "database.db") 17 | { 18 | DbPath = dbPath; 19 | } 20 | 21 | protected override void OnConfiguring(DbContextOptionsBuilder options) 22 | => options.UseSqlite($"Data Source={DbPath}"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /WanBot.Plugin.Essential/EssAttribute/WanBotPluginExtension.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; 7 | using WanBot.Plugin.Essential.Extension; 8 | 9 | namespace WanBot.Plugin.Essential.EssAttribute 10 | { 11 | public static class WanBotPluginExtension 12 | { 13 | public static EssAttrUserFactory GetEssAttrUserFactory(this WanBotPlugin plugin) 14 | { 15 | return plugin.Application.PluginManager.GetPlugin()?.essAttrUsrFactory 16 | ?? throw new Exception("Failed to get essAttrUsrFactory"); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /WanBot.Plugin.Essential/Extension/HelpCategory.cs: -------------------------------------------------------------------------------- 1 | using SkiaSharp; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using WanBot.Graphic.UI; 8 | using WanBot.Graphic.UI.Layout; 9 | using WanBot.Graphic.Util; 10 | 11 | namespace WanBot.Plugin.Essential.Extension 12 | { 13 | /// 14 | /// 命令帮助 15 | /// 16 | public struct HelpCategory : IHelp 17 | { 18 | public string category; 19 | 20 | public UIElement ToUI(float width) 21 | { 22 | var vertical = new VerticalHelper(); 23 | 24 | vertical 25 | .Box(category, SKColors.White, SKColors.Black, 19) 26 | .Width(width); 27 | 28 | return vertical.VerticalLayout; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /WanBot.Plugin.Essential/Extension/HelpCommand.cs: -------------------------------------------------------------------------------- 1 | using SkiaSharp; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using WanBot.Graphic.UI; 8 | using WanBot.Graphic.UI.Layout; 9 | using WanBot.Graphic.Util; 10 | 11 | namespace WanBot.Plugin.Essential.Extension 12 | { 13 | /// 14 | /// 命令帮助 15 | /// 16 | public struct HelpCommand : IHelp 17 | { 18 | public string command; 19 | public string usage; 20 | 21 | public UIElement ToUI(float width) 22 | { 23 | var vertical = new VerticalHelper(); 24 | 25 | vertical 26 | .Box(command, 18, textAlignment: SKTextAlign.Left) 27 | .Box(usage, 15, textAlignment: SKTextAlign.Right) 28 | .Space(0) 29 | .Width(width); 30 | 31 | return vertical.VerticalLayout; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /WanBot.Plugin.Essential/Extension/HelpInfo.cs: -------------------------------------------------------------------------------- 1 | using SkiaSharp; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using WanBot.Graphic.UI; 8 | using WanBot.Graphic.UI.Layout; 9 | using WanBot.Graphic.Util; 10 | 11 | namespace WanBot.Plugin.Essential.Extension 12 | { 13 | /// 14 | /// 命令帮助 15 | /// 16 | public struct HelpInfo : IHelp 17 | { 18 | public string info; 19 | 20 | public HorizontalAlignment alignment; 21 | 22 | public UIElement ToUI(float width) 23 | { 24 | var vertical = new VerticalHelper(); 25 | 26 | vertical 27 | .Box(info, SKColors.White, SKColors.Black, 14, textAlignment: SKTextAlign.Right) 28 | .Width(width); 29 | 30 | return vertical.VerticalLayout; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /WanBot.Plugin.Essential/Extension/IHelp.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.Graphic.UI; 7 | 8 | namespace WanBot.Plugin.Essential.Extension 9 | { 10 | public interface IHelp 11 | { 12 | /// 13 | /// 转换为UI 14 | /// 15 | /// 16 | public UIElement ToUI(float width); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /WanBot.Plugin.Essential/Extension/WanBotPluginExtension.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; 7 | using WanBot.Graphic; 8 | using WanBot.Plugin.Essential.Graphic; 9 | 10 | namespace WanBot.Plugin.Essential.Extension 11 | { 12 | public static class WanBotPluginExtension 13 | { 14 | public static UIRenderer GetUIRenderer(this WanBotPlugin plugin) 15 | { 16 | return plugin.Application.PluginManager.GetPlugin()?.Renderer 17 | ?? throw new Exception("Failed to get renderer"); 18 | } 19 | 20 | public static Scheduler GetScheduler(this WanBotPlugin plugin) 21 | { 22 | return plugin.Application.PluginManager.GetPlugin()?.scheduler 23 | ?? throw new Exception("Failed to get scheduler"); 24 | } 25 | 26 | public static BotHelp GetBotHelp(this WanBotPlugin plugin) 27 | { 28 | return plugin.Application.PluginManager.GetPlugin()?.botHelp 29 | ?? throw new Exception("Failed to get botHelp"); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /WanBot.Plugin.Essential/Graphic/Avatar.cs: -------------------------------------------------------------------------------- 1 | using SkiaSharp; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace WanBot.Plugin.Essential.Graphic 9 | { 10 | public class Avatar : IDisposable 11 | { 12 | public SKImage? Image { get; } 13 | 14 | private Avatar(SKImage? image) 15 | { 16 | Image = image; 17 | } 18 | 19 | public static async Task FromQQAsync(long qq) 20 | { 21 | using var httpClient = new HttpClient(); 22 | 23 | var url = $"http://q1.qlogo.cn/g?b=qq&nk={qq}&s=640"; 24 | var response = await httpClient.GetAsync(url); 25 | if (!response.IsSuccessStatusCode) 26 | return new Avatar(null); 27 | 28 | var skData = SKData.Create(await response.Content.ReadAsStreamAsync()); 29 | var image = SKImage.FromEncodedData(skData); 30 | 31 | return new Avatar(image); 32 | } 33 | 34 | public void Dispose() 35 | { 36 | Image?.Dispose(); 37 | GC.SuppressFinalize(this); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /WanBot.Plugin.Essential/Graphic/GraphicConfig.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.Plugin.Essential.Graphic 8 | { 9 | public class GraphicConfig 10 | { 11 | /// 12 | /// 默认字体下载链接 13 | /// 14 | public string DefaultFontUrl = "https://github.com/lxgw/LxgwWenKai/releases/download/v1.235.2/LXGWWenKai-Light.ttf"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /WanBot.Plugin.Essential/Graphic/GraphicPlugin.Example.cs: -------------------------------------------------------------------------------- 1 | using SkiaSharp; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using WanBot.Graphic.UI; 8 | using WanBot.Graphic.UI.Layout; 9 | 10 | namespace WanBot.Plugin.Essential.Graphic 11 | { 12 | public partial class GraphicPlugin 13 | { 14 | public Grid GetExample(string title, SKImage? icon) 15 | { 16 | var grid = new Grid(); 17 | grid.Width = 500; 18 | grid.Height = 500; 19 | 20 | // 背景 21 | var gridBg = new Rectangle(); 22 | gridBg.Radius = new SKSize(50, 50); 23 | gridBg.Paint.Color = SKColors.DarkGray; 24 | grid.Children.Add(gridBg); 25 | 26 | // 垂直布局 27 | var verticalLayout = new VerticalLayout(); 28 | verticalLayout.HorizontalAlignment = HorizontalAlignment.Center; 29 | 30 | { 31 | //文本框 32 | var textBox = new TextBox(); 33 | textBox.Text = title; 34 | textBox.Margin = new Margin(50, 50, 50, 0); 35 | textBox.FontPaint.Color = SKColors.DarkBlue; 36 | 37 | verticalLayout.Children.Add(textBox); 38 | 39 | // 头像 40 | var imageBox = new ImageBox(); 41 | imageBox.Image = icon; 42 | imageBox.Width = 300; 43 | imageBox.Height = 300; 44 | verticalLayout.Children.Add(imageBox); 45 | } 46 | grid.Children.Add(verticalLayout); 47 | 48 | return grid; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /WanBot.Plugin.Essential/Migrations/20220819153046_InitialCreate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | 4 | #nullable disable 5 | 6 | namespace WanBot.Plugin.Essential.Migrations 7 | { 8 | public partial class InitialCreate : Migration 9 | { 10 | protected override void Up(MigrationBuilder migrationBuilder) 11 | { 12 | migrationBuilder.CreateTable( 13 | name: "Users", 14 | columns: table => new 15 | { 16 | Id = table.Column(type: "INTEGER", nullable: false) 17 | .Annotation("Sqlite:Autoincrement", true), 18 | Money = table.Column(type: "TEXT", nullable: false), 19 | EnergyMax = table.Column(type: "INTEGER", nullable: false), 20 | Energy = table.Column(type: "INTEGER", nullable: false), 21 | LastTimeCheckEnergy = table.Column(type: "TEXT", nullable: false), 22 | AttactAddition = table.Column(type: "INTEGER", nullable: false), 23 | DefenceAddition = table.Column(type: "INTEGER", nullable: false), 24 | SpAttactAddition = table.Column(type: "INTEGER", nullable: false), 25 | SpDefenceAddition = table.Column(type: "INTEGER", nullable: false), 26 | HpAddition = table.Column(type: "INTEGER", nullable: false), 27 | MagicAddition = table.Column(type: "INTEGER", nullable: false) 28 | }, 29 | constraints: table => 30 | { 31 | table.PrimaryKey("PK_Users", x => x.Id); 32 | }); 33 | } 34 | 35 | protected override void Down(MigrationBuilder migrationBuilder) 36 | { 37 | migrationBuilder.DropTable( 38 | name: "Users"); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /WanBot.Plugin.Essential/Permission/PermissionConfig.cs: -------------------------------------------------------------------------------- 1 | namespace WanBot.Plugin.Essential.Permission 2 | { 3 | public class PermissionConfig 4 | { 5 | public class PermissionGroup 6 | { 7 | public string Name { get; set; } = ""; 8 | 9 | public List Permissions { get; set; } = new(); 10 | } 11 | 12 | public List GroupPermissionGroups { get; set; } = new() 13 | { 14 | new PermissionGroup() 15 | { 16 | Name = "Default", 17 | Permissions = new() { "Permission.User" } 18 | } 19 | }; 20 | 21 | public string DefaultGroupGroup { get; set; } = "Default"; 22 | 23 | /// 24 | /// 管理员账户列表 25 | /// 26 | public List Admin { get; set; } = new(); 27 | } 28 | } -------------------------------------------------------------------------------- /WanBot.Plugin.Essential/Permission/PermissionException.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.Plugin.Essential.Permission 8 | { 9 | /// 10 | /// 权限异常 11 | /// 12 | public class PermissionException : Exception 13 | { 14 | public string RequirePermission { get; } 15 | public PermissionException(string requirePermission) : base($"Require permission {requirePermission}") 16 | { 17 | RequirePermission = requirePermission; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /WanBot.Plugin.Essential/WanBot.Plugin.Essential.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | $(SolutionDir)Bin/Plugin/ 8 | true 9 | 10 | 11 | 12 | preview 13 | 14 | 15 | 16 | preview 17 | 18 | 19 | 20 | 21 | 22 | all 23 | runtime; build; native; contentfiles; analyzers; buildtransitive 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /WanBot.Plugin.HelloWorld/JrrpAddition.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.Plugin.Jrrp; 7 | using WanBot.Api; 8 | 9 | namespace WanBot.Plugin.HelloWorld 10 | { 11 | /// 12 | /// 与Jrrp插件的联动 13 | /// 14 | public class JrrpAddition 15 | { 16 | private JrrpPlugin _jrrpPlugin; 17 | 18 | public JrrpAddition(BasePlugin plugin) 19 | { 20 | _jrrpPlugin = plugin.Application.PluginManager.GetPlugin()!; 21 | _jrrpPlugin.Tips.Add((id, jrrp) => 22 | { 23 | if (jrrp > 0.7) 24 | return "完犊子今天非常开心!他会尽可能带给你好运的。\t"; 25 | else if (jrrp > 0.5) 26 | return "这很罕见。完犊子今天很冷漠。"; 27 | else 28 | return "完犊子十分不满。他会竭尽全力给你捣蛋的。\t"; 29 | }); 30 | } 31 | 32 | /// 33 | /// 是否能打完犊子 34 | /// 35 | /// 36 | public async Task CanBeatWanBotAsync(long id) 37 | { 38 | return await _jrrpPlugin?.GetJrrpAsync(id)! > 0.7; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /WanBot.Plugin.HelloWorld/WanBot.Plugin.HelloWorld.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | $(SolutionDir)Bin/Plugin/ 8 | 9 | 10 | 11 | preview 12 | 13 | 14 | 15 | preview 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /WanBot.Plugin.HotSpot/WanBot.Plugin.HotSpot.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | $(SolutionDir)Bin/Plugin/ 8 | true 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /WanBot.Plugin.HotSpot/WeiboUtil.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.Plugin.HotSpot 8 | { 9 | public class WeiboSearchResult 10 | { 11 | public int ok { get; set; } 12 | public WeiboSearchData data { get; set; } = null!; 13 | } 14 | 15 | public class WeiboSearchData 16 | { 17 | public WeiboCardListInfo cardlistInfo { get; set; } = null!; 18 | public WeiboCard[] cards { get; set; } = Array.Empty(); 19 | } 20 | 21 | public class WeiboCardListInfo 22 | { 23 | public string cardlist_title { get; set; } = string.Empty; 24 | 25 | public string desc { get; set; } = string.Empty; 26 | } 27 | 28 | public class WeiboCard 29 | { 30 | public int card_type { get; set; } 31 | 32 | public WeiboBlog mblog { get; set; } = null!; 33 | 34 | public List card_group = new(); 35 | 36 | } 37 | 38 | public class WeiboBlog 39 | { 40 | public string text { get; set; } = null!; 41 | 42 | public string original_pic { get; set; } = null!; 43 | 44 | public WeiboUser user { get; set; } = null!; 45 | } 46 | 47 | public class WeiboUser 48 | { 49 | public string screen_name { get; set; } = string.Empty; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /WanBot.Plugin.JavaScript/WanBot.Plugin.JavaScript.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | $(SolutionDir)Bin/Plugin/ 8 | true 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /WanBot.Plugin.JobAndLife/JrrpAddition.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.Plugin.Jrrp; 7 | using WanBot.Api; 8 | 9 | namespace WanBot.Plugin.JobAndLife 10 | { 11 | /// 12 | /// 与Jrrp插件的联动 13 | /// 14 | public class JrrpAddition 15 | { 16 | private JrrpPlugin _jrrpPlugin; 17 | 18 | public JrrpAddition(BasePlugin plugin) 19 | { 20 | _jrrpPlugin = plugin.Application.PluginManager.GetPlugin()!; 21 | _jrrpPlugin.Tips.Add((id, jrrp) => 22 | { 23 | if (GetJrrpSalaryScale(jrrp) > 1) 24 | return "今天非常适合#打工哦!老板看好你~"; 25 | else if (GetJrrpSalaryScale(jrrp) > 0.8) 26 | return "今天有一点不在状态,是不是不适合#打工呢"; 27 | else 28 | return "今天完全不想#打工"; 29 | }); 30 | } 31 | 32 | /// 33 | /// 获取Jrrp系数 34 | /// 35 | /// 36 | private async Task GetJrrpAsync(long id) 37 | { 38 | return await _jrrpPlugin?.GetJrrpAsync(id)!; 39 | } 40 | 41 | /// 42 | /// 根据Jrrp计算工资系数 43 | /// 44 | /// 45 | /// 46 | public async Task GetJrrpSalaryScale(long id) 47 | { 48 | return GetJrrpSalaryScale(await GetJrrpAsync(id)); 49 | } 50 | 51 | /// 52 | /// 根据Jrrp计算工资系数 53 | /// 54 | /// 55 | /// 56 | private float GetJrrpSalaryScale(float jrrp) 57 | { 58 | return jrrp * 0.5f + 0.6f; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /WanBot.Plugin.JobAndLife/WanBot.Plugin.JobAndLife.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | $(SolutionDir)Bin/Plugin/ 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /WanBot.Plugin.Jrrp/JrrpConfig.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.Plugin.Jrrp 8 | { 9 | public class JrrpConfig 10 | { 11 | public List Activity { get; set; } = new() 12 | { 13 | "打牌", 14 | "打音游", 15 | "写代码", 16 | "女装", 17 | "学习", 18 | "修仙", 19 | "水群", 20 | "考试", 21 | "打工", 22 | "逛街", 23 | "跑步", 24 | "氪金", 25 | "抽卡" 26 | }; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /WanBot.Plugin.Jrrp/JrrpDatabaseContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace WanBot.Plugin.Jrrp 9 | { 10 | internal class JrrpDatabaseContext : DbContext 11 | { 12 | public DbSet Users { get; set; } = null!; 13 | 14 | public string DbPath { get; } 15 | 16 | public JrrpDatabaseContext(string dbPath = "database.db") 17 | { 18 | DbPath = dbPath; 19 | } 20 | 21 | protected override void OnConfiguring(DbContextOptionsBuilder options) 22 | => options.UseSqlite($"Data Source={DbPath}"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /WanBot.Plugin.Jrrp/JrrpUser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace WanBot.Plugin.Jrrp 9 | { 10 | public class JrrpUser 11 | { 12 | /// 13 | /// QQ号 14 | /// 15 | public long Id { get; internal set; } 16 | 17 | /// 18 | /// 今日运势 19 | /// 20 | public float Jrrp { get; set; } 21 | 22 | /// 23 | /// 能做的事情Id 24 | /// 25 | public int CanDo { get; set; } 26 | 27 | /// 28 | /// 不能做的事情Id 29 | /// 30 | public int CantDo { get; set; } 31 | 32 | /// 33 | /// 上次获取日期 34 | /// 35 | public DateTime LastTime { get; set; } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /WanBot.Plugin.Jrrp/Migrations/20220806155035_InitialCreate.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using Microsoft.EntityFrameworkCore; 4 | using Microsoft.EntityFrameworkCore.Infrastructure; 5 | using Microsoft.EntityFrameworkCore.Migrations; 6 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 7 | using WanBot.Plugin.Jrrp; 8 | 9 | #nullable disable 10 | 11 | namespace WanBot.Plugin.Jrrp.Migrations 12 | { 13 | [DbContext(typeof(JrrpDatabaseContext))] 14 | [Migration("20220806155035_InitialCreate")] 15 | partial class InitialCreate 16 | { 17 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 18 | { 19 | #pragma warning disable 612, 618 20 | modelBuilder.HasAnnotation("ProductVersion", "6.0.7"); 21 | 22 | modelBuilder.Entity("WanBot.Plugin.Jrrp.JrrpUser", b => 23 | { 24 | b.Property("Id") 25 | .ValueGeneratedOnAdd() 26 | .HasColumnType("INTEGER"); 27 | 28 | b.Property("Jrrp") 29 | .HasColumnType("REAL"); 30 | 31 | b.Property("LastTime") 32 | .HasColumnType("TEXT"); 33 | 34 | b.HasKey("Id"); 35 | 36 | b.ToTable("Users"); 37 | }); 38 | #pragma warning restore 612, 618 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /WanBot.Plugin.Jrrp/Migrations/20220806155035_InitialCreate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | 4 | #nullable disable 5 | 6 | namespace WanBot.Plugin.Jrrp.Migrations 7 | { 8 | public partial class InitialCreate : Migration 9 | { 10 | protected override void Up(MigrationBuilder migrationBuilder) 11 | { 12 | migrationBuilder.CreateTable( 13 | name: "Users", 14 | columns: table => new 15 | { 16 | Id = table.Column(type: "INTEGER", nullable: false) 17 | .Annotation("Sqlite:Autoincrement", true), 18 | Jrrp = table.Column(type: "REAL", nullable: false), 19 | LastTime = table.Column(type: "TEXT", nullable: false) 20 | }, 21 | constraints: table => 22 | { 23 | table.PrimaryKey("PK_Users", x => x.Id); 24 | }); 25 | } 26 | 27 | protected override void Down(MigrationBuilder migrationBuilder) 28 | { 29 | migrationBuilder.DropTable( 30 | name: "Users"); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /WanBot.Plugin.Jrrp/Migrations/20220819170410_AddCanDoAndCantDo.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using Microsoft.EntityFrameworkCore; 4 | using Microsoft.EntityFrameworkCore.Infrastructure; 5 | using Microsoft.EntityFrameworkCore.Migrations; 6 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 7 | using WanBot.Plugin.Jrrp; 8 | 9 | #nullable disable 10 | 11 | namespace WanBot.Plugin.Jrrp.Migrations 12 | { 13 | [DbContext(typeof(JrrpDatabaseContext))] 14 | [Migration("20220819170410_AddCanDoAndCantDo")] 15 | partial class AddCanDoAndCantDo 16 | { 17 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 18 | { 19 | #pragma warning disable 612, 618 20 | modelBuilder.HasAnnotation("ProductVersion", "6.0.8"); 21 | 22 | modelBuilder.Entity("WanBot.Plugin.Jrrp.JrrpUser", b => 23 | { 24 | b.Property("Id") 25 | .ValueGeneratedOnAdd() 26 | .HasColumnType("INTEGER"); 27 | 28 | b.Property("CanDo") 29 | .HasColumnType("INTEGER"); 30 | 31 | b.Property("CantDo") 32 | .HasColumnType("INTEGER"); 33 | 34 | b.Property("Jrrp") 35 | .HasColumnType("REAL"); 36 | 37 | b.Property("LastTime") 38 | .HasColumnType("TEXT"); 39 | 40 | b.HasKey("Id"); 41 | 42 | b.ToTable("Users"); 43 | }); 44 | #pragma warning restore 612, 618 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /WanBot.Plugin.Jrrp/Migrations/20220819170410_AddCanDoAndCantDo.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | 3 | #nullable disable 4 | 5 | namespace WanBot.Plugin.Jrrp.Migrations 6 | { 7 | public partial class AddCanDoAndCantDo : Migration 8 | { 9 | protected override void Up(MigrationBuilder migrationBuilder) 10 | { 11 | migrationBuilder.AddColumn( 12 | name: "CanDo", 13 | table: "Users", 14 | type: "INTEGER", 15 | nullable: false, 16 | defaultValue: 0); 17 | 18 | migrationBuilder.AddColumn( 19 | name: "CantDo", 20 | table: "Users", 21 | type: "INTEGER", 22 | nullable: false, 23 | defaultValue: 0); 24 | } 25 | 26 | protected override void Down(MigrationBuilder migrationBuilder) 27 | { 28 | migrationBuilder.DropColumn( 29 | name: "CanDo", 30 | table: "Users"); 31 | 32 | migrationBuilder.DropColumn( 33 | name: "CantDo", 34 | table: "Users"); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /WanBot.Plugin.Jrrp/Migrations/JrrpDatabaseContextModelSnapshot.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using Microsoft.EntityFrameworkCore; 4 | using Microsoft.EntityFrameworkCore.Infrastructure; 5 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 6 | using WanBot.Plugin.Jrrp; 7 | 8 | #nullable disable 9 | 10 | namespace WanBot.Plugin.Jrrp.Migrations 11 | { 12 | [DbContext(typeof(JrrpDatabaseContext))] 13 | partial class JrrpDatabaseContextModelSnapshot : ModelSnapshot 14 | { 15 | protected override void BuildModel(ModelBuilder modelBuilder) 16 | { 17 | #pragma warning disable 612, 618 18 | modelBuilder.HasAnnotation("ProductVersion", "6.0.8"); 19 | 20 | modelBuilder.Entity("WanBot.Plugin.Jrrp.JrrpUser", b => 21 | { 22 | b.Property("Id") 23 | .ValueGeneratedOnAdd() 24 | .HasColumnType("INTEGER"); 25 | 26 | b.Property("CanDo") 27 | .HasColumnType("INTEGER"); 28 | 29 | b.Property("CantDo") 30 | .HasColumnType("INTEGER"); 31 | 32 | b.Property("Jrrp") 33 | .HasColumnType("REAL"); 34 | 35 | b.Property("LastTime") 36 | .HasColumnType("TEXT"); 37 | 38 | b.HasKey("Id"); 39 | 40 | b.ToTable("Users"); 41 | }); 42 | #pragma warning restore 612, 618 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /WanBot.Plugin.Jrrp/WanBot.Plugin.Jrrp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | $(SolutionDir)Bin/Plugin/ 8 | 9 | 10 | 11 | 12 | 13 | all 14 | runtime; build; native; contentfiles; analyzers; buildtransitive 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /WanBot.Plugin.Kemono/WanBot.Plugin.Kemono.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | $(SolutionDir)Bin/Plugin/ 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /WanBot.Plugin.LuaScript/LuaDebugger.cs: -------------------------------------------------------------------------------- 1 | using Neo.IronLua; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace WanBot.Plugin.LuaScript 9 | { 10 | internal class LuaDebugger : LuaTraceLineDebugger 11 | { 12 | private CancellationToken _ct; 13 | public int CurrentLine { get; private set; } 14 | 15 | public LuaDebugger(CancellationToken ct) 16 | { 17 | _ct = ct; 18 | } 19 | 20 | protected override void OnExceptionUnwind(LuaTraceLineExceptionEventArgs e) 21 | { 22 | CurrentLine = e.SourceLine; 23 | base.OnExceptionUnwind(e); 24 | } 25 | protected override void OnTracePoint(LuaTraceLineEventArgs e) 26 | { 27 | _ct.ThrowIfCancellationRequested(); 28 | CurrentLine = e.SourceLine; 29 | base.OnTracePoint(e); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /WanBot.Plugin.LuaScript/WanBot.Plugin.LuaScript.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | $(SolutionDir)Bin/Plugin/ 8 | true 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /WanBot.Plugin.Pokemon/WanBot.Plugin.Pokemon.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | $(SolutionDir)Bin/Plugin/ 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /WanBot.Plugin.RandomStuff/Food/CookMethod.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.Plugin.RandomStuff.Food 8 | { 9 | internal class CookMethod : IFoodGenerator 10 | { 11 | private bool _multiWord; 12 | 13 | public static string[] CookMethodList = new[] 14 | { 15 | "油爆", "油闷", "宫保", "凉拌", "冰糖", 16 | "干拌", "干烧", "香辣", "清蒸", "白灼", 17 | "糖醋", "蒜蓉", "油泼" 18 | }; 19 | 20 | public static string[] CookMethodSingleWordList = new[] 21 | { 22 | "炒", "煎", "烹", "炸", "蒸", "煮" 23 | }; 24 | 25 | public CookMethod(bool multiWord) 26 | { 27 | _multiWord = multiWord; 28 | } 29 | 30 | public CookMethod() : this(false) 31 | { 32 | } 33 | 34 | public string GenFood() 35 | { 36 | if (_multiWord && new Random().Next(0, 2) == 0) 37 | return CookMethodList[new Random().Next(0, CookMethodList.Length)]; 38 | return CookMethodSingleWordList[new Random().Next(0, CookMethodSingleWordList.Length)]; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /WanBot.Plugin.RandomStuff/Food/FoodStructure.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection.Metadata.Ecma335; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace WanBot.Plugin.RandomStuff.Food 9 | { 10 | internal class FoodStructure : IFoodGenerator 11 | { 12 | public static List> FoodStructureList = new() 13 | { 14 | // 油闷 大虾 15 | () => $"{new CookMethod().GenFood()}{new Ingredients(true, false, false).GenFood()}", 16 | () => $"{new CookMethod().GenFood()}{new Ingredients(false, true, false).GenFood()}", 17 | () => $"{new CookMethod().GenFood()}{new Ingredients(false, false, true).GenFood()}", 18 | () => $"{new CookMethod().GenFood()}{new Ingredients(true, true, false).GenFood()}", 19 | () => $"{new CookMethod().GenFood()}{new Ingredients(true, false, true).GenFood()}", 20 | () => $"{new CookMethod().GenFood()}{new Ingredients(false, true, true).GenFood()}", 21 | () => $"{new CookMethod().GenFood()}{new Ingredients(true, true, true).GenFood()}", 22 | 23 | // 西红柿 炒 鸡蛋 24 | () => $"{new Ingredients(false, false, true).GenFood()}{new CookMethod().GenFood()}{new Ingredients(true, false, false).GenFood()}", 25 | () => $"{new Ingredients(false, false, true).GenFood()}{new Ingredients(false, false, true).GenFood()}{new CookMethod().GenFood()}{new Ingredients(true, false, false).GenFood()}", 26 | 27 | // 金枪鱼 刺身 28 | () => $"{new Ingredients(false, true, false).GenFood()}刺身" 29 | }; 30 | 31 | public string GenFood() 32 | { 33 | return FoodStructureList[new Random().Next(0, FoodStructureList.Count)](); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /WanBot.Plugin.RandomStuff/Food/IFoodGenerator.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.Plugin.RandomStuff.Food 8 | { 9 | public interface IFoodGenerator 10 | { 11 | public string GenFood(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /WanBot.Plugin.RandomStuff/Food/RandomFoodGenerator.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.Plugin.RandomStuff.Food 8 | { 9 | /// 10 | /// 随机食物 11 | /// 12 | public class RandomFoodGenerator : IFoodGenerator 13 | { 14 | public static string[] FoodList = new[] 15 | { 16 | "面包", "蛋糕", "荷包蛋", "烧饼", "饽饽", 17 | "肉夹馍", "油条", "馄饨", "火腿", "面条", 18 | "小笼包", "玉米粥", "肉包", "煎饼果子", "饺子", 19 | "煎蛋", "烧卖", "生煎", "锅贴", "包子", 20 | "酸奶", "苹果", "梨", "香蕉", "皮蛋瘦肉粥", 21 | "蛋挞", "南瓜粥", "煎饼", "玉米糊", "泡面", 22 | "粥", "馒头", "燕麦片", "水煮蛋", "米粉", 23 | "豆浆", "牛奶", "花卷", "豆腐脑", "煎饼果子", 24 | "小米粥", "黑米糕", "鸡蛋饼", "牛奶布丁", "水果沙拉", 25 | "鸡蛋羹", "南瓜馅饼", "鸡蛋灌饼", "奶香小馒头", "汉堡包", 26 | "披萨", "八宝粥", "三明治", "蛋包饭", "豆沙红薯饼", 27 | "驴肉火烧", "粥", "粢饭糕", "蒸饺", "白粥", 28 | "盖浇饭", "砂锅", "大排档", "米线", "满汉全席", 29 | "西餐", "麻辣烫", "自助餐", "炒面", "快餐", 30 | "水果", "西北风", "馄饨", "火锅", "烧烤", 31 | "泡面", "水饺", "日本料理", "涮羊肉", "味千拉面", 32 | "面包", "扬州炒饭", "自助餐", "菜饭骨头汤", "茶餐厅", 33 | "海底捞", "西贝莜面村", "披萨", "麦当劳", "KFC", 34 | "汉堡王", "卡乐星", "兰州拉面", "沙县小吃", "烤鱼", 35 | "烤肉", "海鲜", "铁板烧", "韩国料理", "粥", 36 | "快餐", "萨莉亚", "桂林米粉", "东南亚菜", "甜点", 37 | "农家菜", "川菜", "粤菜", "湘菜", "本帮菜", 38 | "生活", "全家便当" 39 | }; 40 | 41 | public string GenFood() 42 | { 43 | var rand = new Random(); 44 | 45 | if (rand.Next(0, 3) != 1) 46 | { 47 | // 从数据库里找食物 48 | return FoodList[rand.Next(0, FoodList.Length)]; 49 | } 50 | else 51 | return new FoodStructure().GenFood(); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /WanBot.Plugin.RandomStuff/RandomStuffConfig.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.Plugin.RandomStuff 8 | { 9 | public class RandomStuffConfig 10 | { 11 | public string[] TalkWords { get; set; } = 12 | { 13 | "?","你说啥?","嗷?", "我不", "哼!" 14 | }; 15 | 16 | /// 17 | /// 概率基数 18 | /// 19 | public int RateBase { get; set; } = 20; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /WanBot.Plugin.RandomStuff/WanBot.Plugin.RandomStuff.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | $(SolutionDir)Bin/Plugin/ 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /WanBot.Plugin.WanCoin/JrrpAddition.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.Plugin.Jrrp; 7 | using WanBot.Api; 8 | 9 | namespace WanBot.Plugin.WanCoin 10 | { 11 | /// 12 | /// 与Jrrp插件的联动 13 | /// 14 | public class JrrpAddition 15 | { 16 | private JrrpPlugin _jrrpPlugin; 17 | 18 | public JrrpAddition(BasePlugin plugin) 19 | { 20 | _jrrpPlugin = plugin.Application.PluginManager.GetPlugin()!; 21 | _jrrpPlugin.Tips.Add((id, jrrp) => 22 | { 23 | var wanCoinPlugin = plugin as WanCoinPlugin; 24 | if (wanCoinPlugin == null) 25 | return "虚度币呢??!"; 26 | using var wanCoinDb = wanCoinPlugin.GetWanCoinDatabase(); 27 | var serverUser = wanCoinPlugin.GetWanCoinUser(wanCoinDb, WanCoinPlugin.ServerQQId); 28 | var buyPrice = wanCoinPlugin.GetCurrentPrice(serverUser.CoinCount - 1); 29 | var sellPrice = wanCoinPlugin.GetCurrentPrice(serverUser.CoinCount); 30 | if (jrrp < 0.5) 31 | return $"虚犊币当前价格 买:{buyPrice} 卖:{sellPrice}(快买 快买 快买)"; 32 | else 33 | return $"虚犊币当前价格 买:{buyPrice} 卖:{sellPrice}(快卖 快卖 快卖)"; 34 | }); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /WanBot.Plugin.WanCoin/Migrations/20221009071933_InitialCreate.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Infrastructure; 4 | using Microsoft.EntityFrameworkCore.Migrations; 5 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 6 | using WanBot.Plugin.WanCoin; 7 | 8 | #nullable disable 9 | 10 | namespace WanBot.Plugin.WanCoin.Migrations 11 | { 12 | [DbContext(typeof(WanCoinDatabase))] 13 | [Migration("20221009071933_InitialCreate")] 14 | partial class InitialCreate 15 | { 16 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 17 | { 18 | #pragma warning disable 612, 618 19 | modelBuilder.HasAnnotation("ProductVersion", "6.0.8"); 20 | 21 | modelBuilder.Entity("WanBot.Plugin.WanCoin.WanCoinHash", b => 22 | { 23 | b.Property("Hash") 24 | .HasColumnType("INTEGER"); 25 | 26 | b.Property("GroupId") 27 | .HasColumnType("INTEGER"); 28 | 29 | b.Property("Str") 30 | .IsRequired() 31 | .HasColumnType("TEXT"); 32 | 33 | b.HasKey("Hash"); 34 | 35 | b.ToTable("CoinHash"); 36 | }); 37 | 38 | modelBuilder.Entity("WanBot.Plugin.WanCoin.WanCoinUser", b => 39 | { 40 | b.Property("UserId") 41 | .HasColumnType("INTEGER"); 42 | 43 | b.Property("CoinCount") 44 | .HasColumnType("INTEGER"); 45 | 46 | b.HasKey("UserId"); 47 | 48 | b.ToTable("Users"); 49 | }); 50 | #pragma warning restore 612, 618 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /WanBot.Plugin.WanCoin/Migrations/20221009071933_InitialCreate.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | 3 | #nullable disable 4 | 5 | namespace WanBot.Plugin.WanCoin.Migrations 6 | { 7 | public partial class InitialCreate : Migration 8 | { 9 | protected override void Up(MigrationBuilder migrationBuilder) 10 | { 11 | migrationBuilder.CreateTable( 12 | name: "CoinHash", 13 | columns: table => new 14 | { 15 | Hash = table.Column(type: "INTEGER", nullable: false), 16 | Str = table.Column(type: "TEXT", nullable: false), 17 | GroupId = table.Column(type: "INTEGER", nullable: false) 18 | }, 19 | constraints: table => 20 | { 21 | table.PrimaryKey("PK_CoinHash", x => x.Hash); 22 | }); 23 | 24 | migrationBuilder.CreateTable( 25 | name: "Users", 26 | columns: table => new 27 | { 28 | UserId = table.Column(type: "INTEGER", nullable: false), 29 | CoinCount = table.Column(type: "INTEGER", nullable: false) 30 | }, 31 | constraints: table => 32 | { 33 | table.PrimaryKey("PK_Users", x => x.UserId); 34 | }); 35 | } 36 | 37 | protected override void Down(MigrationBuilder migrationBuilder) 38 | { 39 | migrationBuilder.DropTable( 40 | name: "CoinHash"); 41 | 42 | migrationBuilder.DropTable( 43 | name: "Users"); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /WanBot.Plugin.WanCoin/Migrations/20221022055158_AddTrade.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | 4 | #nullable disable 5 | 6 | namespace WanBot.Plugin.WanCoin.Migrations 7 | { 8 | public partial class AddTrade : Migration 9 | { 10 | protected override void Up(MigrationBuilder migrationBuilder) 11 | { 12 | migrationBuilder.CreateTable( 13 | name: "Trade", 14 | columns: table => new 15 | { 16 | Id = table.Column(type: "INTEGER", nullable: false) 17 | .Annotation("Sqlite:Autoincrement", true), 18 | User = table.Column(type: "INTEGER", nullable: false), 19 | Group = table.Column(type: "INTEGER", nullable: false), 20 | Time = table.Column(type: "TEXT", nullable: false), 21 | Price = table.Column(type: "TEXT", nullable: false), 22 | CoinCount = table.Column(type: "INTEGER", nullable: false), 23 | TotalCount = table.Column(type: "INTEGER", nullable: false), 24 | IsBuy = table.Column(type: "INTEGER", nullable: false) 25 | }, 26 | constraints: table => 27 | { 28 | table.PrimaryKey("PK_Trade", x => x.Id); 29 | }); 30 | } 31 | 32 | protected override void Down(MigrationBuilder migrationBuilder) 33 | { 34 | migrationBuilder.DropTable( 35 | name: "Trade"); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /WanBot.Plugin.WanCoin/WanBot.Plugin.WanCoin.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | $(SolutionDir)Bin/Plugin/ 8 | 9 | 10 | 11 | preview 12 | 13 | 14 | 15 | preview 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /WanBot.Plugin.WanCoin/WanCoinDatabase.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | #pragma warning disable CS8618 9 | namespace WanBot.Plugin.WanCoin 10 | { 11 | /// 12 | /// 虚犊币数据库 13 | /// 14 | public class WanCoinDatabase : DbContext 15 | { 16 | /// 17 | /// 虚犊币用户 18 | /// 19 | public DbSet Users { get; set; } 20 | 21 | /// 22 | /// 虚犊币Hash记录 23 | /// 24 | public DbSet CoinHash { get; set; } 25 | 26 | /// 27 | /// 虚犊币交易记录 28 | /// 29 | public DbSet Trade { get; set; } 30 | 31 | public string DbPath { get; } 32 | 33 | public WanCoinDatabase(string dbPath = "database.db") 34 | { 35 | DbPath = dbPath; 36 | } 37 | 38 | protected override void OnConfiguring(DbContextOptionsBuilder options) 39 | => options.UseSqlite($"Data Source={DbPath}"); 40 | } 41 | } 42 | #pragma warning restore CS8618 43 | -------------------------------------------------------------------------------- /WanBot.Plugin.WanCoin/WanCoinHash.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | #pragma warning disable CS8618 10 | namespace WanBot.Plugin.WanCoin 11 | { 12 | /// 13 | /// 虚犊币Hash记录 14 | /// 15 | public class WanCoinHash 16 | { 17 | /// 18 | /// hash记录,采用long以便于查询 19 | /// 20 | [Key, DatabaseGenerated(DatabaseGeneratedOption.None)] 21 | public long Hash { get; internal set; } 22 | 23 | /// 24 | /// 字符串记录 25 | /// 26 | public string Str { get; set; } = string.Empty; 27 | 28 | /// 29 | /// 字符串所在群 30 | /// 31 | public long GroupId { get; set; } 32 | } 33 | } 34 | #pragma warning restore CS8618 -------------------------------------------------------------------------------- /WanBot.Plugin.WanCoin/WanCoinTrade.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Numerics; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace WanBot.Plugin.WanCoin 9 | { 10 | /// 11 | /// 记录虚犊币交易 12 | /// 13 | public class WanCoinTrade 14 | { 15 | /// 16 | /// 交易Id 17 | /// 18 | public long Id { get; internal set; } 19 | 20 | /// 21 | /// 用户Id 22 | /// 23 | public long User { get; set; } 24 | 25 | /// 26 | /// 交易所在的群 27 | /// 28 | public long Group { get; set; } 29 | 30 | /// 31 | /// 交易时间 32 | /// 33 | public DateTime Time { get; set; } 34 | 35 | /// 36 | /// 价格 37 | /// 38 | public string Price { get; set; } = "0"; 39 | 40 | /// 41 | /// 币数 42 | /// 43 | public long CoinCount { get; set; } 44 | 45 | /// 46 | /// 服务器总币数 47 | /// 48 | public long TotalCount { get; set; } 49 | 50 | /// 51 | /// 是否为购买 52 | /// 53 | public bool IsBuy { get; set; } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /WanBot.Plugin.WanCoin/WanCoinUser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | #pragma warning disable CS8618 10 | namespace WanBot.Plugin.WanCoin 11 | { 12 | /// 13 | /// 虚犊币用户 14 | /// 15 | public class WanCoinUser 16 | { 17 | [Key, DatabaseGenerated(DatabaseGeneratedOption.None)] 18 | public long UserId { get; internal set; } 19 | 20 | /// 21 | /// 币数 22 | /// 23 | public long CoinCount { get; set; } 24 | } 25 | } 26 | #pragma warning restore CS8618 -------------------------------------------------------------------------------- /WanBot.Plugin.YGO/CardEnum/CardAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace WanBot.Plugin.YGO.CardEnum 2 | { 3 | public enum CardAttribute 4 | { 5 | Unknown = 0x0, 6 | Earth = 0x01, 7 | Water = 0x02, 8 | Fire = 0x04, 9 | Wind = 0x08, 10 | Light = 0x10, 11 | Dark = 0x20, 12 | Divine = 0x40, 13 | } 14 | 15 | public enum TwoNameCards 16 | { 17 | CARD_MARINE_DOLPHIN = 78734254, 18 | CARD_TWINKLE_MOSS = 13857930, 19 | } 20 | } -------------------------------------------------------------------------------- /WanBot.Plugin.YGO/CardEnum/CardLimitOt.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.Plugin.YGO.CardEnum 8 | { 9 | public enum CardLimitOt 10 | { 11 | OCG = 0x01, 12 | TCG = 0x02, 13 | Custom = 0x04, 14 | SimpleChinese = 0x08 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /WanBot.Plugin.YGO/CardEnum/CardLinkMarker.cs: -------------------------------------------------------------------------------- 1 | namespace WanBot.Plugin.YGO.CardEnum 2 | { 3 | public enum CardLinkMarker 4 | { 5 | BottomLeft = 0x01, 6 | Bottom = 0x02, 7 | BottomRight = 0x04, 8 | Left = 0x08, 9 | 10 | Right = 0x20, 11 | TopLeft = 0x40, 12 | Top = 0x80, 13 | TopRight = 0x100 14 | } 15 | } -------------------------------------------------------------------------------- /WanBot.Plugin.YGO/CardEnum/CardLocation.cs: -------------------------------------------------------------------------------- 1 | namespace WanBot.Plugin.YGO.CardEnum 2 | { 3 | public enum CardLocation 4 | { 5 | Deck = 0x01, 6 | Hand = 0x02, 7 | MonsterZone = 0x04, 8 | SpellZone = 0x08, 9 | Grave = 0x10, 10 | Removed = 0x20, 11 | Extra = 0x40, 12 | Overlay = 0x80, 13 | Onfield = 0x0C, 14 | 15 | Unknown = 0, 16 | Search = 0x800 17 | } 18 | } -------------------------------------------------------------------------------- /WanBot.Plugin.YGO/CardEnum/CardPosition.cs: -------------------------------------------------------------------------------- 1 | namespace WanBot.Plugin.YGO.CardEnum 2 | { 3 | public enum CardPosition 4 | { 5 | FaceUpAttack = 0x1, 6 | FaceDownAttack = 0x2, 7 | FaceUpDefence = 0x4, 8 | FaceDownDefence = 0x8, 9 | FaceUp = 0x5, 10 | FaceDown = 0xA, 11 | Attack = 0x3, 12 | Defence = 0xC 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /WanBot.Plugin.YGO/CardEnum/CardRace.cs: -------------------------------------------------------------------------------- 1 | namespace WanBot.Plugin.YGO.CardEnum 2 | { 3 | public enum CardRace 4 | { 5 | Unknown = 0x0, 6 | Warrior = 0x1, 7 | SpellCaster = 0x2, 8 | Fairy = 0x4, 9 | Fiend = 0x8, 10 | Zombie = 0x10, 11 | Machine = 0x20, 12 | Aqua = 0x40, 13 | Pyro = 0x80, 14 | Rock = 0x100, 15 | WindBeast = 0x200, 16 | Plant = 0x400, 17 | Insect = 0x800, 18 | Thunder = 0x1000, 19 | Dragon = 0x2000, 20 | Beast = 0x4000, 21 | BestWarrior = 0x8000, 22 | Dinosaur = 0x10000, 23 | Fish = 0x20000, 24 | SeaSerpent = 0x40000, 25 | Reptile = 0x80000, 26 | Psycho = 0x100000, 27 | DivineBeast = 0x200000, 28 | CreatorGod = 0x400000, 29 | Wyrm = 0x800000, 30 | Cyberse = 0x1000000 31 | } 32 | } -------------------------------------------------------------------------------- /WanBot.Plugin.YGO/CardEnum/CardType.cs: -------------------------------------------------------------------------------- 1 | namespace WanBot.Plugin.YGO.CardEnum 2 | { 3 | public enum CardType 4 | { 5 | Unknown = 0x0, 6 | Monster = 0x1, 7 | Spell = 0x2, 8 | Trap = 0x4, 9 | Normal = 0x10, 10 | Effect = 0x20, 11 | Fusion = 0x40, 12 | Ritual = 0x80, 13 | TrapMonster = 0x100, 14 | Spirit = 0x200, 15 | Union = 0x400, 16 | Dual = 0x800, 17 | Tuner = 0x1000, 18 | Synchro = 0x2000, 19 | Token = 0x4000, 20 | QuickPlay = 0x10000, 21 | Continuous = 0x20000, 22 | Equip = 0x40000, 23 | Field = 0x80000, 24 | Counter = 0x100000, 25 | Flip = 0x200000, 26 | Toon = 0x400000, 27 | Xyz = 0x800000, 28 | Pendulum = 0x1000000, 29 | SpSummon = 0x2000000, 30 | Link = 0x4000000 31 | } 32 | } -------------------------------------------------------------------------------- /WanBot.Plugin.YGO/WanBot.Plugin.YGO.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | $(SolutionDir)Bin/Plugin/ 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /WanBot.Plugin.YGO/YgoCardImage.cs: -------------------------------------------------------------------------------- 1 | using SkiaSharp; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace WanBot.Plugin.YGO 9 | { 10 | public static class YgoCardImage 11 | { 12 | private static HttpClient _httpClient = new(); 13 | public static string CachePath = string.Empty; 14 | 15 | /// 16 | /// 获取图像下载链接 17 | /// 18 | /// 19 | /// 20 | private static string GetCardImageUrl(int id) 21 | { 22 | return $"https://cdn02.moecube.com:444/ygomobile-images/{id}.png"; 23 | } 24 | 25 | public static async Task GetCardImagePathAsync(int id) 26 | { 27 | if (!string.IsNullOrEmpty(CachePath) && 28 | !Directory.Exists(CachePath)) 29 | Directory.CreateDirectory(CachePath); 30 | var path = Path.Combine(CachePath, $"{id}.png"); 31 | if (string.IsNullOrEmpty(CachePath) || !File.Exists(path)) 32 | { 33 | using var response = await _httpClient.GetAsync(GetCardImageUrl(id)); 34 | if (!response.IsSuccessStatusCode) 35 | return null; 36 | 37 | using var data = SKData.Create(response.Content.ReadAsStream()); 38 | using var cacheStream = File.Create(path); 39 | data.SaveTo(cacheStream); 40 | } 41 | return path; 42 | } 43 | 44 | public static async Task LoadFromIdAsync(int id) 45 | { 46 | var path = await GetCardImagePathAsync(id); 47 | if (string.IsNullOrEmpty(path)) 48 | return null; 49 | using var data = SKData.Create(path); 50 | return SKImage.FromEncodedData(data); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /WanBot.Test/EventFriendSerializeTest.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 | using WanBot.Test.Util; 8 | 9 | namespace WanBot.Test 10 | { 11 | /// 12 | /// Bot事件事件序列化测试 13 | /// 14 | [TestClass] 15 | public class EventFriendSerializeTest 16 | { 17 | [TestMethod] 18 | public void TestFriendInputStatusChangedEventProtocol() 19 | { 20 | var json = 21 | """ 22 | { 23 | "type": "FriendInputStatusChangedEvent", 24 | "friend": { 25 | "id": 123123, 26 | "nickname": "nick", 27 | "remark": "remark" 28 | }, 29 | "inputting": true 30 | } 31 | """; 32 | JsonHelper.TestJsonSerialization(json); 33 | JsonHelper.TestJsonSerialization(json); 34 | } 35 | 36 | [TestMethod] 37 | public void TestFriendNickChangedEventProtocol() 38 | { 39 | var json = 40 | """ 41 | { 42 | "type": "FriendNickChangedEvent", 43 | "friend": { 44 | "id": 123123, 45 | "nickname": "nick", 46 | "remark": "remark" 47 | }, 48 | "from": "origin nickname", 49 | "to": "new nickname" 50 | } 51 | """; 52 | JsonHelper.TestJsonSerialization(json); 53 | JsonHelper.TestJsonSerialization(json); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /WanBot.Test/MessageChainSerializeTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GScience/WanBot/744dd6b3f389e35e20061fac3ffd8512aa23f193/WanBot.Test/MessageChainSerializeTest.cs -------------------------------------------------------------------------------- /WanBot.Test/Usings.cs: -------------------------------------------------------------------------------- 1 | global using Microsoft.VisualStudio.TestTools.UnitTesting; -------------------------------------------------------------------------------- /WanBot.Test/WanBot.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 8 | false 9 | 10 | 11 | 12 | preview 13 | 14 | 15 | 16 | preview 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /WanBot/Logger.cs: -------------------------------------------------------------------------------- 1 | using Serilog; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using WanBot.Api; 8 | 9 | namespace WanBot 10 | { 11 | public class Logger : Api.ILogger 12 | { 13 | private const string DefaultConsoleOutputTemplate = "[{Timestamp:HH:mm:ss} {Level:u3}] [{Category}] {Message:lj}{NewLine}{Exception}"; 14 | private static readonly Serilog.Core.Logger _globalLogger; 15 | 16 | static Logger() 17 | { 18 | _globalLogger = new LoggerConfiguration() 19 | .MinimumLevel.Debug() 20 | .WriteTo.Console(outputTemplate: DefaultConsoleOutputTemplate) 21 | .CreateLogger(); 22 | } 23 | 24 | private string _category; 25 | private Serilog.ILogger _logger; 26 | 27 | internal Logger(string category) 28 | { 29 | _category = category; 30 | _logger = _globalLogger.ForContext("Category", _category); 31 | } 32 | 33 | /// 34 | /// 绑定日志目录 35 | /// 36 | /// 37 | internal void SetCategory(string category) 38 | { 39 | _logger = _globalLogger.ForContext("Category", category); 40 | } 41 | 42 | public Logger CreateSubLogger(string subCategory) 43 | { 44 | return new Logger($"_category.{subCategory}"); 45 | } 46 | 47 | public void Error(string message, params object?[]? args) 48 | { 49 | _logger.Error(message, args); 50 | } 51 | 52 | public void Fatal(string message, params object?[]? args) 53 | { 54 | _logger.Fatal(message, args); 55 | } 56 | 57 | public void Info(string message, params object?[]? args) 58 | { 59 | _logger.Information(message, args); 60 | } 61 | 62 | public void Warn(string message, params object?[]? args) 63 | { 64 | _logger.Warning(message, args); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /WanBot/PluginChangeListener.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 8 | { 9 | /// 10 | /// 插件变动监听器 11 | /// 12 | internal class PluginChangeListener : IDisposable 13 | { 14 | public event Action? OnPluginChange; 15 | 16 | private FileSystemWatcher _fileSystemWatcher; 17 | 18 | public PluginChangeListener(string pluginDir) 19 | { 20 | _fileSystemWatcher = new(pluginDir); 21 | _fileSystemWatcher.Path = pluginDir; 22 | _fileSystemWatcher.Created += OnChanged; 23 | _fileSystemWatcher.Changed += OnChanged; 24 | _fileSystemWatcher.Deleted += OnChanged; 25 | _fileSystemWatcher.EnableRaisingEvents = true; 26 | } 27 | 28 | private void OnChanged(object s, FileSystemEventArgs e) 29 | { 30 | if (e.FullPath.EndsWith(".dll", true, null)) 31 | OnPluginChange?.Invoke(e.FullPath); 32 | } 33 | 34 | public void Dispose() 35 | { 36 | _fileSystemWatcher.Dispose(); 37 | GC.SuppressFinalize(this); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /WanBot/Program.cs: -------------------------------------------------------------------------------- 1 | Console.WriteLine("Start"); 2 | WanBot.BotDomain.Launch(args); 3 | Console.WriteLine("Exit"); 4 | return 0; -------------------------------------------------------------------------------- /WanBot/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "WanBot": { 4 | "commandName": "Project", 5 | "commandLineArgs": "-config \"$(SolutionDir)Bin/Config/\" -plugin \"$(SolutionDir)Bin/Plugin/$(Configuration)/$(TargetFramework)\"" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /WanBot/Util/ConfigHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Text.Json; 6 | using System.Text.Json.Serialization; 7 | using System.Threading.Tasks; 8 | 9 | namespace WanBot.Util 10 | { 11 | /// 12 | /// 配置助手 13 | /// 14 | internal static class ConfigHelper 15 | { 16 | private static JsonSerializerOptions _options; 17 | 18 | static ConfigHelper() 19 | { 20 | _options = new() 21 | { 22 | WriteIndented = true, 23 | AllowTrailingCommas = true 24 | }; 25 | } 26 | 27 | /// 28 | /// 读取配置,若不存在则创建 29 | /// 30 | /// 31 | /// 32 | /// 33 | public static T ReadConfigFromFile(string fullPath) where T : new() 34 | { 35 | if (File.Exists(fullPath)) 36 | { 37 | using var ifs = File.OpenRead(fullPath); 38 | return JsonSerializer.Deserialize(ifs)!; 39 | } 40 | 41 | var fileInfo = new FileInfo(fullPath); 42 | 43 | if (!fileInfo.Directory!.Exists) 44 | Directory.CreateDirectory(fileInfo.DirectoryName!); 45 | 46 | var conf = new T(); 47 | using var ofs = File.Create(fullPath); 48 | JsonSerializer.Serialize(ofs, conf, _options); 49 | return conf; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /WanBot/WanBot.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; 7 | 8 | namespace WanBot 9 | { 10 | public class WanBot : WanBotPlugin 11 | { 12 | public override string PluginName => "WanBot"; 13 | 14 | public override string PluginAuthor => "WanNeng"; 15 | 16 | public override string PluginDescription => "完犊子Bot,负责对插件进行管理以及和Mirai的连接"; 17 | 18 | public override Version PluginVersion => GetType().Assembly.GetName().Version ?? Version.Parse("1.0.0"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /WanBot/WanBot.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | preview 12 | true 13 | 14 | 15 | 16 | preview 17 | true 18 | 19 | 20 | 21 | 22 | 23 | all 24 | runtime; build; native; contentfiles; analyzers; buildtransitive 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /WanBot/WanBotConfig.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 9 | { 10 | /// 11 | /// 完犊子Bot配置 12 | /// 13 | public class WanBotConfig 14 | { 15 | public List MiraiConfigs { get; set; } = new() 16 | { 17 | new MiraiConfig() 18 | }; 19 | 20 | public bool EnableAutoReload { get; set; } = false; 21 | } 22 | } 23 | --------------------------------------------------------------------------------