summary refs log tree commit diff
path: root/start.js
blob: 39e8ea09b62ad1c7ccf7602257899c54be28f742 (plain) (blame)
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
#!/usr/bin/env node
// @ts-check

const fs = require("fs")
const sqlite = require("better-sqlite3")
const migrate = require("./src/db/migrate")
const HeatSync = require("heatsync")

const {reg} = require("./src/matrix/read-registration")
const passthrough = require("./src/passthrough")
const db = new sqlite("ooye.db")

const sync = new HeatSync({watchFunction: fs.watchFile})

Object.assign(passthrough, {sync, db})

const DiscordClient = require("./src/d2m/discord-client")

const discord = new DiscordClient(reg.ooye.discord_token)
passthrough.discord = discord

const {as} = require("./src/matrix/appservice")
passthrough.as = as

const orm = sync.require("./src/db/orm")
passthrough.from = orm.from
passthrough.select = orm.select

const power = require("./src/matrix/power.js")
sync.require("./src/m2d/event-dispatcher")

;(async () => {
	await migrate.migrate(db)
	await discord.cloud.connect()
	console.log("Discord gateway started")
	sync.require("./src/web/server")
	await power.applyPower()

	discord.cloud.once("ready", () => {
		as.listen()
	})

	require("./src/stdin")
})()