Skip to content

Commit

Permalink
Store Discord Client ID during initial setup
Browse files Browse the repository at this point in the history
This makes the user experience much easier, you can now run the script with `node .` instead of `node . <client-id>`.
If you had a previous version, you may need to delete your `config.json` file
  • Loading branch information
RagnarLothbrok-Odin committed Jul 1, 2022
1 parent 5d85691 commit 11cf9e6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ Feel free to open any issues/PR request on how I can improve this, following is
node .
2. You will be asked for your [Trakt Client ID](https://trakt.tv/oauth/applications), if you did not create an application, ensure you read the [Setup section of this page](https://github.com/RagnarLothbrok-Odin/trakt-discord-presence/blob/main/README.md#setup)
3. You will be asked for your [Trakt Client Secret](https://trakt.tv/oauth/applications)
4. You will be provided a `URL`, you must paste this link into a browser of your choosing
4. You will be asked for your [Discord Client ID](https://discord.com/developers/applications), if you did not create an application, ensure you read the [Setup section of this page](https://github.com/RagnarLothbrok-Odin/trakt-discord-presence/blob/main/README.md#setup)
5. You will be provided a `URL`, you must paste this link into a browser of your choosing
* Once you visit this `URL`, a code will be provided, you must paste this code into your CMD/terminal/console
5. Finally, you must now run the following code, replacing the string of numbers, with your [Discord Client ID](https://discord.com/developers/applications), if you did not create an application, ensure you read the [Setup section of this page](https://github.com/RagnarLothbrok-Odin/trakt-discord-presence/blob/main/README.md#setup)
6. Finally, you must now run the following code to start the program.

node . 123456789098765432
node .


## Functionality
Expand Down
17 changes: 7 additions & 10 deletions Trakt.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (!fs.existsSync('./config.json')) {
}

// Fetching the data from config.json
const { clientId, clientSecret, oAuth } = require('./config.json');
const { clientId, clientSecret, oAuth, discordClientID } = require('./config.json');

// Checks if the oAuth has expired and runs tokenExpired() function if it has
if (Date.now() > oAuth.expires) {
Expand All @@ -30,15 +30,6 @@ const options = {
const trakt = new Trakt(options);
trakt.import_token(oAuth);

// Collect arguments from the input
const discordClientID = process.argv.slice(2)[0];

// Check if ID was supplied
if (!discordClientID) {
console.log(chalk.red.bold('Please supply a valid Discord Client ID.\nIf you are unsure where to find this, please refer to the README.md file.'));
process.exit(1);
}

// Create the Discord RPC client
// Create client
const rpc = new DiscordRPC.Client({ transport: 'ipc' });
Expand Down Expand Up @@ -117,6 +108,11 @@ async function questions() {
type: 'input',
name: 'clientSecret',
message: 'What is your Trakt Client Secret?'
},
{
type: 'input',
name: 'discordClientID',
message: 'What is your Discord Client ID?'
}
]).catch(() => {
console.error('The user aborted the request.');
Expand Down Expand Up @@ -146,6 +142,7 @@ async function questions() {
const arr = {};
arr.clientId = response.clientId;
arr.clientSecret = response.clientSecret;
arr.discordClientID = response.discordClientID;

try {
await qTrakt.exchange_code(auth.oAuth, null);
Expand Down

0 comments on commit 11cf9e6

Please sign in to comment.