mirror of
https://github.com/BluemediaDev/muse.git
synced 2025-04-19 21:03:56 +02:00
Automatically refresh Spotify token
This commit is contained in:
parent
60a7658293
commit
e7bf2a4b47
1 changed files with 9 additions and 1 deletions
10
src/index.ts
10
src/index.ts
|
@ -9,11 +9,19 @@ import {sequelize} from './utils/db';
|
||||||
let bot = container.get<Bot>(TYPES.Bot);
|
let bot = container.get<Bot>(TYPES.Bot);
|
||||||
const spotify = container.get<Spotify>(TYPES.Lib.Spotify);
|
const spotify = container.get<Spotify>(TYPES.Lib.Spotify);
|
||||||
|
|
||||||
(async () => {
|
const refreshSpotifyToken = async () => {
|
||||||
const auth = await spotify.clientCredentialsGrant();
|
const auth = await spotify.clientCredentialsGrant();
|
||||||
|
|
||||||
spotify.setAccessToken(auth.body.access_token);
|
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
|
// Create data directories if necessary
|
||||||
await makeDir(container.get(TYPES.Config.DATA_DIR));
|
await makeDir(container.get(TYPES.Config.DATA_DIR));
|
||||||
await makeDir(container.get(TYPES.Config.CACHE_DIR));
|
await makeDir(container.get(TYPES.Config.CACHE_DIR));
|
||||||
|
|
Loading…
Add table
Reference in a new issue