Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mx-puppet-bridge

Package Overview
Dependencies
Maintainers
1
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mx-puppet-bridge - npm Package Compare versions

Comparing version 0.0.12 to 0.0.13

61

lib/botprovisioner.js

@@ -13,3 +13,2 @@ "use strict";

const timedcache_1 = require("./structures/timedcache");
const escapeHtml = require("escape-html");
const MarkdownIt = require("markdown-it");

@@ -136,9 +135,6 @@ const md = new MarkdownIt();

let sendStr = "Links:\n";
let html = "<p>Links:</p><ul>";
for (const d of descs) {
sendStr += `${d.puppetId}: ${d.desc}\n`;
html += `<li>${d.puppetId}: ${d.html}</li>`;
sendStr += ` - ${d.puppetId}: ${d.desc}\n`;
}
html += "</ul>";
yield this.sendMessage(roomId, sendStr, html);
yield this.sendMessage(roomId, sendStr);
break;

@@ -174,15 +170,10 @@ }

let reply = "";
let replyHtml = "";
for (const d of descs) {
const users = yield this.bridge.hooks.listUsers(d.puppetId);
reply += `${d.puppetId}: ${d.desc}:\n\n`;
replyHtml += `<h2>${d.puppetId}: ${d.html}:</h2><ul>`;
reply += `## ${d.puppetId}: ${d.desc}:\n\n`;
for (const u of users) {
const nameHtml = escapeHtml(u.name);
if (u.category) {
reply += `${u.name}:\n`;
replyHtml += `</ul><h3>${nameHtml}</h3><ul>`;
reply += `\n### ${u.name}:\n\n`;
continue;
}
reply += ` - ${u.name}\n`;
const mxid = yield this.bridge.getMxidForUser({

@@ -192,8 +183,6 @@ puppetId: d.puppetId,

}, false);
const pill = `<a href="https://matrix.to/#/${escapeHtml(mxid)}">${nameHtml}</a>`;
replyHtml += `<li>${nameHtml}: ${pill}</li>`;
reply += ` - [${u.name}](https://matrix.to/#/${mxid})\n`;
}
replyHtml += "</ul>";
}
yield this.sendMessage(roomId, reply, replyHtml);
yield this.sendMessage(roomId, reply);
break;

@@ -212,15 +201,10 @@ }

let reply = "";
let replyHtml = "";
for (const d of descs) {
const chans = yield this.bridge.hooks.listChans(d.puppetId);
reply += `${d.puppetId}: ${d.desc}:\n\n`;
replyHtml += `<h2>${d.puppetId}: ${d.html}:</h2><ul>`;
reply += `## ${d.puppetId}: ${d.desc}:\n\n`;
for (const c of chans) {
const nameHtml = escapeHtml(c.name);
if (c.category) {
reply += `${c.name}:\n`;
replyHtml += `</ul><h3>${nameHtml}</h3><ul>`;
reply += `\n### ${c.name}:\n\n`;
continue;
}
reply += ` - ${c.name}\n`;
const mxid = yield this.bridge.getMxidForChan({

@@ -230,8 +214,6 @@ puppetId: d.puppetId,

});
const pill = `<a href="https://matrix.to/#/${escapeHtml(mxid)}">${nameHtml}</a>`;
replyHtml += `<li>${nameHtml}: ${pill}</li>`;
reply += ` - [${c.name}](https://matrix.to/#/${mxid})\n`;
}
replyHtml += "</ul>";
}
yield this.sendMessage(roomId, reply, replyHtml);
yield this.sendMessage(roomId, reply);
break;

@@ -262,19 +244,14 @@ }

