mirror of
https://github.com/BluemediaGER/muse.git
synced 2024-11-12 21:05:29 +01:00
Automatically refresh Spotify token
This commit is contained in:
parent
60a7658293
commit
e7bf2a4b47
10
src/index.ts
10
src/index.ts
|
@ -9,11 +9,19 @@ import {sequelize} from './utils/db';
|
|||
let bot = container.get<Bot>(TYPES.Bot);
|
||||
const spotify = container.get<Spotify>(TYPES.Lib.Spotify);
|
||||
|
||||
(async () => {
|
||||
const refreshSpotifyToken = async () => {
|
||||
const auth = await spotify.clientCredentialsGrant();
|
||||
|
||||
spotify.setAccessToken(auth.body.access_token);
|
||||
|
||||
return auth.body.expires_in;
|
||||
};
|
||||
|
||||
(async () => {
|
||||
const spotifyRefreshIntervalSeconds = await refreshSpotifyToken();
|
||||
|
||||
setInterval(async () => refreshSpotifyToken(), (spotifyRefreshIntervalSeconds / 2) * 1000);
|
||||
|
||||
// Create data directories if necessary
|
||||
await makeDir(container.get(TYPES.Config.DATA_DIR));
|
||||
await makeDir(container.get(TYPES.Config.CACHE_DIR));
|
||||
|
|
Loading…
Reference in a new issue