Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const {
domain,
homeserverUrl,
registration,
} = bridgeConfig
// const domain = 'aka.cn'
// const homeServerUrl = 'http://matrix.aka.cn:8008'
// const registrationFile = REGISTRATION_FILE
const controller = {
onEvent : onEvent.bind(this),
onUserQuery : onUserQuery.bind(this),
}
const bridge = new Bridge({
controller,
domain,
homeserverUrl,
registration,
})
return bridge
}
private async runBridge(port: number, config: any) {
const checkOnly = process.env.BIFROST_CHECK_ONLY === "true";
log.info("Starting purple bridge on port", port);
this.cfg.ApplyConfig(config);
if (checkOnly && this.config.logging.console === "off") {
// Force console if we are doing an integrity check only.
Logging.configure({
console: "info",
});
} else {
Logging.configure(this.cfg.logging);
}
this.bridge = new Bridge({
controller: {
// onUserQuery: userQuery,
onAliasQuery: (alias, aliasLocalpart) => this.eventHandler!.onAliasQuery(alias, aliasLocalpart),
onEvent: (r: IEventRequest, context) => {
if (this.eventHandler === undefined) {return; }
const p = this.eventHandler.onEvent(r, context).catch((err) => {
log.error("onEvent err", err);
}).catch(() => {
Metrics.requestOutcome(false, r.getDuration(), "fail");
}).then(() => {
Metrics.requestOutcome(false, r.getDuration(), "success");
});
},
onLog: (msg: string, error: boolean) => {
bridgeLog[error ? "warn" : "debug"](msg);
},
const registration = AppServiceRegistration.fromObject(yamlConfig);
if (registration === null) {
throw new Error("Failed to parse registration file");
}
const botUserId = `@${registration.sender_localpart}:${config.bridge.domain}`;
const clientFactory = new ClientFactory({
appServiceUserId: botUserId,
token: registration.as_token,
url: config.bridge.homeserverUrl,
});
const store = new DiscordStore(config.database);
const callbacks: { [id: string]: callbackFn; } = {};
const bridge = new Bridge({
clientFactory,
controller: {
// onUserQuery: userQuery,
onAliasQueried: async (alias: string, roomId: string) => {
try {
return await callbacks.onAliasQueried(alias, roomId);
} catch (err) { log.error("Exception thrown while handling \"onAliasQueried\" event", err); }
},
onAliasQuery: async (alias: string, aliasLocalpart: string) => {
try {
return await callbacks.onAliasQuery(alias, aliasLocalpart);
} catch (err) { log.error("Exception thrown while handling \"onAliasQuery\" event", err); }
},
onEvent: async (request) => {
const data = request.getData();
try {
const config = new DiscordBridgeConfig();
config.applyConfig(yaml.safeLoad(fs.readFileSync(options.config, "utf8")) as DiscordBridgeConfig);
config.applyEnvironmentOverrides(process.env);
if (registration === null) {
throw new Error("Failed to parse registration file");
}
const botUserId = `@${registration.sender_localpart}:${config.bridge.domain}`;
const clientFactory = new ClientFactory({
appServiceUserId: botUserId,
token: registration.as_token,
url: config.bridge.homeserverUrl,
});
const bridge = new Bridge({
clientFactory,
controller: {
onEvent: () => { },
},
domain: config.bridge.domain,
homeserverUrl: config.bridge.homeserverUrl,
intentOptions: {
clients: {
dontJoin: true, // handled manually
},
},
registration,
roomStore: config.database.roomStorePath,
userStore: config.database.userStorePath,
});
constructor(config, registration) {
log.info("InstagramBridge", "Constructing bridge");
this._config = config;
this._registration = registration;
this._adminRooms = {}; // { roomId: AdminRoom }
WebService.bind(config.web.bind, config.web.port);
OAuthService.prepare(config.instagram.clientId, config.instagram.clientSecret, config.instagram.publicUrlBase);
this._bridge = new Bridge({
registration: this._registration,
homeserverUrl: this._config.homeserver.url,
domain: this._config.homeserver.domain,
controller: {
onEvent: this._onEvent.bind(this),
onUserQuery: this._onUserQuery.bind(this),
onAliasQuery: this._onAliasQuery.bind(this),
onAliasQueried: this._onAliasQueried.bind(this),
onLog: (line, isError) => {
var method = isError ? log.error : log.verbose;
method("matrix-appservice-bridge", line);
}
// TODO: thirdPartyLookup support?
},
suppressEcho: false,
let bridgeStores = {};
const usingNeDB = config.db === undefined;
if (usingNeDB) {
const dbdir = config.dbdir || "";
const URL = "https://github.com/matrix-org/matrix-appservice-slack/blob/master/docs/datastores.md";
log.warn("** NEDB IS END-OF-LIFE **");
log.warn("Starting with version 1.0, the nedb datastore is being discontinued in favour of " +
`postgresql. Please see ${URL} for more informmation.`);
bridgeStores = {
eventStore: path.join(dbdir, "event-store.db"),
roomStore: path.join(dbdir, "room-store.db"),
userStore: path.join(dbdir, "user-store.db"),
};
}
this.bridge = new Bridge({
controller: {
onEvent: (request: Request) => {
const ev = request.getData();
this.stateStorage.onEvent(ev);
this.onMatrixEvent(ev).then(() => {
log.info(`Handled ${ev.event_id} (${ev.room_id})`);
}).catch((ex) => {
log.error(`Failed to handle ${ev.event_id} (${ev.room_id})`, ex);
});
},
onUserQuery: () => ({}), // auto-provision users with no additional data
},
domain: config.homeserver.server_name,
homeserverUrl: config.homeserver.url,
registration,
...bridgeStores,
const config = new DiscordBridgeConfig();
config.applyConfig(yaml.safeLoad(fs.readFileSync(options.config, "utf8")) as DiscordBridgeConfig);
config.applyEnvironmentOverrides(process.env);
if (registration === null) {
throw new Error("Failed to parse registration file");
}
const botUserId = `@${registration.sender_localpart}:${config.bridge.domain}`;
const clientFactory = new ClientFactory({
appServiceUserId: botUserId,
token: registration.as_token,
url: config.bridge.homeserverUrl,
});
const bridge = new Bridge({
clientFactory,
controller: {
onEvent: () => { },
},
domain: config.bridge.domain,
homeserverUrl: config.bridge.homeserverUrl,
intentOptions: {
clients: {
dontJoin: true, // handled manually
},
},
registration,
roomStore: config.database.roomStorePath,
userStore: config.database.userStorePath,
});
request,
context,
)
const onUserQuery = (
user: any
) => matrixHandler.onUserQuery(
user,
)
const controller = {
onEvent,
onUserQuery,
}
const bridge = new Bridge({
controller,
domain,
homeserverUrl,
registration,
})
return bridge
}
export function createBridge (manager: AppServiceManager) {
log.verbose('AppServiceManager', 'createBridge()')
appServiceManager = manager
const domain = 'aka.cn'
const homeserverUrl = 'http://matrix.aka.cn:8008'
const registration = REGISTRATION_FILE
const controller = {
onEvent : onEvent,
onUserQuery : onUserQuery,
}
const bridge = new Bridge({
controller,
domain,
homeserverUrl,
registration,
})
return bridge
}