const sendStr = `[Status] ${puppetId}: ${desc.desc}: ${msg}`;
const sendStrHtml = `[Status] ${puppetId}: ${desc.html}: ${md.render(msg)}`;
yield this.sendMessage(info.statusRoom, sendStr, sendStrHtml);
yield this.sendMessage(info.statusRoom, sendStr);
});
}
sendMessage(roomId, message, html) {
sendMessage(roomId, message) {
return __awaiter(this, void 0, void 0, function* () {
if (!html) {
yield this.bridge.botIntent.sendText(roomId, message, "m.notice");
}
else {
yield this.bridge.botIntent.underlyingClient.sendMessage(roomId, {
msgtype: "m.notice",
body: message,
formatted_body: html,
format: "org.matrix.custom.html",
});
}
const html = md.render(message);
yield this.bridge.botIntent.underlyingClient.sendMessage(roomId, {
msgtype: "m.notice",
body: message,
formatted_body: html,
format: "org.matrix.custom.html",
});
});

@@ -281,0 +258,0 @@ }

@@ -6,3 +6,2 @@ import { PuppetBridge } from "./puppetbridge";

desc: string;
html: string;
}

@@ -9,0 +8,0 @@ export interface ITokenResponse {

@@ -170,3 +170,2 @@ "use strict";

desc: `${data.puppetMxid} (${data.puppetId})`,
html: `${data.puppetMxid} (${data.puppetId})`,
};

@@ -176,4 +175,3 @@ }

puppetId: data.puppetId,
desc: yield this.bridge.hooks.getDesc(data.puppetId, data.data, false),
html: yield this.bridge.hooks.getDesc(data.puppetId, data.data, true),
desc: yield this.bridge.hooks.getDesc(data.puppetId, data.data),
};

@@ -180,0 +178,0 @@ });

@@ -69,3 +69,3 @@ /// <reference types="node" />

export declare type CreateUserHook = (user: IRemoteUser) => Promise<IRemoteUser | null>;
export declare type GetDescHook = (puppetId: number, data: any, html: boolean) => Promise<string>;
export declare type GetDescHook = (puppetId: number, data: any) => Promise<string>;
export declare type BotHeaderMsgHook = () => string;

@@ -72,0 +72,0 @@ export declare type GetDataFromStrHook = (str: string) => Promise<IRetData>;

@@ -73,3 +73,12 @@ "use strict";

}
const mod = "bot-sdk-" + module;
let mod = "bot-sdk-" + module;
const modParts = module.match(/^(\S+)\s(.*)/);
const MOD_PART_MODULE = 1;
const MOD_PART_EXTRA = 2;
if (modParts) {
if (modParts[MOD_PART_EXTRA]) {
args.unshift(modParts[MOD_PART_EXTRA]);
}
mod = "bot-sdk-" + modParts[MOD_PART_MODULE];
}
let logger = logMap.get(mod);

@@ -80,3 +89,3 @@ if (!logger) {

}
logger[level](args);
logger[level](...args);
};

