This commit is contained in:
Inex Code 2020-11-13 03:14:53 +00:00
parent 9b826748ea
commit 757badde67
3 changed files with 24 additions and 22 deletions

View file

@ -94,9 +94,9 @@ async function run() {
puppet.on("image", vk.handleMatrixImage.bind(vk)); puppet.on("image", vk.handleMatrixImage.bind(vk));
puppet.on("file", vk.handleMatrixFile.bind(vk)); puppet.on("file", vk.handleMatrixFile.bind(vk));
puppet.setCreateRoomHook(vk.createRoom.bind(vk)); puppet.setCreateRoomHook(vk.createRoom.bind(vk));
// required: get description hook // required: get description hook
// tslint:disable-next-line: no-any
puppet.setGetDescHook(async (puppetId: number, data: any): Promise<string> => { puppet.setGetDescHook(async (puppetId: number, data: any): Promise<string> => {
// here we receive the puppet ID and the data associated with that puppet // here we receive the puppet ID and the data associated with that puppet
// we are expected to return a displayable name for that particular puppet // we are expected to return a displayable name for that particular puppet

View file

@ -24,6 +24,7 @@ interface IEchoPuppet {
// this is usually a client class that connects to the remote protocol // this is usually a client class that connects to the remote protocol
// as we just echo back, unneeded in our case // as we just echo back, unneeded in our case
client: VK; client: VK;
// tslint:disable-next-line: no-any
data: any; // and let's keep a copy of the data associated with a puppet data: any; // and let's keep a copy of the data associated with a puppet
} }
@ -82,6 +83,7 @@ export class VkPuppet {
let response: IRemoteRoom; let response: IRemoteRoom;
switch (info.items[0].peer.type) { switch (info.items[0].peer.type) {
case "user": case "user":
// tslint:disable-next-line: no-shadowed-variable
const userInfo = await p.client.api.users.get({ user_ids: info.items[0].peer.id, fields: ["photo_max"] }); const userInfo = await p.client.api.users.get({ user_ids: info.items[0].peer.id, fields: ["photo_max"] });
response = { response = {
puppetId, puppetId,
@ -113,6 +115,7 @@ export class VkPuppet {
return response; return response;
} }
// tslint:disable-next-line: no-any
public async newPuppet(puppetId: number, data: any) { public async newPuppet(puppetId: number, data: any) {
// this is called when we need to create a new puppet // this is called when we need to create a new puppet
// the puppetId is the ID associated with that puppet and the data its data // the puppetId is the ID associated with that puppet and the data its data
@ -173,6 +176,7 @@ export class VkPuppet {
// Matrix -> VK section // // Matrix -> VK section //
////////////////////////// //////////////////////////
// tslint:disable-next-line: no-any
public async handleMatrixMessage(room: IRemoteRoom, data: IMessageEvent, event: any) { public async handleMatrixMessage(room: IRemoteRoom, data: IMessageEvent, event: any) {
// this is called every time we receive a message from matrix and need to // this is called every time we receive a message from matrix and need to
// forward it to the remote protocol. // forward it to the remote protocol.
@ -235,6 +239,7 @@ export class VkPuppet {
room: IRemoteRoom, room: IRemoteRoom,
eventId: string, eventId: string,
data: IMessageEvent, data: IMessageEvent,
// tslint:disable-next-line: no-any
event: any, event: any,
) { ) {
const p = this.puppets[room.puppetId]; const p = this.puppets[room.puppetId];
@ -259,6 +264,7 @@ export class VkPuppet {
room: IRemoteRoom, room: IRemoteRoom,
data: IFileEvent, data: IFileEvent,
asUser: ISendingUser | null, asUser: ISendingUser | null,
// tslint:disable-next-line: no-any
event: any, event: any,
) { ) {
const p = this.puppets[room.puppetId]; const p = this.puppets[room.puppetId];
@ -305,6 +311,7 @@ export class VkPuppet {
room: IRemoteRoom, room: IRemoteRoom,
data: IFileEvent, data: IFileEvent,
asUser: ISendingUser | null, asUser: ISendingUser | null,
// tslint:disable-next-line: no-any
event: any, event: any,
) { ) {
const p = this.puppets[room.puppetId]; const p = this.puppets[room.puppetId];
@ -357,7 +364,6 @@ export class VkPuppet {
} }
} }
public async createRoom(room: IRemoteRoom): Promise<IRemoteRoom | null> { public async createRoom(room: IRemoteRoom): Promise<IRemoteRoom | null> {
const p = this.puppets[room.puppetId]; const p = this.puppets[room.puppetId];
if (!p) { if (!p) {
@ -460,22 +466,17 @@ export class VkPuppet {
} }
} }
public async handleVkEdit(puppetId: number, context: MessageContext) { public async handleVkEdit(puppetId: number, context: MessageContext) {
log.error("OwO", context);
const p = this.puppets[puppetId]; const p = this.puppets[puppetId];
if (!p) { if (!p) {
return; return;
} }
// As VK always sends edit as outbox, we won't work with any edits from groups // As VK always sends edit as outbox, we won't work with any edits from groups
if (context.senderType == "group") { if (context.senderType === "group") {
log.error("oh no no");
return; // Deduping return; // Deduping
} }
const params = await this.getSendParams(puppetId, context.peerId, context.senderId, context.id.toString()); const params = await this.getSendParams(puppetId, context.peerId, context.senderId, context.id.toString());
log.error("UWU", context.hasText);
if (context.hasText) { if (context.hasText) {
const opts: IMessageEvent = { const opts: IMessageEvent = {
body: context.text || "Attachment", body: context.text || "Attachment",
@ -500,6 +501,7 @@ export class VkPuppet {
} }
public async stripReply(body: string) { public async stripReply(body: string) {
// tslint:disable-next-line: prefer-const
let splitted = body.split("\n"); let splitted = body.split("\n");
let isCitate = true; let isCitate = true;
while (isCitate) { while (isCitate) {
@ -509,6 +511,6 @@ export class VkPuppet {
isCitate = false; isCitate = false;
} }
} }
return(splitted.join('\n').trim()); return (splitted.join("\n").trim());
} }
} }

View file

@ -11,7 +11,7 @@
"severity": "warning" "severity": "warning"
}, },
"arrow-return-shorthand": true, "arrow-return-shorthand": true,
"no-magic-numbers": [true, -1, 0, 1, 1000], "no-magic-numbers": [true, -1, 0, 1, 1000, 2000000000, 4],
"prefer-for-of": true, "prefer-for-of": true,
"typedef": { "typedef": {
"severity": "warning" "severity": "warning"