seed initial setup
This commit is contained in:
parent
22dde9faf7
commit
38d7db5071
4 changed files with 57 additions and 2 deletions
|
@ -91,6 +91,18 @@ async function sendEvent(roomID, type, content, mxid) {
|
||||||
return root.event_id
|
return root.event_id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function profileSetDisplayname(mxid, displayname) {
|
||||||
|
await mreq.mreq("PUT", path(`/client/v3/profile/${mxid}/displayname`, mxid), {
|
||||||
|
displayname
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function profileSetAvatarUrl(mxid, avatar_url) {
|
||||||
|
await mreq.mreq("PUT", path(`/client/v3/profile/${mxid}/avatar_url`, mxid), {
|
||||||
|
avatar_url
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.path = path
|
module.exports.path = path
|
||||||
module.exports.register = register
|
module.exports.register = register
|
||||||
module.exports.createRoom = createRoom
|
module.exports.createRoom = createRoom
|
||||||
|
@ -99,3 +111,5 @@ module.exports.inviteToRoom = inviteToRoom
|
||||||
module.exports.getAllState = getAllState
|
module.exports.getAllState = getAllState
|
||||||
module.exports.sendState = sendState
|
module.exports.sendState = sendState
|
||||||
module.exports.sendEvent = sendEvent
|
module.exports.sendEvent = sendEvent
|
||||||
|
module.exports.profileSetDisplayname = profileSetDisplayname
|
||||||
|
module.exports.profileSetAvatarUrl = profileSetAvatarUrl
|
||||||
|
|
|
@ -17,7 +17,14 @@ const inflight = new Map()
|
||||||
* @param {string} path
|
* @param {string} path
|
||||||
*/
|
*/
|
||||||
async function uploadDiscordFileToMxc(path) {
|
async function uploadDiscordFileToMxc(path) {
|
||||||
const url = DISCORD_IMAGES_BASE + path
|
let url
|
||||||
|
if (path.startsWith("http")) {
|
||||||
|
// TODO: this is cheating to make seed.js easier. due a refactor or a name change since it's not soley for discord?
|
||||||
|
// possibly could be good to save non-discord external URLs under a user-specified key rather than simply using the url?
|
||||||
|
url = path
|
||||||
|
} else {
|
||||||
|
url = DISCORD_IMAGES_BASE + path
|
||||||
|
}
|
||||||
|
|
||||||
// Are we uploading this file RIGHT NOW? Return the same inflight promise with the same resolution
|
// Are we uploading this file RIGHT NOW? Return the same inflight promise with the same resolution
|
||||||
let existing = inflight.get(url)
|
let existing = inflight.get(url)
|
||||||
|
|
35
seed.js
Normal file
35
seed.js
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
// @ts-check
|
||||||
|
|
||||||
|
const assert = require("assert")
|
||||||
|
const sqlite = require("better-sqlite3")
|
||||||
|
const HeatSync = require("heatsync")
|
||||||
|
|
||||||
|
const config = require("./config")
|
||||||
|
const passthrough = require("./passthrough")
|
||||||
|
const db = new sqlite("db/ooye.db")
|
||||||
|
|
||||||
|
const sync = new HeatSync({watchFS: false})
|
||||||
|
|
||||||
|
Object.assign(passthrough, { config, sync, db })
|
||||||
|
|
||||||
|
const api = require("./matrix/api")
|
||||||
|
const file = require("./matrix/file")
|
||||||
|
const reg = require("./matrix/read-registration")
|
||||||
|
|
||||||
|
;(async () => {
|
||||||
|
// ensure registration is correctly set...
|
||||||
|
|
||||||
|
// test connection to homeserver...
|
||||||
|
|
||||||
|
// upload initial images...
|
||||||
|
const avatarUrl = await file.uploadDiscordFileToMxc("https://cadence.moe/friends/out_of_your_element_rev_2.jpg")
|
||||||
|
|
||||||
|
// set profile data on homeserver...
|
||||||
|
await api.profileSetDisplayname(`@${reg.sender_localpart}:cadence.moe`, "Out Of Your Element")
|
||||||
|
await api.profileSetAvatarUrl(`@${reg.sender_localpart}:cadence.moe`, avatarUrl)
|
||||||
|
|
||||||
|
// database ddl...
|
||||||
|
|
||||||
|
// add initial rows to database, like adding the bot to sim...
|
||||||
|
|
||||||
|
})()
|
|
@ -7,7 +7,6 @@ const config = require("../config")
|
||||||
const passthrough = require("../passthrough")
|
const passthrough = require("../passthrough")
|
||||||
const db = new sqlite("db/ooye.db")
|
const db = new sqlite("db/ooye.db")
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
const sync = new HeatSync({watchFS: false})
|
const sync = new HeatSync({watchFS: false})
|
||||||
|
|
||||||
Object.assign(passthrough, { config, sync, db })
|
Object.assign(passthrough, { config, sync, db })
|
||||||
|
|
Loading…
Reference in a new issue