richpresence-rb 1.0 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c5222eceed9b5523af1594e17608d42a4878a05ad72703373535cd442c84c8f
4
- data.tar.gz: 5b1b4979548b135d87da013885c63c113073a5145972fe4f10328ae2a2a5db52
3
+ metadata.gz: 8c0f3f194376e41ffd100e000ea28fc17fdf6d2d1d34fc4300c2fef52f086fe7
4
+ data.tar.gz: 6fbf4e80609301a69b293c6a63fd7969b8fdbc3380c130751e0c36856d746759
5
5
  SHA512:
6
- metadata.gz: bd8df23d8338aafd5195ef200bbdc9a09bac31f27e95be5636a556ec20ad39636fc6450fec5056ff5559b97a740ef5c67aa2bc143587cb5f21f04cea8480b1ac
7
- data.tar.gz: 3364866100f2b723623fb6d6452d30f067d471b799b1e51fb29f90eaa2fc516091d74bdba1e19c6844ca74337f79f5c403e56e58d0bf299217d41dcf9d306a81
6
+ metadata.gz: bc80600556a7763a2a54f85d6b038657f000a08fed370951b942fcf6bf0cb60e8076323170bf98587e00d2a2bae5b899164fa315f24de716187fc23b69cc5224
7
+ data.tar.gz: 9b51d9ab8f85c1fc107b26e53834be209e87c578901ab4cd57008d3977021c6117c5a365b5fc6c0081c2a6f4d5e584c7855a644d96ca83d2d4f43776dd858664
@@ -0,0 +1,32 @@
1
+ module Richpresence
2
+ class Errors
3
+ ERRORS = {
4
+ UNKNOWN_ERROR: 1000,
5
+ INVALID_PAYLOAD: 4000,
6
+ INVALID_VERSION: 4001,
7
+ INVALID_COMMAND: 4002,
8
+ INVALID_GUILD: 4003,
9
+ INVALID_EVENT: 4004,
10
+ INVALID_CHANNEL: 4005,
11
+ INVALID_PERMISSIONS: 4006,
12
+ INVALID_CLIENTID: 4007,
13
+ INVALID_ORIGIN: 4008,
14
+ INVALID_TOKEN: 4009,
15
+ INVALID_USER: 4010,
16
+ INVALID_INVITE: 4011,
17
+ INVALID_ACTIVITY_JOIN_REQUEST: 4012,
18
+ OAUTH2_ERROR: 5000,
19
+ SELECT_CHANNEL_TIMED_OUT: 5001,
20
+ GET_GUILD_TIMED_OUT: 5002,
21
+ SELECT_VOICE_FORCE_REQUIRED: 5003,
22
+ CAPTURE_SHORTCUT_ALREADY_LISTENING: 5004,
23
+ RICH_PRESENCE_INVALID_SECRET: 5005
24
+ }.freeze
25
+
26
+ def self.parse_error_code(error_code)
27
+ ERRORS.each do |error, code|
28
+ return error if code == error_code
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,40 @@
1
+ require 'socket'
2
+ require 'json'
3
+
4
+ module Richpresence
5
+ class Opcode
6
+ HANDSHAKE = 0
7
+ FRAME = 1
8
+ end
9
+
10
+ class Ipc
11
+ def initialize
12
+ @socket = UNIXSocket.new("#{ipc_path}discord-ipc-0")
13
+ end
14
+
15
+ def send(opcode, payload)
16
+ @socket.write(encode(opcode, payload))
17
+ decode(@socket.recvfrom(1024).first)
18
+ end
19
+
20
+ def encode(opcode, payload)
21
+ payload[:nonce] = format '%.20f', Time.now
22
+ payload = payload.to_json
23
+ [opcode, payload.length].pack('ii<') + payload
24
+ end
25
+
26
+ def decode(data)
27
+ code, = data[0..3].unpack 'i<'
28
+ [code, data[8..-1]]
29
+ end
30
+
31
+ def ipc_path
32
+ %w[XDG_RUNTIME_DIR TMPDIR TMP TEMP].each do |directory|
33
+ directory = ENV[directory]
34
+ return directory if directory
35
+ end
36
+
37
+ '/tmp'
38
+ end
39
+ end
40
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: richpresence-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - AnanaGame
@@ -16,7 +16,9 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
- - lib/client.rb
19
+ - lib/errors.rb
20
+ - lib/ipc.rb
21
+ - lib/richpresence-client.rb
20
22
  homepage: https://github.com/AnanaGame/richpresence-rb
21
23
  licenses:
22
24
  - MIT