Mirai-CSharp.HttpApi
2.1.0
See the version list below for details.
dotnet add package Mirai-CSharp.HttpApi --version 2.1.0
NuGet\Install-Package Mirai-CSharp.HttpApi -Version 2.1.0
<PackageReference Include="Mirai-CSharp.HttpApi" Version="2.1.0" />
paket add Mirai-CSharp.HttpApi --version 2.1.0
#r "nuget: Mirai-CSharp.HttpApi, 2.1.0"
// Install Mirai-CSharp.HttpApi as a Cake Addin #addin nuget:?package=Mirai-CSharp.HttpApi&version=2.1.0 // Install Mirai-CSharp.HttpApi as a Cake Tool #tool nuget:?package=Mirai-CSharp.HttpApi&version=2.1.0
<div align="center"> <h1>Mirai-CSharp</h1> </div> <div align="center"> <a href="https://www.nuget.org/packages/Mirai-CSharp"> <img src="https://img.shields.io/nuget/v/Mirai-CSharp"/ ></a> <a href="https://www.nuget.org/packages/Mirai-CSharp"> <img src="https://img.shields.io/nuget/vpre/Mirai-CSharp"></a> <a href="https://www.nuget.org/packages/Mirai-CSharp"> <img src="https://img.shields.io/nuget/dt/Mirai-CSharp"></a> <img src="https://img.shields.io/github/last-commit/Executor-Cheng/Mirai-CSharp"> <img src="https://img.shields.io/github/stars/Executor-Cheng/Mirai-CSharp"> </div>
关于本项目
这是一个帮助C#开发者与 Mirai 交互的项目
它通过调用 mirai-api-http 提供的 http-api 与其交互
开始使用
安装
最简单的方式是从 nuget 上获取 Mirai-CSharp 包, 并且我们也推荐你在 nuget 包管理器中为项目安装它, 不过你也可以手动克隆项目, 编译, 并直接引用链接库.
在使用 nuget 安装包时, 如若要使用最新功能, 请勾选 "包括发行版"
注意, 最新版本已将包分离为 Mirai-CSharp 以及 Mirai-CSharp.HttpApi, 其中第一个中只包含程序接口之类的, 第二个中包含的是其实现, 并且在该预览版中, 与正式版发布的内容差异较大, 项目结构有巨大改变
示例
下面以一个最简单的控制台程序为示例, 对 QQ 内的任何 at 自己了的群聊消息响应 "Hello world" 文本消息
在目前已正式发布的最新版本中, Mirai-CSharp 的常用核心组件位于 Mirai_CSharp 以及 Mirai_CSharp.Models 命名空间中.
首先我们可以引用它, 下面是基础框架:
using System;
using System.Linq;
using Mirai.CSharp;
using Mirai.CSharp.Models;
namespace TestProj
{
class Program
{
static void Main(string[] args)
{
}
}
}
Mirai-CSharp 是要与 Mirai 的 mira-http-api 进行交互的, 所以我们接下来创建一个会话(Session), 并连接到在 Mirai 中已经登录的 QQ
// 下面是位于 Main 方法的代码
MiraiHttpSession session = new MiraiHttpSession(); // 创建会话
session.ConnectAsync( // 连接并等待
new MiraiHttpSessionOptions("localhost", 1234, "authKey"), // 连接选项, 地址, 端口, 以及验证密钥, 这些均位于 mirai-http-api 配置文件中
1234567890).Wait(); // Mirai 中已经登录的 QQ 机器人的 QQ 号码
下面为 session 添加群聊成员消息时间的处理方法:
// 下面是位于 Main 方法的代码
session.GroupMessageEvt += async (sender, e) =>
{
await sender.SendGroupMessageAsync(e.Sender.Group.Id, new PlainMessage("Hello world")); // 在消息发送者所在的群聊内发送 Hello world
return false;
};
session.GroupMessageEvt += async (sender, e) => // Mirai-CSharp 的事件处理应该是纯异步的, 我们应该使用异步方法(返回Task<bool>)
{
if (e.Chain.Where(v => v is AtMessage atMsg && atMsg.Target == session.QQNumber).Any()) // 判断是否 at 自己
await sender.SendGroupMessageAsync(e.Sender.Group.Id, new PlainMessage("Hello world")); // 发送 "Hello world"
// PlainMessage 位于 Mirai_CSharp.Models 命名空间下, 基于 IMessage
return false; // Task 的返回结果标识当前事件是否被阻断, 如果返回 true, 那么后面的事件订阅者将不会收到事件 (这里返回false表示不阻断)
};
改动
在当前的最新版本(预览版)中, 包已经分离开来, 由旧的只有一个 "Mirai-CSharp" 就包含所有功能, 变更为 "Mirai-CSharp" 提供基本接口, "Mirai-CSharp.HttpApi" 提供接口实现.
并且一些类型的命名空间也有所改动, 例如原来的 MiraiHttpSession 被移动到 Mirai.CSharp.HttpApi.Models 命名空间. 所以在使用最新预览版时应注意命名空间的更改.
注意事项
- 本项目使用
C# 9.0
编写, 你需要至少.NET Core 2.0
或.NET Framework 4.6.1
才能使用本项目, 其中所有的api均为异步方法
使用例子
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 is compatible. netcoreapp3.1 is compatible. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 3.0
- Mirai-CSharp (>= 2.1.0)
- Mirai-CSharp.NativeAssets.Win32 (>= 1.0.2)
- SkiaSharp (>= 2.80.3)
-
.NETCoreApp 3.1
- Mirai-CSharp (>= 2.1.0)
- Mirai-CSharp.NativeAssets.Win32 (>= 1.0.2)
- SkiaSharp (>= 2.80.3)
-
.NETStandard 2.0
- Mirai-CSharp (>= 2.1.0)
- Mirai-CSharp.NativeAssets.Win32 (>= 1.0.2)
- SkiaSharp (>= 2.80.3)
- System.Text.Json (>= 5.0.2)
-
.NETStandard 2.1
- Mirai-CSharp (>= 2.1.0)
- Mirai-CSharp.NativeAssets.Win32 (>= 1.0.2)
- SkiaSharp (>= 2.80.3)
- System.Text.Json (>= 5.0.2)
-
net5.0
- Mirai-CSharp (>= 2.1.0)
- Mirai-CSharp.NativeAssets.Win32 (>= 1.0.2)
- SkiaSharp (>= 2.80.3)
-
net6.0
- Mirai-CSharp (>= 2.1.0)
- Mirai-CSharp.NativeAssets.Win32 (>= 1.0.2)
- SkiaSharp (>= 2.80.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on Mirai-CSharp.HttpApi:
Repository | Stars |
---|---|
GardenHamster/Theresa3rd-Bot
一个QQ群聊机器人,基于Mirai和GoCQHttp,包括 Pixiv搜索、Pixiv推送、Pixiv日榜、词云、定时提醒、复读机等功能
|
|
Alex1911-Jiang/GreenOnions
一个Mirai的QQ机器人, 实现了搜图, RSS订阅转发, 根据PixivID下载原图, 翻译, setu等功能
|
Version | Downloads | Last updated |
---|---|---|
2.1.9 | 620 | 12/31/2022 |
2.1.9-preview.1 | 221 | 10/18/2022 |
2.1.8 | 517 | 8/24/2022 |
2.1.7 | 662 | 5/22/2022 |
2.1.7-preview.1 | 137 | 5/16/2022 |
2.1.6 | 437 | 5/15/2022 |
2.1.6-preview.1 | 184 | 3/22/2022 |
2.1.5 | 478 | 3/14/2022 |
2.1.4 | 521 | 1/30/2022 |
2.1.4-preview.1 | 147 | 1/24/2022 |
2.1.3 | 451 | 1/18/2022 |
2.1.2 | 325 | 12/14/2021 |
2.1.1 | 593 | 12/4/2021 |
2.1.0 | 285 | 11/29/2021 |
2.0.0 | 336 | 11/9/2021 |
2.0.0-rc.2 | 158 | 11/2/2021 |
2.0.0-rc.1 | 180 | 9/23/2021 |
2.0.0-preview.2 | 232 | 9/10/2021 |