diff --git a/d2m/actions/register-user.js b/d2m/actions/register-user.js index 325a3d0..a23147d 100644 --- a/d2m/actions/register-user.js +++ b/d2m/actions/register-user.js @@ -1,20 +1,42 @@ // @ts-check -const reg = require("../../matrix/read-registration.js") -const fetch = require("node-fetch").default +const assert = require("assert") -fetch("https://matrix.cadence.moe/_matrix/client/v3/register", { - method: "POST", - body: JSON.stringify({ +const passthrough = require("../../passthrough") +const { discord, sync, db } = passthrough +/** @type {import("../../matrix/mreq")} */ +const mreq = sync.require("../../matrix/mreq") +/** @type {import("../../matrix/file")} */ +const file = sync.require("../../matrix/file") + +async function registerUser(username) { + assert.ok(username.startsWith("_ooye_")) + /** @type {import("../../types").R.Registered} */ + const res = await mreq.mreq("POST", "/client/v3/register", { type: "m.login.application_service", - username: "_ooye_example" - }), - headers: { - Authorization: `Bearer ${reg.as_token}` - } -}).then(res => res.text()).then(text => { - // {"user_id":"@_ooye_example:cadence.moe","home_server":"cadence.moe","access_token":"XXX","device_id":"XXX"} - console.log(text) -}).catch(err => { - console.log(err) -}) + username + }) + return res +} + +/** + * A sim is an account that is being simulated by the bridge to copy events from the other side. + * @param {import("discord-api-types/v10").APIUser} user + */ +async function createSim(user) { + assert.notEqual(user.discriminator, "0000", "user is not a webhook") + fetch("https://matrix.cadence.moe/_matrix/client/v3/register", { + method: "POST", + body: JSON.stringify({ + type: "m.login.application_service", + username: "_ooye_example" + }), + headers: { + Authorization: `Bearer ${reg.as_token}` + } + }).then(res => res.text()).then(text => { + + console.log(text) + }).catch(err => { + console.log(err) + }) diff --git a/types.d.ts b/types.d.ts index 1f00836..8d15d6b 100644 --- a/types.d.ts +++ b/types.d.ts @@ -46,4 +46,12 @@ namespace R { export type FileUploaded = { content_uri: string } + + export type Registered = { + /** "@localpart:domain.tld" */ + user_id: string + home_server: string + access_token: string + device_id: string + } }