forked from PartMan7/PartProfessor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatcher.js
More file actions
76 lines (76 loc) · 2.39 KB
/
watcher.js
File metadata and controls
76 lines (76 loc) · 2.39 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
module.exports = function watcher () {
const watchers = [];
const watchHots = [{
path: './data/ALIASES',
name: 'aliases'
}, {
path: './autores.js',
name: 'autores'
}, {
path: './chat.js',
name: 'chat'
}, {
path: './discord_chat.js',
name: 'discord'
}, {
path: './data/GAMES',
name: 'games'
}, {
path: './global.js',
name: 'global'
}, {
path: './data/hotpatch.js',
name: 'hotpatch'
}, {
path: './minorhandler.js',
name: 'minor'
}, {
path: './pmhandler.js',
name: 'pms'
}, {
path: './router.js',
name: 'router'
}, {
path: './ticker.js',
name: 'ticker'
}, {
path: './data/tools.js',
name: 'tools'
}, {
path: './tours.js',
name: 'tour'
}, {
path: './watcher.js',
name: 'watcher'
}];
watchHots.forEach(watch => watchers.push(fs.watch(watch.path, (event, name) => {
if (event === 'change') return Bot.hotpatch(watch.name, '*Sentinel').then(res => client.channels.cache.get('848835497845194752').send(`Hotpatched: ${res}`)).catch(err => client.channels.cache.get('848835497845194752').send(`Unable to hotpatch ${watch.name} because: ${err}`));
})));
fs.readdirSync('./commands').forEach(folder => {
watchers.push(fs.watch(`./commands/${folder}`, (event, name) => {
if (event === 'change') delete require.cache[require.resolve(`./commands/${folder}/${name}`)];
}));
});
watchers.push(fs.watch('./commands', (eventName, folder) => {
if (eventName === 'rename') watchers.push(fs.watch(`./commands/${folder}`, (event, name) => {
if (event === 'change') delete require.cache[require.resolve(`./commands/${folder}/${name}`)];
}));
}));
watchers.push(fs.watch('./pmcommands', (event, name) => {
if (event === 'change') delete require.cache[require.resolve(`./pmcommands/${name}`)];
}));
watchers.push(fs.watch('./discord', (event, name) => {
if (event === 'change') delete require.cache[require.resolve(`./discord/${name}`)];
}));
['bot.js', 'client.js'].forEach(file => watchers.push(fs.watch(file, (event, name) => {
if (event === 'change') client.channels.cache.get('848835497845194752').send(`<@!333219724890603520> Changes have been pushed that require a restart`);
})))
return ({
watchers: watchers,
close: () => {
watchers.forEach(swatch => swatch.close());
}
});
// This is untouched, but I'd highly recommend switching out some of the code here and
// setting up a small system to detect Git webhooks and automatically hotpatch.
}