-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.js
More file actions
96 lines (73 loc) · 2.49 KB
/
app.js
File metadata and controls
96 lines (73 loc) · 2.49 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const winston = require('winston');
const nconf = require('nconf');
const { Client, Collection, GatewayIntentBits } = require('discord.js');
const _ = require('lodash');
const { CronJob } = require('cron');
const Keyv = require('keyv');
const express = require('express');
const { useSqlite } = require('./settings');
let keyv;
if (useSqlite) {
keyv = new Keyv('sqlite://database.sqlite');
} else {
keyv = new Keyv(process.env.DATABASE_URL, {
ssl: {
require: true,
rejectUnauthorized: false,
},
});
}
const winstonOptions = {
colorize: true,
timestamp: true,
handleExceptions: true,
prettyPrint: true,
format: winston.format.simple(),
};
if (process.env.LOG_LEVEL) {
winstonOptions.level = process.env.LOG_LEVEL;
} else if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
winstonOptions.level = 'debug';
} else {
winstonOptions.level = 'info';
}
winston.add(new winston.transports.Console(winstonOptions));
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.commands = new Collection();
const commands = require('./commands');
_.each(commands, (command) => {
client.commands.set(command.data.name, command);
});
client.once('ready', async () => {
winston.info('Ready!');
const version = await keyv.get('version');
if (!version) {
const channels = client.channels.cache.filter((channel) => channel.name.startsWith('core-meta'));
channels.forEach((channel) => {
channel.send('Oh no! I\'ve forgotten everything :see_no_evil: please tell me what the next release is with `/release-next <version> <date>`');
});
}
});
client.on('interactionCreate', async (interaction) => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction, keyv);
} catch (error) {
winston.error('error executing command', {
command,
error,
});
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
});
const cronJobs = require('./cron');
_.each(cronJobs, (cronJob) => {
// eslint-disable-next-line no-new
new CronJob(cronJob.cron, cronJob.job(client, keyv), null, true, 'UTC');
});
client.login(nconf.get('token'));
const app = express();
app.get('/', (req, res) => res.send('Hello World!'));
app.listen(process.env.PORT, () => console.log(`Example app listening at http://localhost:${process.env.PORT}`));