-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
57 lines (49 loc) · 1.34 KB
/
main.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
import Logger from "https://deno.land/x/logger@v1.1.2/logger.ts";
const logger = new Logger();
async function loadSettings(path) {
logger.info("Loading settings.");
return JSON.parse(await Deno.readTextFile(path));
}
function setupWatcher(networkSettings) {
new Worker(new URL("./src/watcher.js", import.meta.url).href, {
type: "module",
deno: {
permissions: {
net: "inherit",
read: false,
env: false,
},
},
}).postMessage(networkSettings);
}
function setupBot(botSettings) {
new Worker(new URL("./src/bot.js", import.meta.url).href, {
type: "module",
deno: {
permissions: {
net: "inherit",
read: "inherit",
env: false,
},
},
}).postMessage(botSettings);
}
const settings = await loadSettings("./settings.json");
logger.info("Starting up bot.");
setupBot({
discordToken: Deno.env.get("DISCORD_TOKEN"),
botSettings: settings.botSettings,
});
logger.info("Setting up network watchers.");
settings.networks.forEach((element) => {
logger.info("Setting up " + element.name + " watcher.");
setupWatcher({
...element,
priceConversionApi: {
url: settings.priceConversionApi.url,
token: Deno.env.get("COINMARKETCAP_KEY"),
},
webhookUrl: Deno.env.get("DISCORD_WEBHOOK_URL"),
webhookTemplate: settings.webhookTemplate,
});
});