Created
March 6, 2021 14:45
-
-
Save freaktechnik/fc5bb91f61415d4a8f7a8b66e75a18ac to your computer and use it in GitHub Desktop.
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
'use strict'; | |
const {messageValue, reply, random, isBot} = require('../server/tools'); | |
const config = require('../config'); | |
require('dotenv').config(); | |
var CLIENT_ID = config.twitch.TWITCH_CLIENT_ID; | |
var CLIENT_SECRET = config.twitchTWITCH_SECRET; | |
var GET_TOKEN = config.twitch.TOKENURL; | |
var GET_STREAM = config.twitch.TWITCH_GET_USER_URL; | |
var TOKEN = config.twitch.TWITCH_CURRENT_TOKEN; | |
var userOutput; | |
const got = require('got'); | |
async function getToken() { | |
try { | |
const resp = await got({ | |
url: GET_TOKEN, | |
method: "POST", | |
headers: { | |
"Accept": "application/json" | |
}, | |
form: { | |
client_id: CLIENT_ID, | |
client_secret: CLIENT_SECRET, | |
grant_type: "client_credentials" | |
}, | |
responseType: "json" | |
}); | |
// console.log("You got a Twitch token you crazy bastard: " + resp.body.access_token); | |
return resp.body.access_token; | |
} | |
catch(err) { | |
console.error(err); | |
} | |
} | |
async function getStream(twitchToken) { | |
try { | |
const resp = await got({ | |
url: GET_STREAM, | |
method: "GET", | |
headers: { | |
"Client-ID": CLIENT_ID, | |
"Authorization": "Bearer " + twitchToken | |
}, | |
responseType: "json" | |
}); | |
return response.body.data; | |
} | |
catch(err) { | |
console.error(err); | |
} | |
} | |
module.exports = function (client, adapter) { | |
client.on('message', async (inMsg) => { | |
const responseData = await getStream(TOKEN); | |
console.log(responseData); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment