ShamrockCore 1.0.0
Additional Details
此版本包存在图片通过url发送失败的bug
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package ShamrockCore --version 1.0.0
NuGet\Install-Package ShamrockCore -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ShamrockCore" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ShamrockCore --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ShamrockCore, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ShamrockCore as a Cake Addin #addin nuget:?package=ShamrockCore&version=1.0.0 // Install ShamrockCore as a Cake Tool #tool nuget:?package=ShamrockCore&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ShamrockCore.NET
注:目前还在测试阶段,可能会有bug,欢迎大家使用反馈,发现bug会快速修复。
简介
- 基于.NET 6开发,支持多平台。
- 是OpenShamrock在C#上的实现,理论支持基于onebot协议的机器人框架(OpenShamrock独有API除外,例如获取设备电池信息。)。
- 目录结构:
- ShamrockCore-主程序
- ShamrockCore.Test-测试程序
- 如果此项目对你有用,不妨给它点个Star,如果发现问题或者有不够完善的地方,欢迎大家提交PR和Issues。
快速开始
(注:由于还是测试版,所以暂不打算发布到nuget)
安装
- 下载请到releases界面下载dll文件。
- nuget安装下面两个库:Manganese和System.Reactive.Linq
开始
<details> <summary>名称空间引用</summary>
using Manganese.Text;
using ShamrockCore.Reciver;
using ShamrockCore.Reciver.Events;
using ShamrockCore.Reciver.MsgChain;
using ShamrockCore.Reciver.Receivers;
using ShamrockCore.Utils;
using System.Reactive.Linq;
</details>
初始化和启动:
var config = new ConnectConfig("Host", websocket_port, http_port, "token");
using Bot bot = new(config);
await bot.Start();
bot常用接口:
var friends = bot.Friends;//好友列表
var groups = bot.Groups;//群列表
var LoginInfo = bot.LoginInfo;//登录用户信息
var Battery = bot.Battery;//手机电池信息
var StartTime = bot.StartTime;//shamrock启动时间
websocket断开事件:
bot.DisconnectionHappened.Subscribe(e =>
{
Console.WriteLine("webscoket断开连接:" + e);
});
处理消息:
bot.MessageReceived.OfType<GroupReceiver>().Subscribe(async msg =>
{
foreach (var item in msg.Message)
{
if (item.Type == Data.Model.MessageType.Text)
var textMessage = item.ConvertTo<TextMessage>();
if (item.Type == Data.Model.MessageType.Image)
var imageMessage = item.ConvertTo<ImageMessage>();
}
var msgStr = msg.Message.GetPlainText();
await Console.Out.WriteLineAsync("好友消息:" + msg.ToJsonString());
//发送消息,被动。下面有主动的方法
msg.SendMessageAsync("太好辣,我收到消息辣。");
});
bot.MessageReceived.OfType<FriendReceiver>().Subscribe(async msg =>
{
await Console.Out.WriteLineAsync("好友消息:" + msg.ToJsonString());
});
处理事件:
bot.EventReceived.OfType<FriendAddEvent>().Subscribe(async msg =>
{
Console.WriteLine("好友请求事件:" + msg.ToJsonString());
await msg.Agree("好友备注");
await msg.Reject();
});
bot.EventReceived.OfType<GroupIncreaseEvent>().Subscribe(msg =>
{
Console.WriteLine("群成员增加事件:" + msg.ToJsonString());
});
未知消息:
bot.UnknownMessageReceived.Subscribe(msg =>
{
Console.WriteLine("未知消息:" + msg);
});
发送消息: 消息管理器是静态类,但是必须初始化bot后才可以用。
await MessageManager.SendGroupMsgAsync(111, "发送群消息");
await MessageManager.SendPrivateMsgAsync(111, "发送私聊消息");
var message = new MessageChain()
{
new TextMessage("群消息"),
new ImageMessage(url:"http://localhost/test.png")
};
await MessageManager.SendGroupMsgAsync(111, message);
var msgBuilder = new MessageChainBuilder().Text("私聊消息").Video("/Download/test.mp4");
message = msgBuilder.Build();
await MessageManager.SendPrivateMsgAsync(111, message);
阻塞线程:
while (true)
{
Thread.Sleep(10);//建议加上,如果单纯死循环的话,最导致cpu占用飙高。
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- Flurl (>= 3.0.7)
- Flurl.Http (>= 3.2.4)
- Manganese (>= 1.2.9)
- Newtonsoft.Json (>= 13.0.3)
- Websocket.Client (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
1.3.2 | 141 | 3/27/2024 | |
1.3.1 | 121 | 3/11/2024 | |
1.3.0 | 126 | 3/9/2024 | |
1.2.2-alpha | 114 | 3/2/2024 | |
1.2.1-alpha | 88 | 2/25/2024 | |
1.2.0 | 118 | 2/6/2024 | |
1.1.6 | 134 | 2/2/2024 | |
1.1.5 | 136 | 2/2/2024 | |
1.1.4 | 127 | 2/2/2024 | |
1.1.3 | 184 | 1/8/2024 | |
1.1.2 | 165 | 1/3/2024 | |
1.1.1 | 162 | 12/30/2023 | |
1.1.0 | 174 | 12/29/2023 | |
1.0.0 | 181 | 12/25/2023 |
正式发布!