Module: WS
- Defined in:
- lib/websocket.rb
Instance Method Summary collapse
- #c ⇒ Object
- #n ⇒ Object
-
#oM(block) ⇒ Object
onMention.
-
#oN(block) ⇒ Object
onNotification, like just any notification will trigger this.
-
#oQ(block) ⇒ Object
onQuote.
-
#oR(block) ⇒ Object
onReaction.
-
#oRe(block) ⇒ Object
onRenote.
Instance Method Details
#c ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/websocket.rb', line 2 def c Thread.start do EM.run do instance = "wss://#{Misskey.auth.instanceURI}/streaming?i=#{Misskey.auth.token}" socket = Faye::WebSocket::Client.new instance socket.onopen = lambda do |event| puts Rainbow("Connected to websocket successfully.").green socket.send '{"type":"connect","body":{"channel":"main","id":"1"}}' end socket. = lambda do |event| = JSON.parse event.data if Misskey.debug.debugging puts "Got a websocket message!!1 The type is: #{["body"]["type"]}" end case ["body"]["type"] when "notification" if Misskey.debug.debugging puts "The notification's note body type is: #{["body"]["body"]["type"]}" end if @@onMentionDo[0] and ["body"]["body"]["type"] == "mention" @@onMentionDo[1].call elsif @@onReactionDo[0] and ["body"]["body"]["type"] == "reaction" @@onReactionDo[1].call elsif @@onRenoteDo[0] and ["body"]["body"]["type"] == "renote" @@onRenoteDo[1].call elsif @@onQuoteDo[0] and ["body"]["body"]["type"] == "quote" @@onQuoteDo[1].call end if @@onNotificationDo[0] @@onNotificationDo[1].call end end end socket.onclose = lambda do |event| puts Rainbow("Connection to websocket closed.").red end socket.onerror = lambda do |event| puts "An error occurred: #{event}" end end end end |
#n ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/websocket.rb', line 53 def n def oM block # onMention @@onMentionDo = [true, block] end def oR block # onReaction @@onReactionDo = [true, block] end def oRe block # onRenote @@onRenoteDo = [true, block] end def oN block # onNotification, like just any notification will trigger this. @@onNotificationDo = [true, block] end def oQ block # onQuote @@onQuoteDo = [true, block] end end |
#oM(block) ⇒ Object
onMention
54 55 56 |
# File 'lib/websocket.rb', line 54 def oM block # onMention @@onMentionDo = [true, block] end |
#oN(block) ⇒ Object
onNotification, like just any notification will trigger this.
66 67 68 |
# File 'lib/websocket.rb', line 66 def oN block # onNotification, like just any notification will trigger this. @@onNotificationDo = [true, block] end |
#oQ(block) ⇒ Object
onQuote
70 71 72 |
# File 'lib/websocket.rb', line 70 def oQ block # onQuote @@onQuoteDo = [true, block] end |
#oR(block) ⇒ Object
onReaction
58 59 60 |
# File 'lib/websocket.rb', line 58 def oR block # onReaction @@onReactionDo = [true, block] end |
#oRe(block) ⇒ Object
onRenote
62 63 64 |
# File 'lib/websocket.rb', line 62 def oRe block # onRenote @@onRenoteDo = [true, block] end |