diff --git a/src/bot.ts b/src/bot.ts index 65e60a161e7480913b25f3c8039cc096dfdca3cb..4969b885fca68c194884d630c0b67d0d2346f9dc 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -927,7 +927,7 @@ export class DiscordBot { // Update presence because sometimes discord misses people. await this.userSync.OnUpdateUser(msg.author, Boolean(msg.webhookID)); - let rooms; + let rooms: string[]; try { rooms = await this.channelSync.GetRoomIdsFromChannel(msg.channel); if (rooms === null) { @@ -947,12 +947,12 @@ export class DiscordBot { // an edit await Util.AsyncForEach(msg.attachments.array(), async (attachment) => { const content = await Util.DownloadFile(attachment.url); - const fileMime = content.mimeType || mime.getType(attachment.filename) + const fileMime = content.mimeType || mime.getType(attachment.name || "") || "application/octet-stream"; const mxcUrl = await intent.underlyingClient.uploadContent( content.buffer, fileMime, - attachment.filename, + attachment.name || "", ); const type = fileMime.split("/")[0]; let msgtype = { @@ -965,15 +965,15 @@ export class DiscordBot { } const info = { mimetype: fileMime, - size: attachment.filesize, + size: attachment.size, } as IMatrixMediaInfo; if (msgtype === "m.image" || msgtype === "m.video") { - info.w = attachment.width; - info.h = attachment.height; + info.w = attachment.width!; + info.h = attachment.height!; } await Util.AsyncForEach(rooms, async (room) => { const eventId = await intent.sendEvent(room, { - body: attachment.filename, + body: attachment.name || "file", external_url: attachment.url, info, msgtype, diff --git a/src/usersyncroniser.ts b/src/usersyncroniser.ts index bd796ab5c4a7e8668f925ca58e5376c2e609ca5a..6400ecb7cb866a7a6e6a5c7af00385cba58472cf 100644 --- a/src/usersyncroniser.ts +++ b/src/usersyncroniser.ts @@ -400,9 +400,9 @@ export class UserSyncroniser { log.info(`Got update for ${id}.`); await Util.AsyncForEach(this.discord.GetGuilds(), async (guild) => { - if (guild.members.has(id)) { + if (guild.members.cache.has(id)) { log.info(`Updating user ${id} in guild ${guild.id}.`); - const member = guild.members.get(id); + const member = guild.members.resolve(id); try { const state = await this.GetUserStateForGuildMember(member!); const rooms = await this.discord.GetRoomIdsFromGuild(guild, member!); diff --git a/src/util.ts b/src/util.ts index 0ea0690f98bef61fd59c3ffddbc92ec287c923fc..2bbf4122b415ccf4bc32a308e62ea8914fd7df2d 100644 --- a/src/util.ts +++ b/src/util.ts @@ -296,7 +296,7 @@ export class Util { return {command, args}; } - public static async AsyncForEach(arr, callback) { + public static async AsyncForEach<T>(arr: T[], callback: (item: T, i: number, a: T[]) => Promise<void>) { for (let i = 0; i < arr.length; i++) { await callback(arr[i], i, arr); } diff --git a/test/test_discordbot.ts b/test/test_discordbot.ts index d04f5f29c77b4663bac08500abe0bd78b062cec5..17f6375a564f292221c3950e678fadb5c510bf8b 100644 --- a/test/test_discordbot.ts +++ b/test/test_discordbot.ts @@ -184,8 +184,8 @@ describe("DiscordBot", () => { discordBot = getDiscordBot(); msg.author = author; msg.attachments.set("1234", { - filename: "someimage.png", - filesize: 42, + name: "someimage.png", + size: 42, height: 0, url: "asdf", width: 0, @@ -210,8 +210,8 @@ describe("DiscordBot", () => { discordBot = getDiscordBot(); msg.author = author; msg.attachments.set("1234", { - filename: "foxes.mov", - filesize: 42, + name: "foxes.mov", + size: 42, height: 0, url: "asdf", width: 0, @@ -236,8 +236,8 @@ describe("DiscordBot", () => { discordBot = getDiscordBot(); msg.author = author; msg.attachments.set("1234", { - filename: "meow.mp3", - filesize: 42, + name: "meow.mp3", + size: 42, height: 0, url: "asdf", width: 0, @@ -260,8 +260,8 @@ describe("DiscordBot", () => { discordBot = getDiscordBot(); msg.author = author; msg.attachments.set("1234", { - filename: "meow.zip", - filesize: 42, + name: "meow.zip", + size: 42, height: 0, url: "asdf", width: 0, diff --git a/tools/addRoomsToDirectory.ts b/tools/addRoomsToDirectory.ts index 11c8a62b15e7b975eced6d57a5a1d907d7dc5473..520a24774ddccb814c9c8451923e365cb6ca1828 100644 --- a/tools/addRoomsToDirectory.ts +++ b/tools/addRoomsToDirectory.ts @@ -82,8 +82,8 @@ async function run() { log.info(`Got ${rooms.length} rooms to set`); try { await Util.AsyncForEach(rooms, async (room) => { - const guild = room.remote.get("discord_guild"); - const roomId = room.matrix.getId(); + const guild = room.remote!.get("discord_guild"); + const roomId = room.matrix!.getId(); try { await appservice.botIntent.underlyingClient.setDirectoryVisibility( roomId,