forked from cadence/out-of-your-element
Compare commits
2 commits
d8e6de62e5
...
e19703ef03
Author | SHA1 | Date | |
---|---|---|---|
e19703ef03 | |||
42b331135d |
15 changed files with 46 additions and 23 deletions
|
@ -12,6 +12,7 @@ if (!channelID) {
|
||||||
|
|
||||||
const assert = require("assert/strict")
|
const assert = require("assert/strict")
|
||||||
const sqlite = require("better-sqlite3")
|
const sqlite = require("better-sqlite3")
|
||||||
|
const path = require("path")
|
||||||
const backfill = new sqlite("scripts/backfill.db")
|
const backfill = new sqlite("scripts/backfill.db")
|
||||||
backfill.prepare("CREATE TABLE IF NOT EXISTS backfill (channel_id TEXT NOT NULL, message_id INTEGER NOT NULL, PRIMARY KEY (channel_id, message_id))").run()
|
backfill.prepare("CREATE TABLE IF NOT EXISTS backfill (channel_id TEXT NOT NULL, message_id INTEGER NOT NULL, PRIMARY KEY (channel_id, message_id))").run()
|
||||||
|
|
||||||
|
@ -19,9 +20,10 @@ const HeatSync = require("heatsync")
|
||||||
|
|
||||||
const {reg} = require("../src/matrix/read-registration")
|
const {reg} = require("../src/matrix/read-registration")
|
||||||
const passthrough = require("../src/passthrough")
|
const passthrough = require("../src/passthrough")
|
||||||
|
const {getDatabase} = require("../src/db/database")
|
||||||
|
|
||||||
const sync = new HeatSync({watchFS: false})
|
const sync = new HeatSync({watchFS: false})
|
||||||
const db = new sqlite("ooye.db")
|
const db = getDatabase()
|
||||||
Object.assign(passthrough, {sync, db})
|
Object.assign(passthrough, {sync, db})
|
||||||
|
|
||||||
const DiscordClient = require("../src/d2m/discord-client")
|
const DiscordClient = require("../src/d2m/discord-client")
|
||||||
|
|
|
@ -4,10 +4,9 @@
|
||||||
// Trigger the database migration flow and exit after committing.
|
// Trigger the database migration flow and exit after committing.
|
||||||
// You can use this to run migrations locally and check the result using sqlitebrowser.
|
// You can use this to run migrations locally and check the result using sqlitebrowser.
|
||||||
|
|
||||||
const sqlite = require("better-sqlite3")
|
|
||||||
|
|
||||||
const passthrough = require("../src/passthrough")
|
const passthrough = require("../src/passthrough")
|
||||||
const db = new sqlite("ooye.db")
|
const {getDatabase} = require("../src/db/database")
|
||||||
|
const db = getDatabase()
|
||||||
const migrate = require("../src/db/migrate")
|
const migrate = require("../src/db/migrate")
|
||||||
|
|
||||||
Object.assign(passthrough, {db})
|
Object.assign(passthrough, {db})
|
||||||
|
|
|
@ -16,7 +16,8 @@ const oldAT = reg.old_bridge.as_token
|
||||||
const newAT = reg.as_token
|
const newAT = reg.as_token
|
||||||
|
|
||||||
const oldDB = new sqlite(reg.old_bridge.database)
|
const oldDB = new sqlite(reg.old_bridge.database)
|
||||||
const db = new sqlite("ooye.db")
|
const {getDatabase} = require("../src/db/database")
|
||||||
|
const db = getDatabase()
|
||||||
|
|
||||||
db.exec(`CREATE TABLE IF NOT EXISTS half_shot_migration (
|
db.exec(`CREATE TABLE IF NOT EXISTS half_shot_migration (
|
||||||
discord_channel TEXT NOT NULL,
|
discord_channel TEXT NOT NULL,
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
const HeatSync = require("heatsync")
|
const HeatSync = require("heatsync")
|
||||||
const sync = new HeatSync({watchFS: false})
|
const sync = new HeatSync({watchFS: false})
|
||||||
|
|
||||||
const sqlite = require("better-sqlite3")
|
const {getDatabase} = require("../src/db/database")
|
||||||
const db = new sqlite("db/ooye.db")
|
const db = getDatabase()
|
||||||
|
|
||||||
const passthrough = require("../src/passthrough")
|
const passthrough = require("../src/passthrough")
|
||||||
Object.assign(passthrough, {db, sync})
|
Object.assign(passthrough, {db, sync})
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
// @ts-check
|
// @ts-check
|
||||||
|
|
||||||
const sqlite = require("better-sqlite3")
|
|
||||||
const HeatSync = require("heatsync")
|
const HeatSync = require("heatsync")
|
||||||
|
|
||||||
const {reg} = require("../src/matrix/read-registration")
|
const {reg} = require("../src/matrix/read-registration")
|
||||||
const passthrough = require("../src/passthrough")
|
const passthrough = require("../src/passthrough")
|
||||||
const db = new sqlite("ooye.db")
|
const {getDatabase} = require("../src/db/database")
|
||||||
|
const db = getDatabase()
|
||||||
|
|
||||||
const sync = new HeatSync({watchFS: false})
|
const sync = new HeatSync({watchFS: false})
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
// @ts-check
|
// @ts-check
|
||||||
|
|
||||||
const sqlite = require("better-sqlite3")
|
|
||||||
const HeatSync = require("heatsync")
|
const HeatSync = require("heatsync")
|
||||||
|
|
||||||
const passthrough = require("../src/passthrough")
|
const passthrough = require("../src/passthrough")
|
||||||
const db = new sqlite("ooye.db")
|
const {getDatabase} = require("../src/db/database")
|
||||||
|
const db = getDatabase()
|
||||||
|
|
||||||
const sync = new HeatSync({watchFS: false})
|
const sync = new HeatSync({watchFS: false})
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,8 @@ if (fs.existsSync("db")) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const passthrough = require("../src/passthrough")
|
const passthrough = require("../src/passthrough")
|
||||||
const db = new sqlite("ooye.db")
|
const {getDatabase} = require("../src/db/database")
|
||||||
|
const db = getDatabase()
|
||||||
const migrate = require("../src/db/migrate")
|
const migrate = require("../src/db/migrate")
|
||||||
|
|
||||||
const sync = new HeatSync({watchFS: false})
|
const sync = new HeatSync({watchFS: false})
|
||||||
|
|
|
@ -4,13 +4,13 @@
|
||||||
const {createServer} = require("http")
|
const {createServer} = require("http")
|
||||||
const EventEmitter = require("events")
|
const EventEmitter = require("events")
|
||||||
const {createApp, createRouter, toNodeListener} = require("h3")
|
const {createApp, createRouter, toNodeListener} = require("h3")
|
||||||
const sqlite = require("better-sqlite3")
|
|
||||||
const migrate = require("../src/db/migrate")
|
const migrate = require("../src/db/migrate")
|
||||||
const HeatSync = require("heatsync")
|
const HeatSync = require("heatsync")
|
||||||
|
|
||||||
const {reg} = require("../src/matrix/read-registration")
|
const {reg} = require("../src/matrix/read-registration")
|
||||||
const passthrough = require("../src/passthrough")
|
const passthrough = require("../src/passthrough")
|
||||||
const db = new sqlite("ooye.db")
|
const {getDatabase} = require("../src/db/database")
|
||||||
|
const db = getDatabase()
|
||||||
|
|
||||||
const sync = new HeatSync()
|
const sync = new HeatSync()
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
// @ts-check
|
// @ts-check
|
||||||
|
|
||||||
const sqlite = require("better-sqlite3")
|
const {getDatabase} = require("../src/db/database")
|
||||||
const db = new sqlite("ooye.db", {fileMustExist: true})
|
const db = getDatabase({fileMustExist: true})
|
||||||
db.pragma("journal_mode = wal")
|
db.pragma("journal_mode = wal")
|
||||||
db.close()
|
db.close()
|
||||||
|
|
|
@ -40,7 +40,9 @@ const PRIVACY_ENUMS = {
|
||||||
|
|
||||||
const DEFAULT_PRIVACY_LEVEL = 0
|
const DEFAULT_PRIVACY_LEVEL = 0
|
||||||
|
|
||||||
const READ_ONLY_ROOM_EVENTS_DEFAULT_POWER = 50
|
function getReadOnlyRoomEventsDefaultPower() {
|
||||||
|
return reg.ooye.read_only_room_events_default_power ?? 50
|
||||||
|
}
|
||||||
|
|
||||||
/** @type {Map<string, Promise<string>>} channel ID -> Promise<room ID> */
|
/** @type {Map<string, Promise<string>>} channel ID -> Promise<room ID> */
|
||||||
const inflightRoomCreate = new Map()
|
const inflightRoomCreate = new Map()
|
||||||
|
@ -148,7 +150,7 @@ async function channelToKState(channel, guild, di) {
|
||||||
"m.room.join_rules/": join_rules,
|
"m.room.join_rules/": join_rules,
|
||||||
/** @type {Ty.Event.M_Power_Levels} */
|
/** @type {Ty.Event.M_Power_Levels} */
|
||||||
"m.room.power_levels/": {
|
"m.room.power_levels/": {
|
||||||
events_default: everyoneCanSend ? 0 : READ_ONLY_ROOM_EVENTS_DEFAULT_POWER,
|
events_default: everyoneCanSend ? 0 : getReadOnlyRoomEventsDefaultPower(),
|
||||||
events: {
|
events: {
|
||||||
"m.reaction": 0,
|
"m.reaction": 0,
|
||||||
"m.room.redaction": 0 // only affects redactions of own events, required to be able to un-react
|
"m.room.redaction": 0 // only affects redactions of own events, required to be able to un-react
|
||||||
|
@ -559,7 +561,7 @@ async function createAllForGuild(guildID) {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.DEFAULT_PRIVACY_LEVEL = DEFAULT_PRIVACY_LEVEL
|
module.exports.DEFAULT_PRIVACY_LEVEL = DEFAULT_PRIVACY_LEVEL
|
||||||
module.exports.READ_ONLY_ROOM_EVENTS_DEFAULT_POWER = READ_ONLY_ROOM_EVENTS_DEFAULT_POWER
|
module.exports.getReadOnlyRoomEventsDefaultPower = getReadOnlyRoomEventsDefaultPower
|
||||||
module.exports.PRIVACY_ENUMS = PRIVACY_ENUMS
|
module.exports.PRIVACY_ENUMS = PRIVACY_ENUMS
|
||||||
module.exports.createRoom = createRoom
|
module.exports.createRoom = createRoom
|
||||||
module.exports.ensureRoom = ensureRoom
|
module.exports.ensureRoom = ensureRoom
|
||||||
|
|
|
@ -165,7 +165,7 @@ function memberToPowerLevel(user, member, guild, channel) {
|
||||||
/* PL 50 = if room is read-only but the user has been specially allowed to send messages */
|
/* PL 50 = if room is read-only but the user has been specially allowed to send messages */
|
||||||
const everyoneCanSend = utils.hasPermission(everyonePermissions, DiscordTypes.PermissionFlagsBits.SendMessages)
|
const everyoneCanSend = utils.hasPermission(everyonePermissions, DiscordTypes.PermissionFlagsBits.SendMessages)
|
||||||
const userCanSend = utils.hasPermission(permissions, DiscordTypes.PermissionFlagsBits.SendMessages)
|
const userCanSend = utils.hasPermission(permissions, DiscordTypes.PermissionFlagsBits.SendMessages)
|
||||||
if (!everyoneCanSend && userCanSend) return createRoom.READ_ONLY_ROOM_EVENTS_DEFAULT_POWER
|
if (!everyoneCanSend && userCanSend) return createRoom.getReadOnlyRoomEventsDefaultPower()
|
||||||
/* PL 20 = Mention Everyone for technical reasons. */
|
/* PL 20 = Mention Everyone for technical reasons. */
|
||||||
const everyoneCanMentionEveryone = utils.hasPermission(everyonePermissions, DiscordTypes.PermissionFlagsBits.MentionEveryone)
|
const everyoneCanMentionEveryone = utils.hasPermission(everyonePermissions, DiscordTypes.PermissionFlagsBits.MentionEveryone)
|
||||||
const userCanMentionEveryone = utils.hasPermission(permissions, DiscordTypes.PermissionFlagsBits.MentionEveryone)
|
const userCanMentionEveryone = utils.hasPermission(permissions, DiscordTypes.PermissionFlagsBits.MentionEveryone)
|
||||||
|
|
16
src/db/database.js
Normal file
16
src/db/database.js
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
// @ts-check
|
||||||
|
|
||||||
|
const sqlite = require("better-sqlite3")
|
||||||
|
const path = require("path")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new SQLite database instance
|
||||||
|
* @param {import("better-sqlite3").Options} [options] - SQLite options
|
||||||
|
* @returns {import("better-sqlite3").Database} Database instance
|
||||||
|
*/
|
||||||
|
function getDatabase(options = {}) {
|
||||||
|
const dataDir = process.env.OOYE_DATA_DIR || process.cwd()
|
||||||
|
return new sqlite(path.join(dataDir, "ooye.db"), options)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {getDatabase}
|
|
@ -57,7 +57,8 @@ function getTemplateRegistration(serverName) {
|
||||||
max_file_size: 5000000,
|
max_file_size: 5000000,
|
||||||
content_length_workaround: false,
|
content_length_workaround: false,
|
||||||
include_user_id_in_mxid: false,
|
include_user_id_in_mxid: false,
|
||||||
invite: []
|
invite: [],
|
||||||
|
read_only_room_events_default_power: 50
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
1
src/types.d.ts
vendored
1
src/types.d.ts
vendored
|
@ -31,6 +31,7 @@ export type AppServiceRegistrationConfig = {
|
||||||
discord_origin?: string
|
discord_origin?: string
|
||||||
discord_cdn_origin?: string,
|
discord_cdn_origin?: string,
|
||||||
web_password: string
|
web_password: string
|
||||||
|
read_only_room_events_default_power?: number
|
||||||
}
|
}
|
||||||
old_bridge?: {
|
old_bridge?: {
|
||||||
as_token: string
|
as_token: string
|
||||||
|
|
4
start.js
4
start.js
|
@ -2,13 +2,13 @@
|
||||||
// @ts-check
|
// @ts-check
|
||||||
|
|
||||||
const fs = require("fs")
|
const fs = require("fs")
|
||||||
const sqlite = require("better-sqlite3")
|
|
||||||
const migrate = require("./src/db/migrate")
|
const migrate = require("./src/db/migrate")
|
||||||
const HeatSync = require("heatsync")
|
const HeatSync = require("heatsync")
|
||||||
|
|
||||||
const {reg} = require("./src/matrix/read-registration")
|
const {reg} = require("./src/matrix/read-registration")
|
||||||
const passthrough = require("./src/passthrough")
|
const passthrough = require("./src/passthrough")
|
||||||
const db = new sqlite("ooye.db")
|
const {getDatabase} = require("./src/db/database")
|
||||||
|
const db = getDatabase()
|
||||||
|
|
||||||
const sync = new HeatSync({watchFunction: fs.watchFile})
|
const sync = new HeatSync({watchFunction: fs.watchFile})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue