mirror of
https://github.com/muerwre/vk-tg-bot.git
synced 2025-04-24 22:46:41 +07:00
made event safe json stringify
This commit is contained in:
parent
225b80ecae
commit
1969b2666a
2 changed files with 22 additions and 13 deletions
|
@ -115,11 +115,7 @@ export class PostNewHandler extends VkEventHandler<Fields, Values> {
|
||||||
this.channel.markdown
|
this.channel.markdown
|
||||||
);
|
);
|
||||||
|
|
||||||
const event = await this.createEvent(
|
const event = await this.createEvent(id, msg.message_id, context);
|
||||||
id,
|
|
||||||
msg.message_id,
|
|
||||||
context.wall.toJSON()
|
|
||||||
);
|
|
||||||
|
|
||||||
await this.db.createPost(
|
await this.db.createPost(
|
||||||
event!.id,
|
event!.id,
|
||||||
|
|
|
@ -102,13 +102,26 @@ export class VkEventHandler<
|
||||||
tgMessageId: number,
|
tgMessageId: number,
|
||||||
text: Record<any, any>
|
text: Record<any, any>
|
||||||
) => {
|
) => {
|
||||||
return await this.db.createEvent(
|
let plain = "";
|
||||||
this.type,
|
|
||||||
id,
|
try {
|
||||||
this.group.id,
|
plain = JSON.stringify(text);
|
||||||
this.channel.id,
|
} catch (e) {
|
||||||
tgMessageId,
|
logger.warn(`createEvent: failed to stringify JSON: ${e}`, e);
|
||||||
text
|
plain = text.toString();
|
||||||
);
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await this.db.createEvent(
|
||||||
|
this.type,
|
||||||
|
id,
|
||||||
|
this.group.id,
|
||||||
|
this.channel.id,
|
||||||
|
tgMessageId,
|
||||||
|
{ event: plain }
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
logger.warn("createEvent error", e);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue