Skip to content

Commit 3f4d747

Browse files
committed
Initial commit
0 parents  commit 3f4d747

File tree

11 files changed

+207
-0
lines changed

11 files changed

+207
-0
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*.cr]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 2
9+
trim_trailing_whitespace = true

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/docs/
2+
/lib/
3+
/bin/
4+
/.shards/
5+
*.dwarf

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
language: crystal

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2019 triinoxys
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# RP42
2+
3+
A Discord Rich Presence integration for [@42School](https://github.com/42School).
4+
5+
## Installation
6+
7+
Just download a prebuilt binary from the [releases](https://github.com/triinoxys/RP42/releases) page, or build it yourself.
8+
To build it:
9+
1. Clone the repo: `git clone https://github.com/triinoxys/RP42.git`
10+
2. Install dependencies: `shards install` (no deps right now)
11+
3. Compile: `crystal build src/RP42.cr --release --no-debug`
12+
13+
## Usage
14+
15+
Just execute the newly created file (in background): `./RP42 &`
16+
17+
## Contributing
18+
19+
1. Fork it (<https://github.com/triinoxys/RP42/fork>)
20+
2. Create your feature branch (`git checkout -b my-new-feature`)
21+
3. Commit your changes (`git commit -am 'Add some feature'`)
22+
4. Push to the branch (`git push origin my-new-feature`)
23+
5. Create a new Pull Request
24+
25+
## Contributors
26+
27+
- [triinoxys/aguiot--](https://github.com/triinoxys) - creator and maintainer

shard.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: RP42
2+
version: 0.1.0
3+
4+
authors:
5+
- aguiot-- <aguiot--@student.42.fr>
6+
7+
targets:
8+
RP42:
9+
main: src/RP42.cr
10+
11+
crystal: 0.27.0
12+
13+
license: MIT

spec/RP42_spec.cr

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require "./spec_helper"
2+
3+
describe RP42 do
4+
# TODO: Write tests
5+
6+
it "works" do
7+
false.should eq(true)
8+
end
9+
end

spec/spec_helper.cr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require "spec"
2+
require "../src/RP42"

src/RP42.cr

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
require "./client"
2+
3+
module RP42
4+
VERSION = "0.1.0"
5+
6+
hostname = System.hostname.split(".", 2)
7+
exit if hostname[1] != "42.fr"
8+
9+
client = RichCrystal::Client.new(531103976029028367_u64)
10+
client.login
11+
client.activity({
12+
"details" => "Location: #{hostname[0]}",
13+
"assets" => {
14+
"large_image" => "logo",
15+
"large_text" => "42",
16+
}
17+
})
18+
19+
sleep
20+
end

src/client.cr

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
require "json"
2+
require "./ipc"
3+
4+
module RichCrystal
5+
class Client
6+
# Creates a new Rich-crystal client used for set rich presence activity
7+
def initialize(@client_id : UInt64)
8+
@ipc = RichCrystal::Ipc.new
9+
end
10+
11+
# Log the RichCrystal client by sending a first handshake to the IPC
12+
def login
13+
# Generate the payload in JSON
14+
payload = {
15+
"v" => 1,
16+
"client_id" => "#{@client_id}",
17+
"nonce" => Time.now.to_s("%s"),
18+
}.to_json
19+
20+
# Send the handshake to the IPC
21+
@ipc.send(RichCrystal::Ipc::Opcode::Handshake, payload)
22+
end
23+
24+
# Retrieves a Hash of Strings for sending the frame payload to the IPC
25+
# with discord-rich-presence parameters (see here https://github.com/discordapp/discord-rpc/blob/master/documentation/hard-mode.md#new-rpc-command)
26+
# and return the JSON response
27+
def activity(activity)
28+
# Generate the payload in JSON
29+
payload = {
30+
"cmd" => "SET_ACTIVITY",
31+
"args" => {
32+
"pid" => Process.pid,
33+
"activity" => activity,
34+
},
35+
"nonce" => Time.now.to_s("%s"),
36+
}.to_json
37+
38+
# Send the frame to the IPC
39+
@ipc.send(RichCrystal::Ipc::Opcode::Frame, payload)
40+
end
41+
end
42+
end

0 commit comments

Comments
 (0)