-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
8 changed files
with
497 additions
and
344 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; | ||
}; |
Oops, something went wrong.