muse/src/index.ts

26 lines
742 B
TypeScript
Raw Normal View History

2020-03-13 04:41:26 +01:00
import Spotify from 'spotify-web-api-node';
2020-03-17 01:37:54 +01:00
import makeDir from 'make-dir';
2020-03-17 18:30:27 +01:00
import path from 'path';
2020-03-17 01:37:54 +01:00
import container from './inversify.config';
2020-03-13 04:41:26 +01:00
import {TYPES} from './types';
import Bot from './bot';
2020-03-17 01:37:54 +01:00
import {sequelize} from './utils/db';
2020-03-09 17:57:39 +01:00
2020-03-13 04:41:26 +01:00
let bot = container.get<Bot>(TYPES.Bot);
const spotify = container.get<Spotify>(TYPES.Lib.Spotify);
2020-03-09 17:57:39 +01:00
2020-03-13 04:41:26 +01:00
(async () => {
const auth = await spotify.clientCredentialsGrant();
2020-03-09 17:57:39 +01:00
2020-03-13 04:41:26 +01:00
spotify.setAccessToken(auth.body.access_token);
2020-03-09 17:57:39 +01:00
2020-03-17 01:37:54 +01:00
// Create data directories if necessary
await makeDir(container.get(TYPES.Config.DATA_DIR));
await makeDir(container.get(TYPES.Config.CACHE_DIR));
2020-03-17 18:30:27 +01:00
await makeDir(path.join(container.get(TYPES.Config.CACHE_DIR), 'tmp'));
2020-03-17 01:37:54 +01:00
await sequelize.sync({});
2020-03-13 04:41:26 +01:00
bot.listen();
})();