@@ -599,2 +608,3 @@ matrix_bot_sdk_1.LogService.setLogger({

if (this.appservice.isNamespacedUser(userId)) {
log.silly("Joining ghost to room...");
const intent = this.appservice.getIntentForUserId(userId);

@@ -605,6 +615,2 @@ yield intent.ensureRegisteredAndJoined(mxid);

const cacheKey = `${params.chan.puppetId}_${mxid}`;
if (created) {
// we just invited if we freshly created
this.ghostInviteCache.set(cacheKey, true);
}
try {

@@ -619,4 +625,14 @@ const cache = this.ghostInviteCache.get(cacheKey);

if ((yield inviteClient.getUserId()) !== puppetMxid) {
yield client.inviteUser(puppetMxid, mxid);
// we just invited if we created, don't try to invite again
if (!created) {
log.silly("Inviting puppet to room...");
yield client.inviteUser(puppetMxid, mxid);
}
this.ghostInviteCache.set(cacheKey, true);
// let's try to also join the room, if we use double-puppeting
const puppetClient = yield this.userSync.getPuppetClient(params.chan.puppetId);
if (puppetClient) {
log.silly("Joining the room...");
yield puppetClient.joinRoom(mxid);
}
}

@@ -897,2 +913,6 @@ }

}
const room = yield this.chanSync.getRemoteHandler(event.room_id);
if (room) {
return; // we are an existing room, meaning a double-puppeted user probably auto-invited. Do nothing
}
log.info(`Processing invite for ${userId} by ${inviteId}`);

@@ -899,0 +919,0 @@ const intent = this.appservice.getIntentForUserId(userId);

@@ -113,10 +113,10 @@ "use strict";

return __awaiter(this, void 0, void 0, function* () {
if (this.config.filename) {
if (this.config.connString) {
log.info("connString present in config, using postgres");
this.db = new postgres_1.Postgres(this.config.connString);
}
else if (this.config.filename) {
log.info("Filename present in config, using sqlite");
this.db = new sqlite3_1.SQLite3(this.config.filename);
}
else if (this.config.connString) {
log.info("connString present in config, using postgres");
this.db = new postgres_1.Postgres(this.config.connString);
}
try {

@@ -123,0 +123,0 @@ this.db.Open();

@@ -19,2 +19,3 @@ /// <reference types="node" />

maybeGetClient(data: IRemoteUser): Promise<MatrixClient | null>;
getPuppetClient(puppetId: number): Promise<MatrixClient | null>;
getClient(data: IRemoteUser): Promise<MatrixClient>;

@@ -21,0 +22,0 @@ getPartsFromMxid(mxid: string): IRemoteUser | null;

@@ -61,2 +61,9 @@ "use strict";

}
getPuppetClient(puppetId) {
return __awaiter(this, void 0, void 0, function* () {
const token = yield this.bridge.provisioner.getToken(puppetId);
const puppetClient = yield this.getClientFromTokenCallback(token);
return puppetClient ? puppetClient : null;
});
}
getClient(data) {

@@ -68,4 +75,3 @@ return __awaiter(this, void 0, void 0, function* () {

if (puppetData && puppetData.userId === data.userId) {
const token = yield this.bridge.provisioner.getToken(data.puppetId);
const puppetClient = yield this.getClientFromTokenCallback(token);
const puppetClient = yield this.getPuppetClient(data.puppetId);
if (puppetClient) {

@@ -72,0 +78,0 @@ return puppetClient;

{
"name": "mx-puppet-bridge",
"version": "0.0.12",
"version": "0.0.13",
"description": "Matrix Puppeting Bridge library",

@@ -22,3 +22,2 @@ "repository": {

"better-sqlite3": "^5.4.0",
"escape-html": "^1.0.3",
"events": "^3.0.0",

@@ -25,0 +24,0 @@ "file-type": "^12.0.0",

@@ -5,3 +5,2 @@ import { PuppetBridge, RetDataFn, IRetData } from "./puppetbridge";

import { TimedCache } from "./structures/timedcache";
import * as escapeHtml from "escape-html";
import * as MarkdownIt from "markdown-it";

@@ -137,9 +136,6 @@

let sendStr = "Links:\n";
let html = "<p>Links:</p><ul>";
for (const d of descs) {
sendStr += `${d.puppetId}: ${d.desc}\n`;
html += `<li>${d.puppetId}: ${d.html}</li>`;
sendStr += ` - ${d.puppetId}: ${d.desc}\n`;
}
html += "</ul>";
await this.sendMessage(roomId, sendStr, html);
await this.sendMessage(roomId, sendStr);
break;

@@ -175,15 +171,10 @@ }

let reply = "";
let replyHtml = "";
for (const d of descs) {
const users = await this.bridge.hooks.listUsers(d.puppetId);
reply += `${d.puppetId}: ${d.desc}:\n\n`;
replyHtml += `<h2>${d.puppetId}: ${d.html}:</h2><ul>`;
reply += `## ${d.puppetId}: ${d.desc}:\n\n`;
for (const u of users) {
const nameHtml = escapeHtml(u.name);
if (u.category) {
reply += `${u.name}:\n`;
replyHtml += `</ul><h3>${nameHtml}</h3><ul>`;
reply += `\n### ${u.name}:\n\n`;
continue;
}
reply += ` - ${u.name}\n`;
const mxid = await this.bridge.getMxidForUser({

@@ -193,8 +184,6 @@ puppetId: d.puppetId,

}, false);
const pill = `<a href="https://matrix.to/#/${escapeHtml(mxid)}">${nameHtml}</a>`;
replyHtml += `<li>${nameHtml}: ${pill}</li>`;
reply += ` - [${u.name}](https://matrix.to/#/${mxid})\n`;
}
replyHtml += "</ul>";
}
await this.sendMessage(roomId, reply, replyHtml);
await this.sendMessage(roomId, reply);
break;

@@ -213,15 +202,10 @@ }

let reply = "";
let replyHtml = "";
for (const d of descs) {
const chans = await this.bridge.hooks.listChans(d.puppetId);
reply += `${d.puppetId}: ${d.desc}:\n\n`;
replyHtml += `<h2>${d.puppetId}: ${d.html}:</h2><ul>`;
reply += `## ${d.puppetId}: ${d.desc}:\n\n`;
for (const c of chans) {
const nameHtml = escapeHtml(c.name);
if (c.category) {
reply += `${c.name}:\n`;
replyHtml += `</ul><h3>${nameHtml}</h3><ul>`;
reply += `\n### ${c.name}:\n\n`;
continue;
}
reply += ` - ${c.name}\n`;
const mxid = await this.bridge.getMxidForChan({

@@ -231,8 +215,6 @@ puppetId: d.puppetId,

});
const pill = `<a href="https://matrix.to/#/${escapeHtml(mxid)}">${nameHtml}</a>`;
replyHtml += `<li>${nameHtml}: ${pill}</li>`;
reply += ` - [${c.name}](https://matrix.to/#/${mxid})\n`;
}
replyHtml += "</ul>";
}
await this.sendMessage(roomId, reply, replyHtml);
await this.sendMessage(roomId, reply);
break;

@@ -262,18 +244,14 @@ }

const sendStr = `[Status] ${puppetId}: ${desc.desc}: ${msg}`;
const sendStrHtml = `[Status] ${puppetId}: ${desc.html}: ${md.render(msg)}`;
await this.sendMessage(info.statusRoom, sendStr, sendStrHtml);
await this.sendMessage(info.statusRoom, sendStr);
}
private async sendMessage(roomId: string, message: string, html?: string) {
if (!html) {
await this.bridge.botIntent.sendText(roomId, message, "m.notice");
} else {
await this.bridge.botIntent.underlyingClient.sendMessage(roomId, {
msgtype: "m.notice",
body: message,
formatted_body: html,
format: "org.matrix.custom.html",
});
}
private async sendMessage(roomId: string, message: string) {
const html = md.render(message);
await this.bridge.botIntent.underlyingClient.sendMessage(roomId, {
msgtype: "m.notice",
body: message,
formatted_body: html,
format: "org.matrix.custom.html",
});
}
}

@@ -11,3 +11,2 @@ import { PuppetBridge } from "./puppetbridge";

desc: string;
html: string;
}

@@ -162,3 +161,2 @@

desc: `${data.puppetMxid} (${data.puppetId})`,
html: `${data.puppetMxid} (${data.puppetId})`,
} as IProvisionerDesc;

@@ -168,6 +166,5 @@ }

puppetId: data.puppetId,
desc: await this.bridge.hooks.getDesc(data.puppetId, data.data, false),
html: await this.bridge.hooks.getDesc(data.puppetId, data.data, true),
desc: await this.bridge.hooks.getDesc(data.puppetId, data.data),
} as IProvisionerDesc;
}
}

@@ -113,3 +113,3 @@ import * as fs from "fs";

export type CreateUserHook = (user: IRemoteUser) => Promise<IRemoteUser | null>;
export type GetDescHook = (puppetId: number, data: any, html: boolean) => Promise<string>;
export type GetDescHook = (puppetId: number, data: any) => Promise<string>;
export type BotHeaderMsgHook = () => string;

@@ -189,3 +189,12 @@ export type GetDataFromStrHook = (str: string) => Promise<IRetData>;

}
const mod = "bot-sdk-" + module;
let mod = "bot-sdk-" + module;
const modParts = module.match(/^(\S+)\s(.*)/);
const MOD_PART_MODULE = 1;
const MOD_PART_EXTRA = 2;
if (modParts) {
if (modParts[MOD_PART_EXTRA]) {
args.unshift(modParts[MOD_PART_EXTRA]);
}
mod = "bot-sdk-" + modParts[MOD_PART_MODULE];
}
let logger = logMap.get(mod);

@@ -196,3 +205,3 @@ if (!logger) {

}
logger[level](args);
logger[level](...args);
};

