-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.js
84 lines (79 loc) · 2.68 KB
/
bot.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
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
var Discord = require('discord.js');
var auth = require('./auth.json');
var api = require('./api.js');
var client = new Discord.Client();
client.once('ready', () => {
console.log('Ready!');
client.user.setActivity('https://covid-19-ab-discord-bot.glitch.me/', {
type: 'PLAYING'
})
.then(presence => console.log(`Activity set to ${presence.activities[0].name}`))
.catch(console.error);
});
client.login(auth.token);
client.on('message', async function (message) {
if (message.content.substring(0, 1) == '!') {
var args = message.content.substring(1).split(' ');
var cmd = args[0];
if (['help', 'info', 'information', 'cases', 'locations', 'recovery', 'recoveries', 'stats', 'statistics', 'testing'].indexOf(cmd) > -1) {
args = args.splice(1);
message.channel.startTyping();
switch (cmd) {
case 'help':
message.channel.send(new Discord.MessageEmbed()
.setColor('#00aad2')
.setTitle('Help')
.addFields(
{ name: '!info / !information', value: 'hyperlink to official website' },
{ name: '!cases / !locations', value: 'view number of cases and their locations' },
{ name: '!recovery / !recoveries', value: 'overview of recoveries in Alberta' },
{ name: '!stats / !statistics', value: 'hyperlink to official statistics website' },
{ name: '!testing', value: 'overview of testing in Alberta' }
));
break;
case 'info':
case 'information':
message.channel.send(new Discord.MessageEmbed()
.setColor('#00aad2')
.setTitle('Information')
.setDescription('Hyperlink to offical website')
.setURL('https://www.alberta.ca/coronavirus-info-for-albertans.aspx')
);
break;
case 'cases':
case 'locations':
message.channel.send(await api.getLocationsEmbed());
break;
case 'testing':
message.channel.send(await api.getTestingEmbed());
break;
case 'recovery':
case 'recoveries':
message.channel.send(await api.getRecoveriesEmbed());
break;
case 'stats':
case 'statistics':
message.channel.send(new Discord.MessageEmbed()
.setColor('#00aad2')
.setTitle('Statistics')
.setDescription('Hyperlink to offical statistics website.')
.setURL('https://covid19stats.alberta.ca/')
);
break;
}
message.channel.stopTyping();
}
}
});
//for glitch.com hosting
// const fetch = require('node-fetch');
// const express = require('express');
// const app = express();
// app.get("/", (request, response) => {
// console.log(Date.now() + " Ping Received");
// response.sendStatus(200);
// });
// app.listen(process.env.PORT);
// setInterval(() => {
// fetch(`http://${process.env.PROJECT_DOMAIN}.glitch.me/`);
// }, 280000);