Misskey.Net 1.0.0

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Misskey.Net --version 1.0.0
                    
NuGet\Install-Package Misskey.Net -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="Misskey.Net" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Misskey.Net" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Misskey.Net" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Misskey.Net --version 1.0.0
                    
#r "nuget: Misskey.Net, 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.
#:package Misskey.Net@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Misskey.Net&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Misskey.Net&version=1.0.0
                    
Install as a Cake Tool

Yet Another Misskey API Library for .NET (WIP)

Misskey API の .NET ライブラリの別実装です.

既存のライブラリとしては公式の実装 Misq があります. 本ライブラリでは上記ライブラリの機能に加え,MiAuth 認証方式への対応とストリーミング API のラップを提供しています.

Installation

NuGet から利用できます.

Usage

src/Example/FSharp/Program.fs および src/Example/CSharp/Program.cs にサンプルコードがあります.

F#

open Misskey.Net.Uri
open Misskey.Net.HttpApi
open Misskey.Net.StreamingApi

open System.Net.Http
open Microsoft.Extensions.DependencyInjection
open System.Net.WebSockets

//

// Name of this app.
let appName = "Example App"

// Hostname of Misskey instance.
let host = "misskey.systems"

//

let client =
    ServiceCollection() // Create DI container.
        .AddHttpClient() // Add HttpClient to DI container.
        .BuildServiceProvider() // Build DI container.
        .GetService<IHttpClientFactory>() // Get IHttpClientFactory from DI container.

// Create HttpApi instance.
let httpApi = HttpApi(scheme = Https, host = host, client = client)

// Get stats of Misskey instance.
let stats =
    httpApi.RequestApiAsync [ "stats" ] |> Async.AwaitTask |> Async.RunSynchronously

printfn "stats: %s" <| stats.ToString()

let auth =
    task {
        // Authorize this app to Misskey instance with permission `read:account` (but not required).
        do! httpApi.AuthorizeAsync(name = appName, permissions = [| Permission.Read <| PermissionKind.Account() |])

        // Wait for authorization.
        return! httpApi.WaitCheckAsync()
    }
    |> Async.AwaitTask
    |> Async.RunSynchronously

if auth = false then
    failwith "authorization failed"

task {
    // Create StreamingApi instance.
    use streamingApi =
        new StreamingApi(httpApi = httpApi, webSocket = new ClientWebSocket())

    // Connect to Misskey instance.
    do! streamingApi.ConnectStreamingAsync()

    printfn "connected"

    // Connect to global timeline.
    let! _channelConnection = streamingApi.ConnectChannelAsync(Channel.GlobalTimeline())

    while true do
        // Subscribe to global timeline.
        let! result = streamingApi.ReceiveAsync()

        let content = result.["body"]

        let body = if content = null then null else content.["body"]

        if body <> null then

            let user = body.["user"]

            let nameNode = if user = null then null else user.["name"]

            let name = if nameNode = null then "<unknown>" else nameNode.ToString()

            let renote = body.["renote"]

            if renote = null then
                printfn "-- text --"

                printfn "user: %s" <| name

                let text = body.["text"]

                if text <> null then
                    printfn "text: %s" <| text.ToString()
                else
                    printfn "text: <image only>"
            else
                printfn "-- renote --"

                let text = renote.["text"]

                let renotedUser = renote.["user"]

                let renotedNameNode = if renotedUser = null then null else renotedUser.["name"]

                let renotedName =
                    if renotedNameNode = null then
                        "<unknown>"
                    else
                        renotedNameNode.ToString()

                printfn "user: %s" <| renotedName

                printfn "renoted by: %s" <| name

                if text <> null then
                    printfn "text: %s" <| text.ToString()
                else
                    printfn "text: <image only>"
        else
            printfn "unknown"

    return ()
}
|> Async.AwaitTask
|> Async.RunSynchronously

C#

using Misskey.Net.Uri;
using Misskey.Net.HttpApi;
using Misskey.Net.StreamingApi;

using System.Net.Http;
using Microsoft.Extensions.DependencyInjection;
using System.Net.WebSockets;

//

// Name of this app.
var appName = "Example app";

// Hostname of Misskey instance.
var host = "misskey.systems";

//

var client =
    new ServiceCollection() // Create DI container.
        .AddHttpClient() // Add HttpClient to DI container.
        .BuildServiceProvider() // Build DI container.
        .GetService<IHttpClientFactory>(); // Get IHttpClientFactory from DI container.

// Create HttpApi instance.
var httpApi = new HttpApi(scheme: Misskey.Net.Uri.Scheme.Https, host: host, client: client);

//

// Get stats of Misskey instance
var stats = await httpApi.RequestApiAsync(new[] { "stats" });

Console.WriteLine($"stats: {stats}");

//

// Authorize this app to Misskey instance with permission `read:account` (but not required).
await httpApi.AuthorizeAsync(name: appName, permissions: new[] { Permission.NewRead(new PermissionKind.Account()) });

// Wait for authorization.
var check = await httpApi.WaitCheckAsync();

if (!check)
{
    Console.WriteLine("authorization failed");
}

Console.WriteLine("authorization completed");

//

// Create StreamingApi instance.
using var streamingApi = new StreamingApi(httpApi: httpApi, webSocket: new ClientWebSocket());

// Connect to Misskey instance.
await streamingApi.ConnectStreamingAsync();

Console.WriteLine("connected");

// Connect to global timeline.
var channelConnection = await streamingApi.ConnectChannelAsync(new Channel.GlobalTimeline());

while (true)
{
    // Subscribe to global timeline.
    var result = await streamingApi.ReceiveAsync();

    var content = result["body"];

    var body = content?["body"];

    if (body != null)
    {
        var user = body["user"];

        var nameNode = user?["name"];

        var name = (nameNode == null) ? "<unknown>" : nameNode.ToString();

        var renote = body["renote"];

        if (renote == null)
        {
            Console.WriteLine("-- text --");

            Console.WriteLine($"user: {name}");

            var text = body["text"];

            if (text != null)
            {
                Console.WriteLine($"text: {text}");
            }
            else
            {
                Console.WriteLine("text: <image only>");
            }
        }
        else
        {
            Console.WriteLine("-- renote --");

            var text = renote["text"];

            var renotedUser = renote["user"];

            var renotedNameNode = renotedUser?["name"];

            var renotedName = renotedNameNode == null ? "<unknown>" : renotedNameNode.ToString();

            Console.WriteLine($"user: {renotedName}");

            Console.WriteLine($"renoted by: {name}");

            if (text != null)
            {
                Console.WriteLine($"text: {text}");
            }
            else
            {
                Console.WriteLine("text: <image only>");
            }
        }
    }
    else
    {
        Console.WriteLine("unknown");
    }
}

License

MIT

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
2.0.0-alpha 224 7/28/2023
1.0.0 279 7/24/2023