@@ -699,2 +708,3 @@

if (this.appservice.isNamespacedUser(userId)) {
log.silly("Joining ghost to room...");
const intent = this.appservice.getIntentForUserId(userId);

@@ -706,6 +716,2 @@ await intent.ensureRegisteredAndJoined(mxid);

const cacheKey = `${params.chan.puppetId}_${mxid}`;
if (created) {
// we just invited if we freshly created
this.ghostInviteCache.set(cacheKey, true);
}
try {

@@ -720,4 +726,15 @@ const cache = this.ghostInviteCache.get(cacheKey);

if (await inviteClient.getUserId() !== puppetMxid) {
await client.inviteUser(puppetMxid, mxid);
// we just invited if we created, don't try to invite again
if (!created) {
log.silly("Inviting puppet to room...");
await client.inviteUser(puppetMxid, mxid);
}
this.ghostInviteCache.set(cacheKey, true);
// let's try to also join the room, if we use double-puppeting
const puppetClient = await this.userSync.getPuppetClient(params.chan.puppetId);
if (puppetClient) {
log.silly("Joining the room...");
await puppetClient.joinRoom(mxid);
}
}

@@ -995,2 +1012,6 @@ }

}
const room = await this.chanSync.getRemoteHandler(event.room_id);
if (room) {
return; // we are an existing room, meaning a double-puppeted user probably auto-invited. Do nothing
}
log.info(`Processing invite for ${userId} by ${inviteId}`);

