preparations for creating users
This commit is contained in:
parent
3fbe7eed6e
commit
48c2ef76f5
2 changed files with 46 additions and 16 deletions
|
@ -1,9 +1,31 @@
|
||||||
// @ts-check
|
// @ts-check
|
||||||
|
|
||||||
const reg = require("../../matrix/read-registration.js")
|
const assert = require("assert")
|
||||||
const fetch = require("node-fetch").default
|
|
||||||
|
|
||||||
fetch("https://matrix.cadence.moe/_matrix/client/v3/register", {
|
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
|
||||||
|
})
|
||||||
|
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",
|
method: "POST",
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
type: "m.login.application_service",
|
type: "m.login.application_service",
|
||||||
|
@ -12,9 +34,9 @@ fetch("https://matrix.cadence.moe/_matrix/client/v3/register", {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${reg.as_token}`
|
Authorization: `Bearer ${reg.as_token}`
|
||||||
}
|
}
|
||||||
}).then(res => res.text()).then(text => {
|
}).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)
|
console.log(text)
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
})
|
})
|
||||||
|
|
8
types.d.ts
vendored
8
types.d.ts
vendored
|
@ -46,4 +46,12 @@ namespace R {
|
||||||
export type FileUploaded = {
|
export type FileUploaded = {
|
||||||
content_uri: string
|
content_uri: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type Registered = {
|
||||||
|
/** "@localpart:domain.tld" */
|
||||||
|
user_id: string
|
||||||
|
home_server: string
|
||||||
|
access_token: string
|
||||||
|
device_id: string
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue