-
Notifications
You must be signed in to change notification settings - Fork 7
/
bot.js
108 lines (95 loc) · 2.08 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
try {
var auth = require('./auth.json');
} catch (error) {
var auth = {
'token': process.env.BOT_TOKEN,
'owner': '376358607836545032'
};
}
var timezones = require('./timezones.js');
var Discord = require('discord.js');
var Commando = require('discord.js-commando');
var moment = require('moment');
var momentTimezone = require('moment-timezone');
const path = require('path');
const client = new Commando.Client({
commandPrefix: '?',
owner: auth.owner,
disableEveryone: true
});
global.settings = {
"prefix": "?",
"timezones": timezones.names,
"offsets": timezones.offsets
};
global.toRoleName = function (zoneName) {
return '.' + zoneName;
}
global.listZones = function (msg) {
msg.say('Available timezones:');
msg.say(
settings.timezones.join(", ")
);
}
var zonesLong = [];
settings.timezones.forEach(
(z) => zonesLong.push(toRoleName(z))
);
client.registry
.registerDefaultTypes()
.registerGroups([
['main', 'Main Command Group']
])
.registerDefaultGroups()
.registerDefaultCommands({
eval: false
})
.registerCommandsIn(path.join(__dirname, 'commands'));
guilds = client.guilds;
global.containedZones = function(zoneList, string) {
var zones = [];
zoneList.forEach(
(zone) => {
if (string.includes(zone)) {
zones.push(zone);
}
}
);
return zones;
}
global.containsZones = function(string) {
var cz = containedZones(zonesLong, string).length;
return !!cz;
}
global.updateTimes = function(roles) {
roles.array().forEach(
(role) => {
var zone = containedZones(settings.timezones, role.name)[0];
role.setName(
toRoleName(zone) + " - " + moment().utcOffset(
settings.offsets[
settings.timezones.indexOf(zone)
]
).format('h:mm A')
);
}
);
}
function updateAllTimes() {
guilds.array().forEach(
(guild) => {
updateTimes(
guild.roles.filter(
x => containsZones(x.name)
)
);
}
);
}
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
client.user.setActivity('with time');
updateAllTimes();
});
client.login(auth.token);
setInterval(updateAllTimes, 60*1000);