diff --git a/src/bot.ts b/src/bot.ts index 6886e59989b5842714b90161e0f02e84c51ba043..c8d5176f2a528f58d7b63adcecc98e9ea9a506eb 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -96,11 +96,11 @@ export class DiscordBot { ); this.presenceHandler = new PresenceHandler(this); this.roomHandler = new MatrixRoomHandler(this, config, this.provisioner, bridge, store.roomStore); + this.channelSync = new ChannelSyncroniser(bridge, config, this, store.roomStore); + this.provisioner = new Provisioner(store.roomStore, this.channelSync); this.mxEventProcessor = new MatrixEventProcessor( new MatrixEventProcessorOpts(config, bridge, this), ); - this.channelSync = new ChannelSyncroniser(bridge, config, this, store.roomStore); - this.provisioner = new Provisioner(store.roomStore, this.channelSync); this.discordCommandHandler = new DiscordCommandHandler(bridge, this); // init vars this.sentMessages = []; diff --git a/src/db/roomstore.ts b/src/db/roomstore.ts index 1ca4ae0862ab64cdae3d123c1c3124a4adda698d..bdb5b373f6a6b6e4ba741d088f1f3a80b051cbe1 100644 --- a/src/db/roomstore.ts +++ b/src/db/roomstore.ts @@ -18,6 +18,7 @@ import { IDatabaseConnector } from "./connector"; import { Util } from "../util"; import * as uuid from "uuid/v4"; +import { Postgres } from "./postgres"; const log = new Log("DbRoomStore"); @@ -47,8 +48,8 @@ interface IRemoteRoomDataLazy { } export class RemoteStoreRoom { - public data: IRemoteRoomData; - constructor(public readonly roomId: string, data: IRemoteRoomData) { + public data: IRemoteRoomDataLazy; + constructor(public readonly roomId: string, data: IRemoteRoomDataLazy) { for (const k of ["discord_guild", "discord_channel", "discord_name", "discord_topic", "discord_iconurl", "discord_iconurl_mxc", "discord_type"]) { data[k] = typeof(data[k]) === "number" ? String(data[k]) : data[k] || null; @@ -92,7 +93,6 @@ const ENTRY_CACHE_LIMETIME = 30000; export class DbRoomStore { private entriesMatrixIdCache: Map<string, {e: IRoomStoreEntry[], ts: number}>; - constructor(private db: IDatabaseConnector) { this.entriesMatrixIdCache = new Map(); } @@ -244,6 +244,12 @@ export class DbRoomStore { } public async getEntriesByRemoteRoomData(data: IRemoteRoomDataLazy): Promise<IRoomStoreEntry[]> { + for (const k of ["update_name", "update_topic", "update_icon", "plumbed"]) { + if (data[k]) { + data[k] = Number(data[k] || 0); + } + } + const whereClaues = Object.keys(data).map((key) => { return `${key} = $${key}`; }).join(" AND "); diff --git a/src/discordcommandhandler.ts b/src/discordcommandhandler.ts index 04401b423968f1d0c5ee49f5b5c965af48c33fb0..c27bb819b081893e10e9ef4bd8679cad30a76945 100644 --- a/src/discordcommandhandler.ts +++ b/src/discordcommandhandler.ts @@ -151,7 +151,7 @@ export class DiscordCommandHandler { return "This channel has been unbridged"; } catch (err) { if (err.message === "Channel is not bridged") { - return "This channel is not bridged to a plubmed matrix room"; + return "This channel is not bridged to a plumbed matrix room"; } log.error("Error while unbridging room " + channel.id); log.error(err); diff --git a/src/matrixcommandhandler.ts b/src/matrixcommandhandler.ts index d289b7a74be8338bd04d23d602b98c230e8d4b7e..792dc2633b49d5a0c5e0dfd530d0fbd149906391 100644 --- a/src/matrixcommandhandler.ts +++ b/src/matrixcommandhandler.ts @@ -46,11 +46,8 @@ export class MatrixCommandHandler { public async HandleInvite(event: IMatrixEvent) { log.info(`Received invite for ${event.state_key} in room ${event.room_id}`); - if (event.state_key === this.discord.GetBotId()) { - log.info("Accepting invite for bridge bot"); - await this.bridge.getIntent().joinRoom(event.room_id); - this.botJoinedRooms.add(event.room_id); - } + await this.bridge.getIntent().join(event.room_id); + this.botJoinedRooms.add(event.room_id); } public async Process(event: IMatrixEvent, context: BridgeContext) { @@ -130,8 +127,8 @@ export class MatrixCommandHandler { return "This room cannot be unbridged."; } const res = await this.discord.LookupRoom( - remoteRoom.data.discord_guild, - remoteRoom.data.discord_channel, + remoteRoom.data.discord_guild!, + remoteRoom.data.discord_channel!, ); try { await this.provisioner.UnbridgeChannel(res.channel, event.room_id); diff --git a/src/matrixeventprocessor.ts b/src/matrixeventprocessor.ts index 7c7f6a516ccfd7114329f177280c2429eefb76ce..3e39518ed5680ab4b38ac8355d2b90b28882b999 100644 --- a/src/matrixeventprocessor.ts +++ b/src/matrixeventprocessor.ts @@ -81,7 +81,7 @@ export class MatrixEventProcessor { if ( event.type === "m.room.member" && event.content!.membership === "invite" && - event.state_key === this.discord.GetBotId() + event.state_key === this.bridge.getClientFactory()._botUserId ) { await this.mxCommandHandler.HandleInvite(event); return; diff --git a/src/util.ts b/src/util.ts index 68fe972037a2f9a643348935febc2c230ea15abc..3cbf8b381baa00506a8e09d64cd00427c2f9d850 100644 --- a/src/util.ts +++ b/src/util.ts @@ -299,7 +299,6 @@ export class Util { permissionCheck?: CommandPermissonCheck, ): Promise<string> { const {command, args} = Util.MsgToArgs(msg, prefix); - if (command === "help") { return await Util.HandleHelpCommand(prefix, actions, parameters, args, permissionCheck); }