Module: WS
- Defined in:
- lib/websocket.rb
Instance Method Summary collapse
- #c ⇒ Object
- #n ⇒ Object
-
#oM(block) ⇒ Object
onMention.
-
#oMOR(block) ⇒ Object
onMentionOrReply.
-
#oN(block) ⇒ Object
onNotification, like just any notification will trigger this.
-
#oQ(block) ⇒ Object
onQuote.
-
#oR(block) ⇒ Object
onReaction.
-
#oRe(block) ⇒ Object
onRenote.
-
#oRep(block) ⇒ Object
onReply.
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 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/websocket.rb', line 2 def c @@onMentionDo = [false, nil] @@debugging = false @@onReactionDo = [false, nil] @@onRenoteDo = [false, nil] @@onNotificationDo = [false, nil] @@onQuoteDo = [false, nil] @@onReplyDo = [false, nil] @@onMentionOrReplyDo = [false, nil] 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 elsif @@onReplyDo[0] and ["body"]["body"]["type"] == "reply" @@onReplyDo[1].call elsif @@onMentionOrReplyDo[0] and /(reply)|(mention)/.match ["body"]["body"]["type"] @@onMentionOrReplyDo[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
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/websocket.rb', line 66 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 def oRep block # onReply @@onReplyDo = [true, block] end def oMOR block # onMentionOrReply @@onMentionOrReplyDo = [true, block] end end |
#oM(block) ⇒ Object
onMention
67 68 69 |
# File 'lib/websocket.rb', line 67 def oM block # onMention @@onMentionDo = [true, block] end |
#oMOR(block) ⇒ Object
onMentionOrReply
91 92 93 |
# File 'lib/websocket.rb', line 91 def oMOR block # onMentionOrReply @@onMentionOrReplyDo = [true, block] end |
#oN(block) ⇒ Object
onNotification, like just any notification will trigger this.
79 80 81 |
# File 'lib/websocket.rb', line 79 def oN block # onNotification, like just any notification will trigger this. @@onNotificationDo = [true, block] end |
#oQ(block) ⇒ Object
onQuote
83 84 85 |
# File 'lib/websocket.rb', line 83 def oQ block # onQuote @@onQuoteDo = [true, block] end |
#oR(block) ⇒ Object
onReaction
71 72 73 |
# File 'lib/websocket.rb', line 71 def oR block # onReaction @@onReactionDo = [true, block] end |
#oRe(block) ⇒ Object
onRenote
75 76 77 |
# File 'lib/websocket.rb', line 75 def oRe block # onRenote @@onRenoteDo = [true, block] end |
#oRep(block) ⇒ Object
onReply
87 88 89 |
# File 'lib/websocket.rb', line 87 def oRep block # onReply @@onReplyDo = [true, block] end |