99 lines
2.9 KiB
HTML
99 lines
2.9 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Admin Panel</title>
|
|
</head>
|
|
<body>
|
|
<h1>Admin Panel</h1>
|
|
<p>Note: this admin panel will only work for Shounic!</p>
|
|
<button id="startPoll">Start Bet</button>
|
|
<button id="endPoll">End Bet</button>
|
|
<button id="startStream">Start Stream</button>
|
|
<button id="endStream">End Stream</button>
|
|
<script>
|
|
document.getElementById('startPoll').addEventListener('click', async () => {
|
|
let question = prompt("What is the question of the bet?")
|
|
let outcomes = prompt("What outcomes can the poll have (comma seperated)?")
|
|
let time = prompt("How long should the poll last (in seconds)?")
|
|
let response = await fetch("/api/extra/bet-on-it", {
|
|
method: "POST",
|
|
headers: {
|
|
"Authorization": localStorage.getItem("accessToken")
|
|
},
|
|
body: JSON.stringify({
|
|
"Action": "startBet",
|
|
"question": question,
|
|
"possible": outcomes.split(", "),
|
|
"timeToBet": Math.floor(new Date().getTime() / 1000) + parseInt(time)
|
|
})
|
|
})
|
|
if (response.ok) {
|
|
alert("Poll started!")
|
|
} else {
|
|
alert("Error starting poll")
|
|
}
|
|
})
|
|
|
|
document.getElementById('endPoll').addEventListener('click', async () => {
|
|
let response = await fetch("/api/extra/bet-on-it", {
|
|
method: "POST",
|
|
headers: {
|
|
"Authorization": localStorage.getItem("accessToken")
|
|
},
|
|
body: JSON.stringify({
|
|
"Action": "endBet",
|
|
"answer": prompt("What was the result of the bet (case sensitive)?")
|
|
})
|
|
})
|
|
if (response.ok) {
|
|
alert("Poll ended!")
|
|
} else {
|
|
alert("Error ending poll")
|
|
}
|
|
})
|
|
|
|
document.getElementById('startStream').addEventListener('click', async () => {
|
|
// First, fetch the broadcasts from YouTube
|
|
let response = await fetch("https://www.googleapis.com/youtube/v3/liveBroadcasts?part=snippet&mine=true", {
|
|
headers: {
|
|
"Authorization": "Bearer " + localStorage.getItem("oauthToken")
|
|
}
|
|
})
|
|
let data = await response.json()
|
|
let liveChatID = data.items[0]["snippet"]["liveChatId"]
|
|
// Now that we have the live chat ID, we can start the stream
|
|
let response2 = await fetch("/api/startStream", {
|
|
method: "POST",
|
|
headers: {
|
|
"Authorization": localStorage.getItem("accessToken")
|
|
},
|
|
body: JSON.stringify({
|
|
"liveChatID": liveChatID
|
|
})
|
|
})
|
|
|
|
if (response2.ok) {
|
|
alert("Stream started!")
|
|
} else {
|
|
alert("Error starting stream")
|
|
}
|
|
})
|
|
|
|
document.getElementById('endStream').addEventListener('click', async () => {
|
|
let response = await fetch("/api/endStream", {
|
|
method: "POST",
|
|
headers: {
|
|
"Authorization": localStorage.getItem("accessToken")
|
|
}
|
|
})
|
|
|
|
if (response.ok) {
|
|
alert("Stream ended!")
|
|
} else {
|
|
alert("Error ending stream")
|
|
}
|
|
})
|
|
</script>
|
|
</body>
|
|
</html> |