Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
entraptaa committed Oct 12, 2023
1 parent 451eb32 commit 2bd7754
Show file tree
Hide file tree
Showing 7 changed files with 316 additions and 1 deletion.
3 changes: 3 additions & 0 deletions INSTALL PACKAGES.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
npm i
pause
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
# FN-RPC
Simple Fortnite Discord RPC
Display your Fortnite Statistics on your Discord Profile!

#### SETUP GUIDE

1. Install [Node.JS](https://nodejs.org/en)
2. Run INSTALL PACKAGES.bat
3. Obtain an API Key from [Fortnite-API.com](https://dash.fortnite-api.com/account)
4. Paste your API Key to the apiKey field in settings.json
5. Paste in your Epic Games Account ID to the epicID field in settings.json
6. Run start.bat

### Common Issues
> The RPC won't connect!
Make sure you have the Desktop version of Discord, not the browser version. If you use Vesktop (Discord Client with Vencord preinstalled), make sure you have Rich Presence enabled in your Vesktop settings.

> I keep getting error: "the requested account's stats are not public"
Launch Fortnite & Go to the Account & Privacy Settings, then set Public Game Stats to ON:
<img src="https://vee.hates.college/6gDvqbwlE"/>

> How do I get my Epic Games Account ID?
Launch Fortnite & Go to the Account & Privacy Settings, then click Copy to Clipboard.
<img src="https://vee.hates.college/6gDxp3yzM"/>
44 changes: 44 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const { Client } = require("discord-rpc");
const rpc = new Client({ transport: "ipc" });
const axios = require("axios");

const { clientID, epicID, apiKey, assets } = require("./settings.json");

async function GetStats() {
try {
await axios.get(`https://fortnite-api.com/v2/stats/br/v2/${epicID}`, {
headers: {
'Authorization': apiKey
}
}).catch(err => {
if (err.response) throw `[ERROR] ${err.response.data.error}, Status Code: ${err.response.data.status}`;
if (err) throw err;
}).then(res => {
let data = res.data.data;

return setStatus(data.battlePass.level, data.stats.all.overall.wins, data.stats.all.overall.kills, data.stats.all.overall.deaths, data.battlePass.progress, data.account.name);
});
} catch (err) {
console.error(err);
}
}

async function setStatus(bp, wins, kills, deaths, progress, username) {
rpc.setActivity({
details: `👑 ${bp.toLocaleString()} | ${progress}% (${100 - progress}% Left)`,
state: `🏆 ${wins.toLocaleString()} | 🎯 ${kills.toLocaleString()} | 💀 ${deaths.toLocaleString()}`,
largeImageKey: assets.large_img_key,
largeImageText: `Fortnite Stats for: ${username}`
});
await new Promise((p => setTimeout(p, 60000)));
GetStats();
}

rpc.on("ready", async () => {
console.log('FN-RPC is now initalized.');
GetStats();
})

rpc.login({
clientId: clientID
});
209 changes: 209 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "fn-rpc",
"version": "1.0.0",
"description": "Simple Fortnite Discord RPC",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/RiftSTW/FN-RPC.git"
},
"keywords": [
"Fortnite"
],
"author": "RiftSTW",
"license": "ISC",
"bugs": {
"url": "https://github.com/RiftSTW/FN-RPC/issues"
},
"homepage": "https://github.com/RiftSTW/FN-RPC#readme",
"dependencies": {
"axios": "^1.5.1",
"discord-rpc": "^4.0.1"
}
}
6 changes: 6 additions & 0 deletions settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"clientID": "1161759792507932755",
"epicID": "",
"apiKey": "",
"assets": { "large_img_key": "fn" }
}
3 changes: 3 additions & 0 deletions start.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
node index.js
pause

0 comments on commit 2bd7754

Please sign in to comment.