-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (35 loc) · 1.43 KB
/
index.js
File metadata and controls
41 lines (35 loc) · 1.43 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
const Discord = require('discord.js');
const winston = require('winston');
const Elasticsearch = require('winston-elasticsearch');
const config = require('./config.json');
const { initialiseLogger } = require('./logger.js');
const { matchCommand, dailyTasks } = require('./commands.js');
const client = new Discord.Client();
const logger = initialiseLogger(config, winston, Elasticsearch);
client.login(config.token);
client.once('ready', () => {
logger.info('MupBot logged in successfully!');
setInterval(function () {
const hour = new Date().getHours();
if (hour == 8) {
// Run the daily tasks at 8am every day (server time)
dailyTasks(client);
}
}, 1000 * 60 * 60); // every hour
});
client.on('message', function (message) {
// If someone tags the bot
if (message.mentions.has(client.user.id)) {
message.channel.send(`That's my name, don't wear it out!`);
}
// Ignore messages from the bot and that don't begin with the prefix, and do not run in DMs to bot
if (message.author.bot) return;
if (!message.content.startsWith(config.prefix)) return;
if (message.channel instanceof Discord.DMChannel) return;
// Split out the fields we need from the message
const commandBody = message.content.slice(config.prefix.length);
const args = commandBody.split(' ');
const command = args.shift().toLowerCase();
// Run the matching command
matchCommand(Discord, config, logger, message, command, args);
});