Misskey.rb

A Ruby module for interacting with the Misskey API. Releases hosted on Rubygems. This is not affiliated with Syuilo in any way!!

Installation :neofox_science:

Either add it to your Gemfile:

gem "misskey"

or install it directly with Gem:

gem install misskey

Contributing :neofox_laptop:

Because it would be really difficult for me to implement every Misskey API feature, I would really appreciate contributions!

When contributing please make sure to follow these guidelines. These may change as time goes on:

1) No LLM-generated commits please! Vibecoded software tends to get really messy and introduce more issues than it solves. Also everything around LLMs are highly unethical and I don't want to support that. Thanks!

2) Please do not create multiple functions that do the same thing.

3) Follow common sense.

Thank you! :neofox_heart:

Using :neofox_notice:

I didn't have the energy to make a real wiki for this and I have no idea how to use the Rubygems documentation thingy so I just stuck it in one big readme. I am deeply sorry about this :neofox_googly_shocked:

Like I said in the contributing guide, this doesn't implement every Misskey API feature and if you want to see a feature added it would mean a lot to me if you could contribute! Thanks :neofox_heart:

All responses from the API are automatically parsed from JSON to a Ruby Array so you shouldn't need to worry about that.

Authentication (REQUIRED!!!)

Misskey.auth.instanceURI

This sets the instance URI that your client will connect to. This and Misskey.auth.token are required when using Misskey.rb.

This can be used like a variable. You can change it or access it at any time. See some examples below:

Changing the value:

require "misskey"

Misskey.auth.instanceURI = "sharkey.skydevs.me"

Calling the value:

require "misskey"

Misskey.auth.instanceURI = "sharkey.skydevs.me"

# Getting the value
puts Misskey.auth.instanceURI

Pretty simple :neofox_floof_happy:

Misskey.auth.token

This sets the API key/token that your client will connect to. This and Misskey.auth.instanceURI are required when using Misskey.rb.

This can be used like a variable. You can change it or access it at any time. See some examples below:

Changing the value:

require "misskey"

Misskey.auth.token = "blahblahtokenweeewooooooo"

Calling the value:

require "misskey"

Misskey.auth.token = "wafwaftokenaaaaaa"

# Getting the value
puts Misskey.auth.token

You can also use this in pair with the dotenv module:

require "misskey"
require "dotenv"

Dotenv.load "./.env"
Misskey.auth.token = ENV["APIKey"]

Also pretty simple :neofox_floof_happy:

Notes

Misskey.notes.create

Creates a note.

Order of arguments are as follows: noteContent also known as the body text (REQUIRED), visibility, localonly, cw also known as a content warning.

Visibility options include: public, home, followers, and specified. specified is also known as a direct note or private message.

Some examples:

require "misskey"

Misskey.auth.token = "tokenwaaaaaaa"
Misskey.auth.instanceURI = "sharkey.skydevs.me"

Misskey.notes.create "Hello world!! :neofox_floof:"

It will automatically convert things like ":neofox_floof:" to their respective emojis as seen above.

require "misskey"

Misskey.auth.token = "tokenwaaaaaaa"
Misskey.auth.instanceURI = "sharkey.skydevs.me"

Misskey.notes.create "Hello there, this is a home note.", "home"

The example above shows a client creating a note with the visibility "home"

require "misskey"

Misskey.auth.token = "tokenwaaaaaaa"
Misskey.auth.instanceURI = "sharkey.skydevs.me"

Misskey.notes.create "Hi this is local!", "public", true

The example above shows a client creating a public local (aka defederated) note.

require "misskey"

Misskey.auth.token = "tokenwaaaaaaa"
Misskey.auth.instanceURI = "sharkey.skydevs.me"

Misskey.notes.create "Hi this is local and features a content warning!", "public", true, "Holy moly it's a post by me wow beware"

As the note body suggests, this is a local note that has a content warning.

You may refer to the Misskey API docs for more info.

Misskey.notes.create.reply

Very similar to Misskey.notes.create except it features a new required argument called replyId.

Arguments for this are as follows: replyId (REQUIRED), noteContent (REQUIRED), visibility, localOnly, cw

An example:

require "misskey"

Misskey.auth.token = "tokenwaaaaaaa"
Misskey.auth.instanceURI = "sharkey.skydevs.me"

Misskey.notes.create.reply "someReplyId", "Hello there, this is a reply."

You may refer to the Misskey API docs for more info.

Misskey.notes.timeline

Retrieves the home timeline of the currently logged-in user I believe? Not too sure because I only tested it on a dummy account that doesn't follow anyone.

There is one optional argument which is limit. As the name suggests, it sets a limit to how many notes should be retrieved. By default it's set to 10.

Here's an example:

require "misskey"

Misskey.auth.token = "tokenwaaaaaaa"
Misskey.auth.instanceURI = "sharkey.skydevs.me"

puts Misskey.notes.timeline

You may refer to the Misskey API docs for more info.

Misskey.getOnlineUsersCount

Pretty self-explanatory, gets the number of users online. Using it is really simple, here's an example:

require "misskey"

Misskey.auth.token = "tokenwaaaaaaa"
Misskey.auth.instanceURI = "sharkey.skydevs.me"

puts "There are #{Misskey.getOnlineUsersCount} user(s) online right now!"

Slightly more complicated example:

require "misskey"

Misskey.auth.token = "tokenwaaaaaaa"
Misskey.auth.instanceURI = "sharkey.skydevs.me"

case Misskey.getOnlineUserscount.to_i
when 0
    puts "There are no users online :("
when 1
    puts "There is 1 user online."
when > 1
    puts "There are #{Misskey.getOnlineUserscount} users online"
end

You may refer to the Misskey API docs for more info.

Misskey.serverInfo

Retrieves the instance/server information. Example:

require "misskey"

Misskey.auth.token = "tokenwaaaaaaa"
Misskey.auth.instanceURI = "sharkey.skydevs.me"

puts Misskey.serverInfo

You may refer to the Misskey API docs for more info.

Misskey.i

Retrieves the information about the currently logged-in user. Example:

require "misskey"

Misskey.auth.token = "tokenwaaaaaaa"
Misskey.auth.instanceURI = "sharkey.skydevs.me"

puts Misskey.i

You may refer to the Misskey API docs for more info.

Misskey.i.notifications

Retrieves the currently logged-in user's notifications. Has one argument which is limit. By default, limit is set to 10. Here's an example

require "misskey"

Misskey.auth.token = "tokenwaaaaaaa"
Misskey.auth.instanceURI = "sharkey.skydevs.me"

puts Misskey.i.notifications

You may refer to the Misskey API docs for more info.

Websockets!! (THis is my favorite thing about this library :neofox_floof_cute:)

Misskey.websocket.connect

Connects your client to Misskey via the websocket protocol. Automatically runs in a separate thread. There is no documentation on websockets in the Misskey API docs but the JSON data it gives is in the same structure as doing a normal request to their documented API.

Notifications

Misskey.websocket.notifications.onMention

Used with a block; runs said block with an argument contianing the message when you recieve a mention notification.

Example:

require "misskey"

Misskey.auth.token = "tokenwaaaaaaa"
Misskey.auth.instanceURI = "sharkey.skydevs.me"

Misskey.websocket.connect

Misskey.websocket.notifications.onMention do |message|
    puts message
end

In this example, puts message will print the message JSON data in the terminal when it recieves a mention.

Misskey.websocket.notifications.onReaction

Used with a block; runs said block with an argument contianing the message when you recieve a reaction notification.

Example:

require "misskey"

Misskey.auth.token = "tokenwaaaaaaa"
Misskey.auth.instanceURI = "sharkey.skydevs.me"

Misskey.websocket.connect

Misskey.websocket.notifications.onReaction do |message|
    puts message
end

In this example, puts message will print the message JSON data in the terminal when it recieves a reaction.

Misskey.websocket.notifications.onRenote

Used with a block; runs said block with an argument contianing the message when you recieve a renote notification.

Example:

require "misskey"

Misskey.auth.token = "tokenwaaaaaaa"
Misskey.auth.instanceURI = "sharkey.skydevs.me"

Misskey.websocket.connect

Misskey.websocket.notifications.onRenote do |message|
    puts message
end

In this example, puts message will print the message JSON data in the terminal when it recieves a renote.

Misskey.websocket.notifications.onNotification

Used with a block; runs said block with an argument contianing the message when you recieve a notification.

Example:

require "misskey"

Misskey.auth.token = "tokenwaaaaaaa"
Misskey.auth.instanceURI = "sharkey.skydevs.me"

Misskey.websocket.connect

Misskey.websocket.notifications.onNotification do |message|
    puts message
end

In this example, puts message will print the message JSON data in the terminal when it recieves a notification.

Misskey.websocket.notifications.onQuote

Used with a block; runs said block with an argument contianing the message when you recieve a quote notification.

Example:

require "misskey"

Misskey.auth.token = "tokenwaaaaaaa"
Misskey.auth.instanceURI = "sharkey.skydevs.me"

Misskey.websocket.connect

Misskey.websocket.notifications.onQuote do |message|
    puts message
end

In this example, puts message will print the message JSON data in the terminal when it recieves a quote.

That's all!

Those are all the features currently implemented, but don't worry, more will be added as time goes on :neofox_heart: