Linting, version bump

This commit is contained in:
Inex Code 2020-11-20 15:43:32 +00:00
parent 80913c1826
commit acf7bdbf80
2 changed files with 17 additions and 20 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "mx-puppet-vk", "name": "mx-puppet-vk",
"version": "0.0.0", "version": "0.1.0",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

View file

@ -62,7 +62,7 @@ export class VkPuppet {
public async getRemoteUser(puppetId: number, userId: number): Promise<IRemoteUser> { public async getRemoteUser(puppetId: number, userId: number): Promise<IRemoteUser> {
const p = this.puppets[puppetId]; const p = this.puppets[puppetId];
// log.info("User id:", userId, userId.toString()); // log.debug("User id:", userId, userId.toString());
if (userId < 0) { if (userId < 0) {
const info = await p.client.api.groups.getById({ group_id: Math.abs(userId).toString() }); const info = await p.client.api.groups.getById({ group_id: Math.abs(userId).toString() });
const response: IRemoteUser = { const response: IRemoteUser = {
@ -75,7 +75,6 @@ export class VkPuppet {
return response; return response;
} else { } else {
const info = await p.client.api.users.get({ user_ids: userId.toString(), fields: ["photo_max", "screen_name"] }); const info = await p.client.api.users.get({ user_ids: userId.toString(), fields: ["photo_max", "screen_name"] });
log.info(info[0]);
const response: IRemoteUser = { const response: IRemoteUser = {
puppetId, puppetId,
userId: userId.toString(), userId: userId.toString(),
@ -90,7 +89,6 @@ export class VkPuppet {
public async getRemoteRoom(puppetId: number, peerId: number): Promise<IRemoteRoom> { public async getRemoteRoom(puppetId: number, peerId: number): Promise<IRemoteRoom> {
const p = this.puppets[puppetId]; const p = this.puppets[puppetId];
const info = await p.client.api.messages.getConversationsById({ peer_ids: peerId, fields: ["photo_max"] }); const info = await p.client.api.messages.getConversationsById({ peer_ids: peerId, fields: ["photo_max"] });
// log.info(info.items[0]);
let response: IRemoteRoom; let response: IRemoteRoom;
switch (info.items[0]?.peer.type || "chat") { switch (info.items[0]?.peer.type || "chat") {
case "user": case "user":
@ -254,7 +252,7 @@ export class VkPuppet {
const displayname = (new TextEncoder().encode(asUser.displayname)); const displayname = (new TextEncoder().encode(asUser.displayname));
asUser.displayname = (new TextDecoder().decode(displayname.slice(0, MAX_NAME_LENGTH))); asUser.displayname = (new TextDecoder().decode(displayname.slice(0, MAX_NAME_LENGTH)));
} }
// usually you'd send it here to the remote protocol via the client object
try { try {
await this.handleMatrixEdit(room, eventId, { body: "[ДАННЫЕ УДАЛЕНЫ]", eventId }, asUser); await this.handleMatrixEdit(room, eventId, { body: "[ДАННЫЕ УДАЛЕНЫ]", eventId }, asUser);
// broken in chats without admin access // broken in chats without admin access
@ -412,16 +410,15 @@ export class VkPuppet {
} }
} }
// Never called on my server for some reason, but
// if being called, should work
public async handleMatrixTyping( public async handleMatrixTyping(
room: IRemoteRoom, room: IRemoteRoom,
typing: boolean, typing: boolean,
asUser: ISendingUser | null, asUser: ISendingUser | null,
event: any, event: any,
) { ) {
log.info("Got typing", typing);
if (typing) { if (typing) {
log.info("Got typing");
const p = this.puppets[room.puppetId]; const p = this.puppets[room.puppetId];
if (!p) { if (!p) {
return null; return null;
@ -430,9 +427,9 @@ export class VkPuppet {
const response = await p.client.api.messages.setActivity({ const response = await p.client.api.messages.setActivity({
peer_id: Number(room.roomId), peer_id: Number(room.roomId),
type: "typing", type: "typing",
}) });
} catch (err) { } catch (err) {
log.error("Error sending typing presence to vk", err.error || err.body || err) log.error("Error sending typing presence to vk", err.error || err.body || err);
} }
} }
} }
@ -456,7 +453,7 @@ export class VkPuppet {
if (!p) { if (!p) {
return; return;
} }
log.info("Received new message!", context); log.debug("Received new message!", context);
if (context.isOutbox) { if (context.isOutbox) {
return; // Deduping return; // Deduping
} }
@ -598,34 +595,34 @@ export class VkPuppet {
let formatted = `${body}\n`; let formatted = `${body}\n`;
for (const f of forwards) { for (const f of forwards) {
const user = await this.getRemoteUser(puppetId, Number(f.senderId)); const user = await this.getRemoteUser(puppetId, Number(f.senderId));
formatted += `> <[${user.name}](${user.externalUrl})>\n` formatted += `> <[${user.name}](${user.externalUrl})>\n`;
f.text?.split("\n").forEach((element) => { f.text?.split("\n").forEach((element) => {
formatted += `> ${element}\n`; formatted += `> ${element}\n`;
}) });
if (f.hasAttachments()) { if (f.hasAttachments()) {
f.attachments.forEach((attachment) => { f.attachments.forEach((attachment) => {
switch (attachment.type) { switch (attachment.type) {
case AttachmentType.PHOTO: case AttachmentType.PHOTO:
formatted += `> 🖼️ [Photo](${attachment["largeSizeUrl"]})\n` formatted += `> 🖼️ [Photo](${attachment["largeSizeUrl"]})\n`;
break; break;
case AttachmentType.STICKER: case AttachmentType.STICKER:
formatted += `> 🖼️ [Sticker](${attachment["imagesWithBackground"][4]["url"]})\n` formatted += `> 🖼️ [Sticker](${attachment["imagesWithBackground"][4]["url"]})\n`;
break; break;
case AttachmentType.AUDIO_MESSAGE: case AttachmentType.AUDIO_MESSAGE:
formatted += `> 🗣️ [Audio message](${attachment["oggUrl"]})\n` formatted += `> 🗣️ [Audio message](${attachment["oggUrl"]})\n`;
break; break;
case AttachmentType.DOCUMENT: case AttachmentType.DOCUMENT:
formatted += `> 📁 [File ${attachment["title"]}](${attachment["url"]})\n` formatted += `> 📁 [File ${attachment["title"]}](${attachment["url"]})\n`;
break; break;
default: default:
break; break;
} }
}) });
} }
if (f.hasForwards) { if (f.hasForwards) {
(await this.appendForwards(puppetId, "", f.forwards)).trim().split("\n").forEach((element) => { (await this.appendForwards(puppetId, "", f.forwards)).trim().split("\n").forEach((element) => {
formatted += `> ${element}\n`; formatted += `> ${element}\n`;
}) });
} }
formatted += "\n"; formatted += "\n";
} }