Compare commits

..

2 commits

12 changed files with 138 additions and 153 deletions

View file

@ -2,8 +2,6 @@
const passthrough = require("../../passthrough")
const { sync, db } = passthrough
/** @type {import("../converters/edit-to-changes")} */
const editToChanges = sync.require("../converters/edit-to-changes")
/** @type {import("../../matrix/api")} */
const api = sync.require("../../matrix/api")
@ -12,7 +10,7 @@ const api = sync.require("../../matrix/api")
*/
async function deleteMessage(data) {
/** @type {string?} */
const roomID = db.prepare("SELECT channel_id FROM channel_room WHERE channel_id = ?").pluck().get(data.channel_id)
const roomID = db.prepare("SELECT room_id FROM channel_room WHERE channel_id = ?").pluck().get(data.channel_id)
if (!roomID) return
/** @type {string[]} */
@ -22,7 +20,6 @@ async function deleteMessage(data) {
// Unfortuately, we can't specify a sender to do the redaction as, unless we find out that info via the audit logs
await api.redactEvent(roomID, eventID)
db.prepare("DELETE from event_message WHERE event_id = ?").run(eventID)
// TODO: Consider whether this code could be reused between edited messages and deleted messages.
}
}

View file

@ -35,11 +35,8 @@ async function editMessage(message, guild) {
// Not redacting as the last action because the last action is likely to be shown in the room preview in clients, and we don't want it to look like somebody actually deleted a message.
for (const eventID of eventsToRedact) {
await api.redactEvent(roomID, eventID, senderMxid)
// TODO: Reconsider whether it's the right thing to do to delete it from our database? I mean, it's literally not there any more... you can't do anything else with it...
// and you definitely want to mark it in *some* way to prevent duplicate redactions...
db.prepare("DELETE from event_message WHERE event_id = ?").run(eventID)
// TODO: If I just redacted part = 0, I should update one of the other events to make it the new part = 0, right?
// TODO: Consider whether this code could be reused between edited messages and deleted messages.
}
// 3. Send all the things.

View file

@ -115,8 +115,14 @@ function calculateProfileEventContentHash(content) {
}
/**
* Sync profile data for a sim user. This function follows the following process:
* 1. Join the sim to the room if needed
* 2. Make an object of what the new room member state content would be, including uploading the profile picture if it hasn't been done before
* 3. Compare against the previously known state content, which is helpfully stored in the database
* 4. If the state content has changes, send it to Matrix and update it in the database for next time
* @param {import("discord-api-types/v10").APIUser} user
* @param {Omit<import("discord-api-types/v10").APIGuildMember, "user">} member
* @returns {Promise<string>} mxid of the updated sim
*/
async function syncUser(user, member, guildID, roomID) {
const mxid = await ensureSimJoined(user, roomID)
@ -128,6 +134,7 @@ async function syncUser(user, member, guildID, roomID) {
await api.sendState(roomID, "m.room.member", mxid, content, mxid)
db.prepare("UPDATE sim_member SET profile_event_content_hash = ? WHERE room_id = ? AND mxid = ?").run(profileEventContentHash, roomID, mxid)
}
return mxid
}
async function syncAllUsersInRoom(roomID) {

View file

@ -23,8 +23,7 @@ async function sendMessage(message, guild) {
let senderMxid = null
if (!message.webhook_id) {
assert(message.member)
senderMxid = await registerUser.ensureSimJoined(message.author, roomID)
await registerUser.syncUser(message.author, message.member, message.guild_id, roomID)
senderMxid = await registerUser.syncUser(message.author, message.member, message.guild_id, roomID)
}
const events = await messageToEvent.messageToEvent(message, guild, {}, {api})

View file

@ -11,7 +11,7 @@ const utils = {
* @param {import("./discord-client")} client
* @param {import("cloudstorm").IGatewayMessage} message
*/
onPacket(client, message) {
async onPacket(client, message) {
// requiring this later so that the client is already constructed by the time event-dispatcher is loaded
/** @type {typeof import("./event-dispatcher")} */
const eventDispatcher = sync.require("./event-dispatcher")
@ -68,16 +68,16 @@ const utils = {
// Event dispatcher for OOYE bridge operations
try {
if (message.t === "MESSAGE_CREATE") {
eventDispatcher.onMessageCreate(client, message.d)
await eventDispatcher.onMessageCreate(client, message.d)
} else if (message.t === "MESSAGE_UPDATE") {
eventDispatcher.onMessageUpdate(client, message.d)
await eventDispatcher.onMessageUpdate(client, message.d)
} else if (message.t === "MESSAGE_DELETE") {
eventDispatcher.onMessageDelete(client, message.d)
await eventDispatcher.onMessageDelete(client, message.d)
} else if (message.t === "MESSAGE_REACTION_ADD") {
eventDispatcher.onReactionAdd(client, message.d)
await eventDispatcher.onReactionAdd(client, message.d)
}
} catch (e) {
// Let OOYE try to handle errors too

View file

@ -27,7 +27,7 @@ module.exports = {
console.error("hit event-dispatcher's error handler with this exception:")
console.error(e) // TODO: also log errors into a file or into the database, maybe use a library for this? or just wing it? definitely need to be able to store the formatted event body to load back in later
console.error(`while handling this ${gatewayMessage.t} gateway event:`)
console.dir(gatewayMessage.d)
console.dir(gatewayMessage.d, {depth: null})
if (Date.now() - lastReportedEvent > 5000) {
lastReportedEvent = Date.now()
@ -60,7 +60,7 @@ module.exports = {
* @param {import("./discord-client")} client
* @param {import("discord-api-types/v10").GatewayMessageCreateDispatchData} message
*/
onMessageCreate(client, message) {
async onMessageCreate(client, message) {
if (message.webhook_id) {
const row = db.prepare("SELECT webhook_id FROM webhook WHERE webhook_id = ?").pluck().get(message.webhook_id)
if (row) {
@ -73,14 +73,14 @@ module.exports = {
if (!channel.guild_id) return // Nothing we can do in direct messages.
const guild = client.guilds.get(channel.guild_id)
if (message.guild_id !== "112760669178241024" && message.guild_id !== "497159726455455754") return // TODO: activate on other servers (requires the space creation flow to be done first)
sendMessage.sendMessage(message, guild)
await sendMessage.sendMessage(message, guild)
},
/**
* @param {import("./discord-client")} client
* @param {import("discord-api-types/v10").GatewayMessageUpdateDispatchData} message
*/
onMessageUpdate(client, data) {
async onMessageUpdate(client, data) {
if (data.webhook_id) {
const row = db.prepare("SELECT webhook_id FROM webhook WHERE webhook_id = ?").pluck().get(data.webhook_id)
if (row) {
@ -98,7 +98,7 @@ module.exports = {
if (!channel.guild_id) return // Nothing we can do in direct messages.
const guild = client.guilds.get(channel.guild_id)
if (message.guild_id !== "112760669178241024" && message.guild_id !== "497159726455455754") return // TODO: activate on other servers (requires the space creation flow to be done first)
editMessage.editMessage(message, guild)
await editMessage.editMessage(message, guild)
}
},
@ -106,19 +106,19 @@ module.exports = {
* @param {import("./discord-client")} client
* @param {import("discord-api-types/v10").GatewayMessageReactionAddDispatchData} data
*/
onReactionAdd(client, data) {
async onReactionAdd(client, data) {
if (data.user_id === client.user.id) return // m2d reactions are added by the discord bot user - do not reflect them back to matrix.
if (data.emoji.id !== null) return // TODO: image emoji reactions
console.log(data)
addReaction.addReaction(data)
await addReaction.addReaction(data)
},
/**
* @param {import("./discord-client")} client
* @param {import("discord-api-types/v10").GatewayMessageDeleteDispatchData} data
*/
onMessageDelete(client, data) {
async onMessageDelete(client, data) {
console.log(data)
deleteMessage.deleteMessage(data)
await deleteMessage.deleteMessage(data)
}
}

94
db/data-for-test.sql Normal file
View file

@ -0,0 +1,94 @@
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS "guild_space" (
"guild_id" TEXT NOT NULL UNIQUE,
"space_id" TEXT NOT NULL UNIQUE,
PRIMARY KEY("guild_id")
);
CREATE TABLE IF NOT EXISTS "file" (
"discord_url" TEXT NOT NULL UNIQUE,
"mxc_url" TEXT NOT NULL UNIQUE,
PRIMARY KEY("discord_url")
);
CREATE TABLE IF NOT EXISTS "sim" (
"discord_id" TEXT NOT NULL UNIQUE,
"sim_name" TEXT NOT NULL UNIQUE,
"localpart" TEXT NOT NULL UNIQUE,
"mxid" TEXT NOT NULL UNIQUE,
PRIMARY KEY("discord_id")
);
CREATE TABLE IF NOT EXISTS "sim_member" (
"mxid" TEXT NOT NULL,
"room_id" TEXT NOT NULL,
"profile_event_content_hash" BLOB,
PRIMARY KEY("mxid","room_id")
);
CREATE TABLE IF NOT EXISTS "webhook" (
"channel_id" TEXT NOT NULL UNIQUE,
"webhook_id" TEXT NOT NULL UNIQUE,
"webhook_token" TEXT NOT NULL,
PRIMARY KEY("channel_id")
);
CREATE TABLE IF NOT EXISTS "channel_room" (
"channel_id" TEXT NOT NULL UNIQUE,
"room_id" TEXT NOT NULL UNIQUE,
"name" TEXT,
"nick" TEXT,
PRIMARY KEY("channel_id")
);
CREATE TABLE IF NOT EXISTS "event_message" (
"event_id" TEXT NOT NULL,
"event_type" TEXT,
"event_subtype" TEXT,
"message_id" TEXT NOT NULL,
"channel_id" TEXT,
"part" INTEGER NOT NULL,
"source" INTEGER NOT NULL,
PRIMARY KEY("event_id","message_id")
);
COMMIT;
BEGIN TRANSACTION;
INSERT INTO guild_space (guild_id, space_id) VALUES
('112760669178241024', '!jjWAGMeQdNrVZSSfvz:cadence.moe');
INSERT INTO channel_room (channel_id, room_id, name, nick) VALUES
('112760669178241024', '!kLRqKKUQXcibIMtOpl:cadence.moe', 'heave', 'main'),
('497161350934560778', '!edUxjVdzgUvXDUIQCK:cadence.moe', 'amanda-spam', NULL),
('160197704226439168', '!uCtjHhfGlYbVnPVlkG:cadence.moe', 'the-stanley-parable-channel', 'bots');
INSERT INTO sim (discord_id, sim_name, localpart, mxid) VALUES
('0', 'bot', '_ooye_bot', '@_ooye_bot:cadence.moe'),
('820865262526005258', 'crunch_god', '_ooye_crunch_god', '@_ooye_crunch_god:cadence.moe'),
('771520384671416320', 'bojack_horseman', '_ooye_bojack_horseman', '@_ooye_bojack_horseman:cadence.moe'),
('112890272819507200', '.wing.', '_ooye_.wing.', '@_ooye_.wing.:cadence.moe'),
('114147806469554185', 'extremity', '_ooye_extremity', '@_ooye_extremity:cadence.moe');
INSERT INTO sim_member (mxid, room_id, profile_event_content_hash) VALUES
('@_ooye_bojack_horseman:cadence.moe', '!uCtjHhfGlYbVnPVlkG:cadence.moe', NULL);
INSERT INTO event_message (event_id, event_type, event_subtype, message_id, channel_id, part, source) VALUES
('$X16nfVks1wsrhq4E9SSLiqrf2N8KD0erD0scZG7U5xg', 'm.room.message', 'm.text', '1126786462646550579', '112760669178241024', 0, 1),
('$Ij3qo7NxMA4VPexlAiIx2CB9JbsiGhJeyt-2OvkAUe4', 'm.room.message', 'm.text', '1128118177155526666', '112760669178241024', 0, 0),
('$zXSlyI78DQqQwwfPUSzZ1b-nXzbUrCDljJgnGDdoI10', 'm.room.message', 'm.text', '1141619794500649020', '497161350934560778', 0, 1),
('$fdD9OZ55xg3EAsfvLZza5tMhtjUO91Wg3Otuo96TplY', 'm.room.message', 'm.text', '1141206225632112650', '160197704226439168', 0, 1),
('$mtR8cJqM4fKno1bVsm8F4wUVqSntt2sq6jav1lyavuA', 'm.room.message', 'm.text', '1141501302736695316', '112760669178241024', 0, 1),
('$51f4yqHinwnSbPEQ9dCgoyy4qiIJSX0QYYVUnvwyTCI', 'm.room.message', 'm.image', '1141501302736695316', '112760669178241024', 1, 1),
('$51f4yqHinwnSbPEQ9dCgoyy4qiIJSX0QYYVUnvwyTCJ', 'm.room.message', 'm.image', '1141501302736695317', '112760669178241024', 0, 1),
('$vgTKOR5ZTYNMKaS7XvgEIDaOWZtVCEyzLLi5Pc5Gz4M', 'm.room.message', 'm.text', '1128084851279536279', '112760669178241024', 0, 1),
('$YUJFa5j0ZJe7PUvD2DykRt9g51RoadUEYmuJLdSEbJ0', 'm.room.message', 'm.image', '1128084851279536279', '112760669178241024', 1, 1),
('$oLyUTyZ_7e_SUzGNWZKz880ll9amLZvXGbArJCKai2Q', 'm.room.message', 'm.text', '1128084748338741392', '112760669178241024', 0, 1);
INSERT INTO file (discord_url, mxc_url) VALUES
('https://cdn.discordapp.com/attachments/497161332244742154/1124628646431297546/image.png', 'mxc://cadence.moe/qXoZktDqNtEGuOCZEADAMvhM'),
('https://cdn.discordapp.com/attachments/122155380120748034/1106366167486038016/image.png', 'mxc://cadence.moe/ZDCNYnkPszxGKgObUIFmvjus'),
('https://cdn.discordapp.com/stickers/1106323941183717586.png', 'mxc://cadence.moe/UuUaLwXhkxFRwwWCXipDlBHn'),
('https://cdn.discordapp.com/attachments/112760669178241024/1128084747910918195/skull.webp', 'mxc://cadence.moe/sDxWmDErBhYBxtDcJQgBETes'),
('https://cdn.discordapp.com/attachments/112760669178241024/1141501302497615912/piper_2.png', 'mxc://cadence.moe/KQYdXKRcHWjDYDLPkTOOWOjA'),
('https://cdn.discordapp.com/attachments/112760669178241024/1128084851023675515/RDT_20230704_0936184915846675925224905.jpg', 'mxc://cadence.moe/WlAbFSiNRIHPDEwKdyPeGywa'),
('https://cdn.discordapp.com/guilds/112760669178241024/users/134826546694193153/avatars/38dd359aa12bcd52dd3164126c587f8c.png?size=1024', 'mxc://cadence.moe/rfemHmAtcprjLEiPiEuzPhpl'),
('https://cdn.discordapp.com/icons/112760669178241024/a_f83622e09ead74f0c5c527fe241f8f8c.png?size=1024', 'mxc://cadence.moe/zKXGZhmImMHuGQZWJEFKJbsF');
COMMIT;

View file

@ -1,120 +0,0 @@
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS "guild_space" (
"guild_id" TEXT NOT NULL UNIQUE,
"space_id" TEXT NOT NULL UNIQUE,
PRIMARY KEY("guild_id")
);
INSERT INTO guild_space VALUES('112760669178241024','!jjWAGMeQdNrVZSSfvz:cadence.moe');
CREATE TABLE IF NOT EXISTS "channel_room" (
"channel_id" TEXT NOT NULL UNIQUE,
"room_id" TEXT NOT NULL UNIQUE,
PRIMARY KEY("channel_id")
);
INSERT INTO channel_room VALUES('395073525641117699','!HfUDHZheYriEncfKpJ:cadence.moe');
INSERT INTO channel_room VALUES('808564048294838284','!uMHZzVXeXPrVehmPIm:cadence.moe');
INSERT INTO channel_room VALUES('694935757160185907','!qAAlGzsrXrLKqAEHas:cadence.moe');
INSERT INTO channel_room VALUES('739017679796436992','!cGIULAxjVJReFZosbK:cadence.moe');
INSERT INTO channel_room VALUES('441910023501774858','!JrwSgmaBchooVnCqcF:cadence.moe');
INSERT INTO channel_room VALUES('841417575120371722','!mwzCPYqPHAHOdeKPMi:cadence.moe');
INSERT INTO channel_room VALUES('488516474735034389','!dqvFUrlHREgNEWmkua:cadence.moe');
INSERT INTO channel_room VALUES('920170211330650152','!sTfMRJPdoqTNzMXvbn:cadence.moe');
INSERT INTO channel_room VALUES('203751294157062145','!repkBsIWwFyOOvudGt:cadence.moe');
INSERT INTO channel_room VALUES('134477188899536898','!uUzBXdWQblkxNmThLz:cadence.moe');
INSERT INTO channel_room VALUES('266767590641238027','!IzOgQiDnusFQiwymaL:cadence.moe');
INSERT INTO channel_room VALUES('834530844743434289','!kczmYjDXhhTVvCRHGE:cadence.moe');
INSERT INTO channel_room VALUES('265998010092093441','!zGfmedYghbfnFQJXjU:cadence.moe');
INSERT INTO channel_room VALUES('339294043274215424','!fNDEjktDGIWAPlMWYy:cadence.moe');
INSERT INTO channel_room VALUES('398661111869865985','!gAnxDqVCDfudmiuwnU:cadence.moe');
INSERT INTO channel_room VALUES('814300638237163550','!GTkemJlzNRPcbXIjHh:cadence.moe');
INSERT INTO channel_room VALUES('112760669178241024','!kLRqKKUQXcibIMtOpl:cadence.moe');
INSERT INTO channel_room VALUES('604901695255740426','!gsMllRhFEUVaVAiJQR:cadence.moe');
INSERT INTO channel_room VALUES('176333891320283136','!pzHnyQchkiIJzfjYlR:cadence.moe');
INSERT INTO channel_room VALUES('350076239257796620','!MkOZEeLWrKJLpYjCig:cadence.moe');
INSERT INTO channel_room VALUES('160197704226439168','!uCtjHhfGlYbVnPVlkG:cadence.moe');
INSERT INTO channel_room VALUES('204427407539568640','!aaBHsbHThhtFBjJnjs:cadence.moe');
INSERT INTO channel_room VALUES('288058913985789953','!TBwEJEXTvbvDSYzyJq:cadence.moe');
INSERT INTO channel_room VALUES('622903842282930198','!RCRvXmNpFSjoFNEmvh:cadence.moe');
INSERT INTO channel_room VALUES('421368191567265794','!cKgTdFmarjJnGDipUE:cadence.moe');
INSERT INTO channel_room VALUES('334553412698112002','!EacGxEcLvxmrSPZoOA:cadence.moe');
INSERT INTO channel_room VALUES('395750520435769347','!btmhtSzFqMYqTzNGmq:cadence.moe');
INSERT INTO channel_room VALUES('196455508146651136','!QGSDlxmJjIGzqmhngS:cadence.moe');
INSERT INTO channel_room VALUES('1089120827926134854','!QlsPSkhOsplXOgvKzG:cadence.moe');
INSERT INTO channel_room VALUES('655216173696286746','!prNIHWeXgudqChdvTJ:cadence.moe');
INSERT INTO channel_room VALUES('171083630985216001','!kEWSvtyEhPFCviOHnA:cadence.moe');
INSERT INTO channel_room VALUES('530220226109898752','!bdNsNYyBQyEdFmeoZd:cadence.moe');
INSERT INTO channel_room VALUES('1075095715396735056','!gPfVCpFUnmoEDVAPph:cadence.moe');
INSERT INTO channel_room VALUES('392141322863116319','!ErHIqXEnsVdvHbFAUO:cadence.moe');
INSERT INTO channel_room VALUES('189898393705906177','!UAXXOjEgIYtexsvzZC:cadence.moe');
INSERT INTO channel_room VALUES('134077753485033472','!qGpHzEREMSFEKDjzdB:cadence.moe');
INSERT INTO channel_room VALUES('696180458417029170','!thbRkzupoPmsxCiWyv:cadence.moe');
INSERT INTO channel_room VALUES('191487489943404544','!nOfpEIzWgaLnRHFoAF:cadence.moe');
INSERT INTO channel_room VALUES('121380024812044288','!QKqjAQJmXwnevnKsGh:cadence.moe');
INSERT INTO channel_room VALUES('687028734322147344','!fGgIymcYWOqjbSRUdV:cadence.moe');
INSERT INTO channel_room VALUES('330164254969823233','!vYZSKYOSArwqWyaJZB:cadence.moe');
INSERT INTO channel_room VALUES('872258827846832139','!INBHUKdIiCMxpizitC:cadence.moe');
INSERT INTO channel_room VALUES('112767097234305024','!bXgJfZZqdFlmmAeYSj:cadence.moe');
INSERT INTO channel_room VALUES('249968792346558465','!CRoJhPJAarFkoOVfUg:cadence.moe');
INSERT INTO channel_room VALUES('130176644093575168','!tgQCmRkBndtQcbhqPX:cadence.moe');
INSERT INTO channel_room VALUES('312054608535224320','!oDNMTEymekxHTizhEC:cadence.moe');
INSERT INTO channel_room VALUES('1099031887500034088','!bexkxPoPBmSuUkvACP:cadence.moe');
INSERT INTO channel_room VALUES('412754166885122048','!ASqMFolSWJsJWAIJqB:cadence.moe');
INSERT INTO channel_room VALUES('700941324810977333','!gLvyxfpmPetCqtOCka:cadence.moe');
INSERT INTO channel_room VALUES('361364140448808960','!yyzLRrLSmYGuNGkbup:cadence.moe');
INSERT INTO channel_room VALUES('132423337019310081','!QcGgaDKBEDvSnFpDUT:cadence.moe');
INSERT INTO channel_room VALUES('698892233398812742','!ASiHdjKOmjyQCmhWEJ:cadence.moe');
INSERT INTO channel_room VALUES('591183598166736908','!NMmIckmkngIVeTLmWM:cadence.moe');
INSERT INTO channel_room VALUES('288882953314893825','!hNBIHkfRMrryuWfPrb:cadence.moe');
INSERT INTO channel_room VALUES('265617582126661642','!YaJsBSpCOtaccZShBy:cadence.moe');
INSERT INTO channel_room VALUES('113414562417496064','!UHfjZYvdnkjqwvOylF:cadence.moe');
INSERT INTO channel_room VALUES('373335332436967424','!cFjDyGrtFmHymyLfRE:cadence.moe');
INSERT INTO channel_room VALUES('331390333810376704','!kdALuKGeNSkYDgRhIZ:cadence.moe');
INSERT INTO channel_room VALUES('768264034327724132','!FEhofHtvWOSNCuvUxW:cadence.moe');
INSERT INTO channel_room VALUES('359903425074561024','!IGixYyKLdvmnAzzOGB:cadence.moe');
INSERT INTO channel_room VALUES('122155380120748034','!iMLtMMlHpWNyAnadZu:cadence.moe');
INSERT INTO channel_room VALUES('325891921463738369','!IsJKZmawitkFurcjwY:cadence.moe');
INSERT INTO channel_room VALUES('805261291908104252','!PAGMqppQIkLaNRwkpN:cadence.moe');
INSERT INTO channel_room VALUES('360567146243293194','!RbrindSuOlbAHAJRFq:cadence.moe');
INSERT INTO channel_room VALUES('295789411856154624','!RbLRKOjmaEafDtOAAJ:cadence.moe');
INSERT INTO channel_room VALUES('279985883560804353','!WuYmXisuwEgrxpSkdW:cadence.moe');
INSERT INTO channel_room VALUES('778183052521111592','!hsALhxajLcTddkKcUE:cadence.moe');
INSERT INTO channel_room VALUES('360564656265232395','!EZmeznyjKwAcBHbUfX:cadence.moe');
INSERT INTO channel_room VALUES('802612899990339645','!NVsoZfMPBtLCzlUQAb:cadence.moe');
INSERT INTO channel_room VALUES('360564868224647168','!YnNokCprKPHliWjKTy:cadence.moe');
INSERT INTO channel_room VALUES('920171008047079425','!IgtetQZJffJcCQjMqG:cadence.moe');
INSERT INTO channel_room VALUES('494913643448631296','!WZdAlxVcydGBNdTuoL:cadence.moe');
INSERT INTO channel_room VALUES('360565596133523459','!OPkSbsYXFqZkRVCIZM:cadence.moe');
INSERT INTO channel_room VALUES('360567400254537729','!BoXSlmwqtovnOCybXt:cadence.moe');
INSERT INTO channel_room VALUES('1036840786093953084','!SMEmWBWGgRXeVyiwHN:cadence.moe');
INSERT INTO channel_room VALUES('360565147854438412','!vwVOQfBJDkaHdiVLUF:cadence.moe');
INSERT INTO channel_room VALUES('802420775860568074','!QsljgtSqHOtGwMYuIc:cadence.moe');
CREATE TABLE IF NOT EXISTS "file" (
"discord_url" TEXT NOT NULL UNIQUE,
"mxc_url" TEXT NOT NULL UNIQUE,
PRIMARY KEY("discord_url")
);
INSERT INTO file VALUES('https://cdn.discordapp.com/icons/112760669178241024/a_f83622e09ead74f0c5c527fe241f8f8c?size=1024','mxc://cadence.moe/sZtPwbfOIsvfSoWCWPrGnzql');
INSERT INTO file VALUES('https://cdn.discordapp.com/icons/112760669178241024/a_f83622e09ead74f0c5c527fe241f8f8c.png?size=1024','mxc://cadence.moe/zKXGZhmImMHuGQZWJEFKJbsF');
CREATE TABLE IF NOT EXISTS "sim_member" (
"mxid" TEXT NOT NULL,
"room_id" TEXT NOT NULL,
PRIMARY KEY("mxid","room_id")
);
INSERT INTO sim_member VALUES('@_ooye_huck:cadence.moe','!VwVlIAjOjejUpDhlbA:cadence.moe');
INSERT INTO sim_member VALUES('@_ooye_bojack_horseman:cadence.moe','!VwVlIAjOjejUpDhlbA:cadence.moe');
INSERT INTO sim_member VALUES('@_ooye_botrac4r:cadence.moe','!VwVlIAjOjejUpDhlbA:cadence.moe');
INSERT INTO sim_member VALUES('@_ooye_crunch_god:cadence.moe','!VwVlIAjOjejUpDhlbA:cadence.moe');
CREATE TABLE IF NOT EXISTS "sim" (
"discord_id" TEXT NOT NULL UNIQUE,
"sim_name" TEXT NOT NULL UNIQUE,
"localpart" TEXT NOT NULL UNIQUE,
"mxid" TEXT NOT NULL UNIQUE,
PRIMARY KEY("discord_id")
);
INSERT INTO sim VALUES('0','bot','_ooye_bot','@_ooye_bot:cadence.moe');
INSERT INTO sim VALUES('113340068197859328','cookie','_ooye_cookie','@_ooye_cookie:cadence.moe');
INSERT INTO sim VALUES('820865262526005258','crunch_god','_ooye_crunch_god','@_ooye_crunch_god:cadence.moe');
INSERT INTO sim VALUES('142843483923677184','huck','_ooye_huck','@_ooye_huck:cadence.moe');
INSERT INTO sim VALUES('771520384671416320','bojack_horseman','_ooye_bojack_horseman','@_ooye_bojack_horseman:cadence.moe');
INSERT INTO sim VALUES('353703396483661824','botrac4r','_ooye_botrac4r','@_ooye_botrac4r:cadence.moe');
COMMIT;

View file

@ -134,7 +134,7 @@ async function sendEvent(roomID, type, content, mxid, timestamp) {
*/
async function redactEvent(roomID, eventID, mxid) {
/** @type {Ty.R.EventRedacted} */
const root = await mreq.mreq("PUT", path(`/client/v3/rooms/${roomID}/redact/${eventID}/${makeTxnId.makeTxnId()}`, mxid))
const root = await mreq.mreq("PUT", path(`/client/v3/rooms/${roomID}/redact/${eventID}/${makeTxnId.makeTxnId()}`, mxid), {})
return root.event_id
}

View file

@ -40,15 +40,8 @@ async function uploadDiscordFileToMxc(path) {
// Download from Discord
const promise = fetch(url, {}).then(/** @param {import("node-fetch").Response} res */ async res => {
const body = res.body
// Upload to Matrix
/** @type {import("../types").R.FileUploaded} */
const root = await mreq.mreq("POST", "/media/v3/upload", body, {
headers: {
"Content-Type": res.headers.get("content-type")
}
})
const root = await module.exports._actuallyUploadDiscordFileToMxc(url, res)
// Store relationship in database
db.prepare("INSERT INTO file (discord_url, mxc_url) VALUES (?, ?)").run(url, root.content_uri)
@ -61,6 +54,17 @@ async function uploadDiscordFileToMxc(path) {
return promise
}
async function _actuallyUploadDiscordFileToMxc(url, res) {
const body = res.body
/** @type {import("../types").R.FileUploaded} */
const root = await mreq.mreq("POST", "/media/v3/upload", body, {
headers: {
"Content-Type": res.headers.get("content-type")
}
})
return root
}
function guildIcon(guild) {
return `/icons/${guild.id}/${guild.icon}.png?size=${IMAGE_SIZE}`
}
@ -102,3 +106,4 @@ module.exports.emoji = emoji
module.exports.stickerFormat = stickerFormat
module.exports.sticker = sticker
module.exports.uploadDiscordFileToMxc = uploadDiscordFileToMxc
module.exports._actuallyUploadDiscordFileToMxc = _actuallyUploadDiscordFileToMxc

Binary file not shown.

View file

@ -1,16 +1,22 @@
// @ts-check
const fs = require("fs")
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 db = new sqlite(":memory:")
db.exec(fs.readFileSync("db/data-for-test.sql", "utf8"))
const sync = new HeatSync({watchFS: false})
Object.assign(passthrough, { config, sync, db })
const file = sync.require("../matrix/file")
file._actuallyUploadDiscordFileToMxc = function(url, res) { throw new Error(`Not allowed to upload files during testing.\nURL: ${url}`) }
require("../matrix/kstate.test")
require("../matrix/api.test")
require("../matrix/read-registration.test")