misskey 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (7) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +73 -0
  3. data/README.md +3 -0
  4. data/lib/create.rb +69 -0
  5. data/lib/misskey.rb +188 -0
  6. data/lib/websocket.rb +74 -0
  7. metadata +94 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 71cbb354bf3e664aced3e95663daf3913fbc15164101b9e142c287b30ee8832c
4
+ data.tar.gz: 64b42af87b8adb89acf63b1127b7b33928f4eee6efd2ceea366ced0c3b46841e
5
+ SHA512:
6
+ metadata.gz: 36fbcabc078bc9802c708b1f9653a7a1677a29ab21433aa8ea34a95b90913945c975b33066e009ae948da8a44b52eafaab944eee34827c181d675628e0faaece
7
+ data.tar.gz: 9794cbf3ddaf2ae5bb4b2d8a2dd1a654d539f2be83cc5ef048178217bac8f60309c98c6b62b3f2b6ed4f89c5e251d570eb18e3bda6dce5123c43d0969119ba0e
data/LICENSE ADDED
@@ -0,0 +1,73 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
10
+
11
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
12
+
13
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
14
+
15
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
16
+
17
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
18
+
19
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
20
+
21
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
22
+
23
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
24
+
25
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
26
+
27
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
28
+
29
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
30
+
31
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
32
+
33
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
34
+
35
+ (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
36
+
37
+ (b) You must cause any modified files to carry prominent notices stating that You changed the files; and
38
+
39
+ (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
40
+
41
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
42
+
43
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
44
+
45
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
46
+
47
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
48
+
49
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
50
+
51
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
52
+
53
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
54
+
55
+ END OF TERMS AND CONDITIONS
56
+
57
+ APPENDIX: How to apply the Apache License to your work.
58
+
59
+ To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
60
+
61
+ Copyright 2026 Sky.Bit
62
+
63
+ Licensed under the Apache License, Version 2.0 (the "License");
64
+ you may not use this file except in compliance with the License.
65
+ You may obtain a copy of the License at
66
+
67
+ http://www.apache.org/licenses/LICENSE-2.0
68
+
69
+ Unless required by applicable law or agreed to in writing, software
70
+ distributed under the License is distributed on an "AS IS" BASIS,
71
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
72
+ See the License for the specific language governing permissions and
73
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Misskey.rb
2
+
3
+ A Ruby module for interacting with the Misskey API
data/lib/create.rb ADDED
@@ -0,0 +1,69 @@
1
+ module Creates
2
+ def created noteContent, visibility = "public", localOnly = false, cw = ""
3
+ instance = "https://#{Misskey.auth.instanceURI}/api/notes/create"
4
+ # Visibility: public, home, followers, specified
5
+ postJSON = <<~JSON
6
+ {
7
+ "visibility": "#{visibility}",
8
+ "visibleUserIds": [],
9
+ "cw": "#{cw}",
10
+ "localOnly": #{localOnly},
11
+ "reactionAcceptance": null,
12
+ "noExtractMentions": false,
13
+ "noExtractHashtags": false,
14
+ "noExtractEmojis": false,
15
+ "replyId": null,
16
+ "renoteId": null,
17
+ "channelId": null,
18
+ "text": "#{noteContent}"
19
+ }
20
+ JSON
21
+
22
+ response = HTTParty.post(
23
+ instance,
24
+ body: postJSON,
25
+ headers: {
26
+ 'Content-Type' => 'application/json',
27
+ "Authorization" => "Bearer #{Misskey.auth.token}"
28
+ }
29
+ )
30
+ if Misskey.debug.debugging
31
+ puts postJSON
32
+ puts response
33
+ end
34
+
35
+ def reply replyId, noteContent, visibility = "public", localOnly = false, cw = ""
36
+ instance = "https://#{Misskey.auth.instanceURI}/api/notes/create"
37
+ # Visibility: public, home, followers, specified
38
+ postJSON = <<~JSON
39
+ {
40
+ "visibility": "#{visibility}",
41
+ "visibleUserIds": [],
42
+ "cw": "#{cw}",
43
+ "localOnly": #{localOnly},
44
+ "reactionAcceptance": null,
45
+ "noExtractMentions": false,
46
+ "noExtractHashtags": false,
47
+ "noExtractEmojis": false,
48
+ "replyId": #{replyId},
49
+ "renoteId": null,
50
+ "channelId": null,
51
+ "text": "#{noteContent}"
52
+ }
53
+ JSON
54
+
55
+ response = HTTParty.post(
56
+ instance,
57
+ body: postJSON,
58
+ headers: {
59
+ 'Content-Type' => 'application/json',
60
+ "Authorization" => "Bearer #{Misskey.auth.token}"
61
+ }
62
+ )
63
+ if Misskey.debug.debugging
64
+ puts postJSON
65
+ puts response
66
+ end
67
+ end
68
+ end
69
+ end
data/lib/misskey.rb ADDED
@@ -0,0 +1,188 @@
1
+ require "httparty"
2
+ require "json"
3
+ require_relative "./create.rb"
4
+ include Creates
5
+ require "faye/websocket"
6
+ require "eventmachine"
7
+ require "rainbow"
8
+ require_relative "./websocket.rb"
9
+ include WS
10
+
11
+ module Misskey
12
+ @@token = nil
13
+ @@instanceURI = nil
14
+ @@onMentionDo = [false, nil]
15
+ @@debugging = false
16
+ @@onReactionDo = [false, nil]
17
+ @@onRenoteDo = [false, nil]
18
+ @@onNotificationDo = [false, nil]
19
+ @@onQuoteDo = [false, nil]
20
+
21
+ def auth
22
+ def token
23
+ return @@token
24
+ end
25
+
26
+ def token=(tkn)
27
+ @@token = tkn
28
+ end
29
+
30
+ def instanceURI
31
+ return @@instanceURI
32
+ end
33
+
34
+ def instanceURI=(uri)
35
+ @@instanceURI = uri
36
+ end
37
+ end
38
+
39
+ def debug
40
+ def debugging
41
+ return @@debugging
42
+ end
43
+
44
+ def debugging=(bool)
45
+ @@debugging = bool
46
+ end
47
+ end
48
+
49
+ def notes
50
+ def create noteContent, visibility = "public", localOnly = false, cw = ""
51
+ Creates.created noteContent, visibility = "public", localOnly = false, cw = ""
52
+
53
+ def reply replyId, noteContent, visibility = "public", localOnly = false, cw = ""
54
+ Creates.created.reply replyId, noteContent, visibility = "public", localOnly = false, cw = ""
55
+ end
56
+ end
57
+ end
58
+
59
+ def getOnlineUsersCount
60
+ instance = "https://#{Misskey.auth.instanceURI}/api/get-online-users-count"
61
+ postJSON = <<EOF
62
+ {
63
+ "Bah": "bahbooey"
64
+ }
65
+ EOF
66
+
67
+ request = HTTParty.post(
68
+ instance,
69
+ body: postJSON,
70
+ headers: {
71
+ "Content-Type" => "application/json"
72
+ }
73
+ )
74
+
75
+ return JSON.parse request.body
76
+ end
77
+
78
+ def serverInfo
79
+ instance = "https://#{Misskey.auth.instanceURI}/api/server-info"
80
+ postJSON = <<EOF
81
+ {
82
+ "Bah": "bahbooey"
83
+ }
84
+ EOF
85
+
86
+ request = HTTParty.post(
87
+ instance,
88
+ body: postJSON,
89
+ headers: {
90
+ "Content-Type" => "application/json"
91
+ }
92
+ )
93
+
94
+ return JSON.parse request.body
95
+ end
96
+
97
+ def i
98
+ instance = "https://#{Misskey.auth.instanceURI}/api/i"
99
+ postJSON = <<EOF
100
+ {
101
+ "Bah": "bahbooey"
102
+ }
103
+ EOF
104
+
105
+ request = HTTParty.post(
106
+ instance,
107
+ body: postJSON,
108
+ headers: {
109
+ "Content-Type" => "application/json",
110
+ "Authorization" => "Bearer #{Misskey.auth.token}"
111
+ }
112
+ )
113
+
114
+ def timeline limit = 100
115
+ instance = "https://#{Misskey.auth.instanceURI}/api/notes/timeline"
116
+
117
+ postJSON = <<EOF
118
+ {
119
+ "limit": #{limit}
120
+ }
121
+ EOF
122
+
123
+ request = HTTParty.post(
124
+ instance,
125
+ body: postJSON,
126
+ headers: {
127
+ "Content-Type" => "application/json",
128
+ "Authorization" => "Bearer #{Misskey.auth.token}"
129
+ }
130
+ )
131
+
132
+ return JSON.parse request.body
133
+ end
134
+
135
+ def notifications limit = 10
136
+ instance = "https://#{Misskey.auth.instanceURI}/api/i/notifications"
137
+
138
+ postJSON = <<EOF
139
+ {
140
+ "limit": #{limit}
141
+ }
142
+ EOF
143
+
144
+ request = HTTParty.post(
145
+ instance,
146
+ body: postJSON,
147
+ headers: {
148
+ "Content-Type" => "application/json",
149
+ "Authorization" => "Bearer #{Misskey.auth.token}"
150
+ }
151
+ )
152
+
153
+ return JSON.parse request.body
154
+ end
155
+
156
+ return JSON.parse request.body
157
+ end
158
+
159
+ def websocket
160
+ def connect
161
+ WS.c
162
+ end
163
+
164
+ def notifications
165
+ def onMention &block
166
+ WS.n.oM block
167
+ end
168
+
169
+ def onReaction &block
170
+ WS.n.oR block
171
+ end
172
+
173
+ def onRenote &block
174
+ WS.n.oRe block
175
+ end
176
+
177
+ def onNotification &block
178
+ WS.n.oN block
179
+ end
180
+
181
+ def onQuote &block
182
+ WS.n.oQ block
183
+ end
184
+ end
185
+ end
186
+ end
187
+
188
+ include Misskey
data/lib/websocket.rb ADDED
@@ -0,0 +1,74 @@
1
+ module WS
2
+ def c
3
+ Thread.start do
4
+ EM.run do
5
+ instance = "wss://#{Misskey.auth.instanceURI}/streaming?i=#{Misskey.auth.token}"
6
+ socket = Faye::WebSocket::Client.new instance
7
+
8
+ socket.onopen = lambda do |event|
9
+ puts Rainbow("Connected to websocket successfully.").green
10
+ socket.send '{"type":"connect","body":{"channel":"main","id":"1"}}'
11
+ end
12
+
13
+ socket.onmessage = lambda do |event|
14
+ message = JSON.parse event.data
15
+
16
+ if Misskey.debug.debugging
17
+ puts "Got a websocket message!!1 The type is: #{message["body"]["type"]}"
18
+ end
19
+
20
+ case message["body"]["type"]
21
+ when "notification"
22
+ if Misskey.debug.debugging
23
+ puts "The notification's note body type is: #{message["body"]["body"]["type"]}"
24
+ end
25
+
26
+ if @@onMentionDo[0] and message["body"]["body"]["type"] == "mention"
27
+ @@onMentionDo[1].call message
28
+ elsif @@onReactionDo[0] and message["body"]["body"]["type"] == "reaction"
29
+ @@onReactionDo[1].call message
30
+ elsif @@onRenoteDo[0] and message["body"]["body"]["type"] == "renote"
31
+ @@onRenoteDo[1].call message
32
+ elsif @@onQuoteDo[0] and message["body"]["body"]["type"] == "quote"
33
+ @@onQuoteDo[1].call message
34
+ end
35
+
36
+ if @@onNotificationDo[0]
37
+ @@onNotificationDo[1].call message
38
+ end
39
+ end
40
+ end
41
+
42
+ socket.onclose = lambda do |event|
43
+ puts Rainbow("Connection to websocket closed.").red
44
+ end
45
+
46
+ socket.onerror = lambda do |event|
47
+ puts "An error occurred: #{event}"
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ def n
54
+ def oM block # onMention
55
+ @@onMentionDo = [true, block]
56
+ end
57
+
58
+ def oR block # onReaction
59
+ @@onReactionDo = [true, block]
60
+ end
61
+
62
+ def oRe block # onRenote
63
+ @@onRenoteDo = [true, block]
64
+ end
65
+
66
+ def oN block # onNotification, like just any notification will trigger this.
67
+ @@onNotificationDo = [true, block]
68
+ end
69
+
70
+ def oQ block # onQuote
71
+ @@onQuoteDo = [true, block]
72
+ end
73
+ end
74
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: misskey
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sky.Bit
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: httparty
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: rainbow
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: faye-websocket
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ description: A Ruby Gem for interacting with the Misskey API
55
+ email:
56
+ - contact@skydevs.me
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - LICENSE
62
+ - README.md
63
+ - lib/create.rb
64
+ - lib/misskey.rb
65
+ - lib/websocket.rb
66
+ homepage: https://git.gay/Sky.Bit/Misskey.rb
67
+ licenses:
68
+ - Apache-2.0
69
+ metadata: {}
70
+ post_install_message: |2+
71
+
72
+
73
+ WARNING: This library is very limited and needs contributors. Please! If you would like to see a feature added to Misskey.rb, try contributing! I would really appreciate it <3
74
+
75
+
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubygems_version: 4.0.3
91
+ specification_version: 4
92
+ summary: A Ruby Gem for interacting with the Misskey API
93
+ test_files: []
94
+ ...