-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
58 lines (49 loc) · 1.98 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const Discord = require('discord.js');
require('dotenv').config();
const figlet = require('figlet');
const bot = require('./lib/bot')
const cache = require('./lib/cache')
const logger = require('./lib/logger')
const nameMatcher = require('./lib/nameMatcher')
const scheduleStore = require('./lib/scheduleStore')
const gameStatusStore = require('./lib/gameStatusStore')
const nameLookups = require('./lib/nameLookups')
const spreadsheetHandler = require('./lib/spreadsheetHandler')
const client = new Discord.Client({
intents: [32768], // MESSAGE_CONTENT
retryLimit: Infinity
});
client.login(process.env.BOT_TOKEN)
client.on('ready', async () => {
// load the player names
const spreadsheetData = await cache.resolveCache(process.env.CACHE_PLAYERS, 'players', async function() {
return await spreadsheetHandler.loadSpreadsheetData()
})
nameMatcher.refreshPlayersAndTeamsList(spreadsheetData)
scheduleStore.refreshScheduleByWeek(spreadsheetData.scheduleByWeek)
gameStatusStore.refreshGameStatus(spreadsheetData.gameSubmissionStatus)
nameLookups.setSpreadsheetData(spreadsheetData)
// load the settings
const settings = await cache.resolveCache(process.env.CACHE_SETTINGS, 'settings', async function() {
return await spreadsheetHandler.loadSettings()
})
config = {
mainGuild: null,
mainChannel: null,
settings: settings,
}
// get the guild
config.guild = await client.guilds.fetch(process.env.DISCORD_SERVER_ID);
if (config.guild == null) {
throw new Error("Could not find guild")
}
// get the main stats channel
config.mainChannel = await config.guild.channels.cache.find(channel => channel.name === process.env.DISCORD_STATS_MAIN_CHANNEL);
if (config.mainChannel == null) {
throw new Error("Could not find channel")
}
// ready
console.log(figlet.textSync('OF Stats Bot 2.1', {font: 'Big'}))
console.log('is connected and ready.')
bot.run(client, config)
});