mirror of
https://github.com/musix-org/musix-oss
synced 2024-12-23 06:43:17 +00:00
Update 3.2.2
This commit is contained in:
parent
3532cc00d3
commit
2a692edf8d
1
index.js
1
index.js
@ -20,4 +20,3 @@ manager.spawn(config.shards, config.shardDelay, config.shardTimeout);
|
|||||||
manager.on("shardCreate", (shard) =>
|
manager.on("shardCreate", (shard) =>
|
||||||
console.log(`- Launched shard ${shard.id} -`)
|
console.log(`- Launched shard ${shard.id} -`)
|
||||||
);
|
);
|
||||||
//require("./src/bot.js");
|
|
@ -15,7 +15,6 @@ module.exports = {
|
|||||||
id: client.config.spotify_client_id,
|
id: client.config.spotify_client_id,
|
||||||
secret: client.config.spotify_client_secret,
|
secret: client.config.spotify_client_secret,
|
||||||
});
|
});
|
||||||
|
|
||||||
spotify.setAccessToken(client.config.spotify_access_key);
|
spotify.setAccessToken(client.config.spotify_access_key);
|
||||||
|
|
||||||
const youtube = new YouTube(client.config.api_key);
|
const youtube = new YouTube(client.config.api_key);
|
||||||
|
@ -41,6 +41,7 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
dbl.postStats(client.guilds.size);
|
dbl.postStats(client.guilds.size);
|
||||||
}
|
}
|
||||||
|
client.funcs.getSpotifyKey(client);
|
||||||
console.log(`- Activated - Shard: ${client.shard.ids} -`);
|
console.log(`- Activated - Shard: ${client.shard.ids} -`);
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
if (!client.config.devMode) client.funcs.checkDB(client);
|
if (!client.config.devMode) client.funcs.checkDB(client);
|
||||||
@ -50,6 +51,9 @@ module.exports = {
|
|||||||
if (client.config.dblApi && !client.config.devMode)
|
if (client.config.dblApi && !client.config.devMode)
|
||||||
dbl.postStats(client.guilds.cache.size);
|
dbl.postStats(client.guilds.cache.size);
|
||||||
}, 1800000);
|
}, 1800000);
|
||||||
|
setInterval(() => {
|
||||||
|
client.funcs.getSpotifyKey(client);
|
||||||
|
}, 3600000);
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
client.funcs.ffmpeg(client, Discord);
|
client.funcs.ffmpeg(client, Discord);
|
||||||
}, 7200000);
|
}, 7200000);
|
||||||
|
@ -10,6 +10,7 @@ module.exports = {
|
|||||||
spotify_access_key: process.env.SPOTIFY_ACCESS_KEY,
|
spotify_access_key: process.env.SPOTIFY_ACCESS_KEY,
|
||||||
spotify_client_secret: process.env.SPOTIFY_CLIENT_SECRET,
|
spotify_client_secret: process.env.SPOTIFY_CLIENT_SECRET,
|
||||||
spotify_client_id: process.env.SPOTIFY_CLIENT_ID,
|
spotify_client_id: process.env.SPOTIFY_CLIENT_ID,
|
||||||
|
spotify_refresh_token: process.env.SPOTIFY_REFRESH_TOKEN,
|
||||||
port: 8888,
|
port: 8888,
|
||||||
redirectUri: "http://localhost:8888/callback/",
|
redirectUri: "http://localhost:8888/callback/",
|
||||||
testServer: "489111553321336832",
|
testServer: "489111553321336832",
|
||||||
@ -19,7 +20,7 @@ module.exports = {
|
|||||||
embedColor: "#b50002",
|
embedColor: "#b50002",
|
||||||
invite: "https://discordapp.com/oauth2/authorize?client_id=607266889537945605&permissions=3427328&scope=bot",
|
invite: "https://discordapp.com/oauth2/authorize?client_id=607266889537945605&permissions=3427328&scope=bot",
|
||||||
supportServer: "https://discord.gg/rvHuJtB",
|
supportServer: "https://discord.gg/rvHuJtB",
|
||||||
devMode: false,
|
devMode: true,
|
||||||
api: false,
|
api: false,
|
||||||
saveDB: true,
|
saveDB: true,
|
||||||
respawn: true,
|
respawn: true,
|
||||||
|
26
src/struct/funcs/getSpotifyKey.js
Normal file
26
src/struct/funcs/getSpotifyKey.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
module.exports = async function (client) {
|
||||||
|
let accessKey;
|
||||||
|
var request = require("request");
|
||||||
|
|
||||||
|
var refresh_token = client.config.spotify_refresh_token;
|
||||||
|
var authOptions = {
|
||||||
|
url: "https://accounts.spotify.com/api/token",
|
||||||
|
headers: {
|
||||||
|
Authorization: "Basic " +
|
||||||
|
new Buffer(client.config.spotify_client_id + ":" + client.config.spotify_client_secret).toString("base64"),
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
grant_type: "refresh_token",
|
||||||
|
refresh_token: refresh_token,
|
||||||
|
},
|
||||||
|
json: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
request.post(authOptions, function (error, response, body) {
|
||||||
|
if (!error && response.statusCode === 200) {
|
||||||
|
client.config.spotify_access_key = body.access_token
|
||||||
|
} else {
|
||||||
|
console.log("An error occured!")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
151
web/app.js
151
web/app.js
@ -1,151 +0,0 @@
|
|||||||
const config = require("../src/struct/config/config.js");
|
|
||||||
const express = require("express"); // Express web server framework
|
|
||||||
const request = require("request"); // "Request" library
|
|
||||||
const cors = require("cors");
|
|
||||||
const querystring = require("querystring");
|
|
||||||
const cookieParser = require("cookie-parser");
|
|
||||||
const http = require("http");
|
|
||||||
const client_id = config.spotify_client_id;
|
|
||||||
const client_secret = config.spotify_client_secret;
|
|
||||||
const redirect_uri = config.redirectUri;
|
|
||||||
const scope = "user-read-private user-read-email";
|
|
||||||
console.log(config);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates a random string containing numbers and letters
|
|
||||||
* @param {number} length The length of the string
|
|
||||||
* @return {string} The generated string
|
|
||||||
*/
|
|
||||||
var generateRandomString = function (length) {
|
|
||||||
var text = "";
|
|
||||||
var possible =
|
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
||||||
|
|
||||||
for (var i = 0; i < length; i++) {
|
|
||||||
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
||||||
}
|
|
||||||
return text;
|
|
||||||
};
|
|
||||||
|
|
||||||
var stateKey = "spotify_auth_state";
|
|
||||||
|
|
||||||
var app = express();
|
|
||||||
|
|
||||||
app
|
|
||||||
.use(express.static(__dirname + "/public"))
|
|
||||||
.use(cors())
|
|
||||||
.use(cookieParser());
|
|
||||||
|
|
||||||
app.get("/login", function (req, res) {
|
|
||||||
var state = generateRandomString(16);
|
|
||||||
res.cookie(stateKey, state);
|
|
||||||
|
|
||||||
res.redirect(
|
|
||||||
"https://accounts.spotify.com/authorize?" +
|
|
||||||
querystring.stringify({
|
|
||||||
response_type: "code",
|
|
||||||
client_id: client_id,
|
|
||||||
scope: scope,
|
|
||||||
redirect_uri: redirect_uri,
|
|
||||||
state: state,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get("/callback", function (req, res) {
|
|
||||||
// your application requests refresh and access tokens
|
|
||||||
// after checking the state parameter
|
|
||||||
|
|
||||||
var code = req.query.code || null;
|
|
||||||
var state = req.query.state || null;
|
|
||||||
var storedState = req.cookies ? req.cookies[stateKey] : null;
|
|
||||||
|
|
||||||
if (state === null || state !== storedState) {
|
|
||||||
res.redirect(
|
|
||||||
"/#" +
|
|
||||||
querystring.stringify({
|
|
||||||
error: "state_mismatch",
|
|
||||||
})
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
res.clearCookie(stateKey);
|
|
||||||
var authOptions = {
|
|
||||||
url: "https://accounts.spotify.com/api/token",
|
|
||||||
form: {
|
|
||||||
code: code,
|
|
||||||
redirect_uri: redirect_uri,
|
|
||||||
grant_type: "authorization_code",
|
|
||||||
},
|
|
||||||
headers: {
|
|
||||||
Authorization: "Basic " +
|
|
||||||
new Buffer(client_id + ":" + client_secret).toString("base64"),
|
|
||||||
},
|
|
||||||
json: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
request.post(authOptions, function (error, response, body) {
|
|
||||||
if (!error && response.statusCode === 200) {
|
|
||||||
var access_token = body.access_token,
|
|
||||||
refresh_token = body.refresh_token;
|
|
||||||
|
|
||||||
var options = {
|
|
||||||
url: "https://api.spotify.com/v1/me",
|
|
||||||
headers: {
|
|
||||||
Authorization: "Bearer " + access_token,
|
|
||||||
},
|
|
||||||
json: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
// use the access token to access the Spotify Web API
|
|
||||||
request.get(options, function (error, response, body) {
|
|
||||||
console.log(body);
|
|
||||||
});
|
|
||||||
|
|
||||||
// we can also pass the token to the browser to make requests from there
|
|
||||||
res.redirect(
|
|
||||||
"/#" +
|
|
||||||
querystring.stringify({
|
|
||||||
access_token: access_token,
|
|
||||||
refresh_token: refresh_token,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
res.redirect(
|
|
||||||
"/#" +
|
|
||||||
querystring.stringify({
|
|
||||||
error: "invalid_token",
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get("/refresh_token", function (req, res) {
|
|
||||||
// requesting access token from refresh token
|
|
||||||
var refresh_token = req.query.refresh_token;
|
|
||||||
var authOptions = {
|
|
||||||
url: "https://accounts.spotify.com/api/token",
|
|
||||||
headers: {
|
|
||||||
Authorization: "Basic " +
|
|
||||||
new Buffer(client_id + ":" + client_secret).toString("base64"),
|
|
||||||
},
|
|
||||||
form: {
|
|
||||||
grant_type: "refresh_token",
|
|
||||||
refresh_token: refresh_token,
|
|
||||||
},
|
|
||||||
json: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
request.post(authOptions, function (error, response, body) {
|
|
||||||
if (!error && response.statusCode === 200) {
|
|
||||||
var access_token = body.access_token;
|
|
||||||
res.send({
|
|
||||||
access_token: access_token,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log("Listening on " + config.port);
|
|
||||||
app.listen(config.port);
|
|
@ -1,145 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html>
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<title>Example of the Authorization Code flow with Spotify</title>
|
|
||||||
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
|
|
||||||
<style type="text/css">
|
|
||||||
#login,
|
|
||||||
#loggedin {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.text-overflow {
|
|
||||||
overflow: hidden;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
white-space: nowrap;
|
|
||||||
width: 500px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="container">
|
|
||||||
<div id="login">
|
|
||||||
<h1>This is an example of the Authorization Code flow</h1>
|
|
||||||
<a href="/login" class="btn btn-primary">Log in with Spotify</a>
|
|
||||||
</div>
|
|
||||||
<div id="loggedin">
|
|
||||||
<div id="user-profile">
|
|
||||||
</div>
|
|
||||||
<div id="oauth">
|
|
||||||
</div>
|
|
||||||
<button class="btn btn-default" id="obtain-new-token">Obtain new token using the refresh token</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script id="user-profile-template" type="text/x-handlebars-template">
|
|
||||||
<h1>Logged in as {{display_name}}</h1>
|
|
||||||
<div class="media">
|
|
||||||
<div class="pull-left">
|
|
||||||
<img class="media-object" width="150" src="{{images.0.url}}" />
|
|
||||||
</div>
|
|
||||||
<div class="media-body">
|
|
||||||
<dl class="dl-horizontal">
|
|
||||||
<dt>Display name</dt><dd class="clearfix">{{display_name}}</dd>
|
|
||||||
<dt>Id</dt><dd>{{id}}</dd>
|
|
||||||
<dt>Email</dt><dd>{{email}}</dd>
|
|
||||||
<dt>Spotify URI</dt><dd><a href="{{external_urls.spotify}}">{{external_urls.spotify}}</a></dd>
|
|
||||||
<dt>Link</dt><dd><a href="{{href}}">{{href}}</a></dd>
|
|
||||||
<dt>Profile Image</dt><dd class="clearfix"><a href="{{images.0.url}}">{{images.0.url}}</a></dd>
|
|
||||||
<dt>Country</dt><dd>{{country}}</dd>
|
|
||||||
</dl>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script id="oauth-template" type="text/x-handlebars-template">
|
|
||||||
<h2>oAuth info</h2>
|
|
||||||
<dl class="dl-horizontal">
|
|
||||||
<dt>Access token</dt><dd class="text-overflow">{{access_token}}</dd>
|
|
||||||
<dt>Refresh token</dt><dd class="text-overflow">{{refresh_token}}</dd>
|
|
||||||
</dl>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/2.0.0-alpha.1/handlebars.min.js"></script>
|
|
||||||
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
|
|
||||||
<script>
|
|
||||||
(function () {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Obtains parameters from the hash of the URL
|
|
||||||
* @return Object
|
|
||||||
*/
|
|
||||||
function getHashParams() {
|
|
||||||
var hashParams = {};
|
|
||||||
var e, r = /([^&;=]+)=?([^&;]*)/g,
|
|
||||||
q = window.location.hash.substring(1);
|
|
||||||
while (e = r.exec(q)) {
|
|
||||||
hashParams[e[1]] = decodeURIComponent(e[2]);
|
|
||||||
}
|
|
||||||
return hashParams;
|
|
||||||
}
|
|
||||||
|
|
||||||
var userProfileSource = document.getElementById('user-profile-template').innerHTML,
|
|
||||||
userProfileTemplate = Handlebars.compile(userProfileSource),
|
|
||||||
userProfilePlaceholder = document.getElementById('user-profile');
|
|
||||||
|
|
||||||
var oauthSource = document.getElementById('oauth-template').innerHTML,
|
|
||||||
oauthTemplate = Handlebars.compile(oauthSource),
|
|
||||||
oauthPlaceholder = document.getElementById('oauth');
|
|
||||||
|
|
||||||
var params = getHashParams();
|
|
||||||
|
|
||||||
var access_token = params.access_token,
|
|
||||||
refresh_token = params.refresh_token,
|
|
||||||
error = params.error;
|
|
||||||
|
|
||||||
if (error) {
|
|
||||||
alert('There was an error during the authentication: ' + error);
|
|
||||||
} else {
|
|
||||||
if (access_token) {
|
|
||||||
// render oauth info
|
|
||||||
oauthPlaceholder.innerHTML = oauthTemplate({
|
|
||||||
access_token: access_token,
|
|
||||||
refresh_token: refresh_token
|
|
||||||
});
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: 'https://api.spotify.com/v1/me',
|
|
||||||
headers: {
|
|
||||||
'Authorization': 'Bearer ' + access_token
|
|
||||||
},
|
|
||||||
success: function (response) {
|
|
||||||
userProfilePlaceholder.innerHTML = userProfileTemplate(response);
|
|
||||||
|
|
||||||
$('#login').hide();
|
|
||||||
$('#loggedin').show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// render initial screen
|
|
||||||
$('#login').show();
|
|
||||||
$('#loggedin').hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById('obtain-new-token').addEventListener('click', function () {
|
|
||||||
$.ajax({
|
|
||||||
url: '/refresh_token',
|
|
||||||
data: {
|
|
||||||
'refresh_token': refresh_token
|
|
||||||
}
|
|
||||||
}).done(function (data) {
|
|
||||||
access_token = data.access_token;
|
|
||||||
oauthPlaceholder.innerHTML = oauthTemplate({
|
|
||||||
access_token: access_token,
|
|
||||||
refresh_token: refresh_token
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}, false);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
Loading…
Reference in New Issue
Block a user