From fd02432559caa35fb1b9c3f07b1a1a3f516a817e Mon Sep 17 00:00:00 2001 From: Inex Code Date: Sat, 13 Feb 2021 11:19:00 +0000 Subject: [PATCH] Handle creation of chats with groups, closes #7 --- src/vk.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/vk.ts b/src/vk.ts index 2bce98b..a56f79d 100755 --- a/src/vk.ts +++ b/src/vk.ts @@ -100,6 +100,7 @@ export class VkPuppet { name: `${userInfo[0].first_name} ${userInfo[0].last_name}`, avatarUrl: userInfo[0].photo_max, isDirect: true, + externalUrl: `https://vk.com/id${info.items[0].peer.id}}`, }; break; @@ -113,6 +114,17 @@ export class VkPuppet { }; break; + case "group": + const groupInfo = await p.client.api.groups.getById({ group_id: info.items[0].peer.id }); + response = { + puppetId, + roomId: peerId.toString(), + name: groupInfo[0].name || peerId.toString(), + avatarUrl: groupInfo[0]?.photo_200, + externalUrl: `https://vk.com/${groupInfo[0].screen_name}`, + }; + break; + default: response = { puppetId, @@ -285,7 +297,7 @@ export class VkPuppet { delete_for_all: 1, message_ids: Number(eventId), }) - : await this.handleMatrixEdit(room, eventId, { body: "[ДАННЫЕ УДАЛЕНЫ]", eventId }, asUser); + : await this.handleMatrixEdit(room, eventId, { body: "[ДАННЫЕ УДАЛЕНЫ]", eventId }, asUser); } catch (err) { log.error("Error sending edit to vk", err.error || err.body || err); } @@ -521,7 +533,7 @@ export class VkPuppet { } if (context.hasAttachments()) { const attachments = p.data.isUserToken - ? (await p.client.api.messages.getById({message_ids: context.id})).items[0].attachments! + ? (await p.client.api.messages.getById({ message_ids: context.id })).items[0].attachments! : context.attachments; for (const f of attachments) { switch (f.type) { @@ -563,7 +575,7 @@ export class VkPuppet { case AttachmentType.STICKER: try { p.data.isUserToken ? await this.puppet.sendFileDetect(params, f["sticker"]["images_with_background"][4]["url"]) - : await this.puppet.sendFileDetect(params, f["imagesWithBackground"][4]["url"]); + : await this.puppet.sendFileDetect(params, f["imagesWithBackground"][4]["url"]); } catch (err) { const opts: IMessageEvent = { body: `Sticker was sent: ${f["imagesWithBackground"][4]["url"]}`, @@ -594,7 +606,7 @@ export class VkPuppet { case AttachmentType.DOCUMENT: try { p.data.isUserToken ? await this.puppet.sendFileDetect(params, f["doc"]["url"], f["doc"]["title"]) - : await this.puppet.sendFileDetect(params, f["url"], f["title"]); + : await this.puppet.sendFileDetect(params, f["url"], f["title"]); } catch (err) { const opts: IMessageEvent = { body: `Document was sent: ${f["url"]}`,