@@ -997,0 +1018,0 @@ const intent = this.appservice.getIntentForUserId(userId);

@@ -109,8 +109,8 @@ import { IDbSchema } from "./db/schema/dbschema";

private async openDatabase(): Promise<void|Error> {
if (this.config.filename) {
if (this.config.connString) {
log.info("connString present in config, using postgres");
this.db = new Postgres(this.config.connString);
} else if (this.config.filename) {
log.info("Filename present in config, using sqlite");
this.db = new SQLite3(this.config.filename);
} else if (this.config.connString) {
log.info("connString present in config, using postgres");
this.db = new Postgres(this.config.connString);
}

@@ -117,0 +117,0 @@ try {

@@ -67,2 +67,8 @@ import { PuppetBridge } from "./puppetbridge";

public async getPuppetClient(puppetId: number): Promise<MatrixClient | null> {
const token = await this.bridge.provisioner.getToken(puppetId);
const puppetClient = await this.getClientFromTokenCallback(token);
return puppetClient ? puppetClient : null;
}
public async getClient(data: IRemoteUser): Promise<MatrixClient> {

@@ -73,4 +79,3 @@ // first we look if we can puppet this user to the matrix side

if (puppetData && puppetData.userId === data.userId) {
const token = await this.bridge.provisioner.getToken(data.puppetId);
const puppetClient = await this.getClientFromTokenCallback(token);
const puppetClient = await this.getPuppetClient(data.puppetId);
if (puppetClient) {

@@ -77,0 +82,0 @@ return puppetClient;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc