Skip to content

Commit

Permalink
new file: assets/osu!nppp.svg
Browse files Browse the repository at this point in the history
	new file:   auth.js
	deleted:    bot.js
	new file:   chat.js
	modified:   index.html
	new file:   main.js
	new file:   osu.js
	new file:   websocket.js
    Organized code into multiple files
  • Loading branch information
Jarran2R committed Aug 10, 2024
1 parent a6a4752 commit b6c6358
Show file tree
Hide file tree
Showing 8 changed files with 497 additions and 344 deletions.
173 changes: 173 additions & 0 deletions assets/osu!nppp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 64 additions & 0 deletions auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const CLIENT_ID = 'dl6k4oj0aiuyymn19opsclt6xyykbc';
const OAUTH_TOKEN = window.location.hash.split('access_token=')[1] ? window.location.hash.split('access_token=')[1].split('&')[0] : "";

var BOT_USER_ID; // This is the User ID of the chat bot
var CHAT_CHANNEL_USER_ID; // This is the User ID of the channel that the bot will join and listen to chat messages of

async function getAuth(token) {
// https://dev.twitch.tv/docs/authentication/validate-tokens/#how-to-validate-a-token
let response = await fetch('https://id.twitch.tv/oauth2/validate', {
method: 'GET',
headers: {
'Authorization': 'OAuth ' + OAUTH_TOKEN
}
});

if (response.status != 200) {
let data = await response.json();
throw new Error("Token is not valid. /oauth2/validate returned status code " + response.status);
};

console.log("Validated token.");
};

async function getUserId() {
const response = await fetch(`https://api.twitch.tv/helix/users?login=${document.getElementById("username").value}`, {
method: 'GET',
headers: {
'Client-Id': CLIENT_ID,
'Authorization': 'Bearer ' + OAUTH_TOKEN
}
});

let data = await response.json();
if (response.status == 401) {
throw new Error("No OAuth token provided");
};
try {
CHAT_CHANNEL_USER_ID = data.data[0].id;
console.log("Channel ID: ", CHAT_CHANNEL_USER_ID);
} catch (error) {
throw new Error("Invalid username, " + error);
};
};

async function getBotId() {
const response = await fetch('https://api.twitch.tv/helix/users', {
method: 'GET',
headers: {
'Client-Id': CLIENT_ID,
'Authorization': 'Bearer ' + OAUTH_TOKEN
}
});

let data = await response.json();
if (response.status == 401) {
throw new Error("No OAuth token provided");
}
try {
BOT_USER_ID = data.data[0].id;
console.log("Bot ID: ", BOT_USER_ID);
} catch (error) {
throw new Error(error);
};
};
Loading

0 comments on commit b6c6358

Please sign in to comment.