How to use the matrix-appservice-bridge.ClientFactory function in matrix-appservice-bridge

To help you get started, we’ve selected a few matrix-appservice-bridge examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Half-Shot / matrix-appservice-discord / tools / chanfix.ts View on Github external
]));
    process.exit(0);
}

const yamlConfig = yaml.safeLoad(fs.readFileSync("./discord-registration.yaml", "utf8"));
const registration = AppServiceRegistration.fromObject(yamlConfig);
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
      },
github Half-Shot / matrix-appservice-discord / tools / ghostfix.ts View on Github external
]));
    process.exit(0);
}

const yamlConfig = yaml.safeLoad(fs.readFileSync("./discord-registration.yaml", "utf8"));
const registration = AppServiceRegistration.fromObject(yamlConfig);
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
      },
github Half-Shot / matrix-appservice-discord / src / discordas.ts View on Github external
async function run(port: number, fileConfig: DiscordBridgeConfig) {
    const config = new DiscordBridgeConfig();
    config.applyConfig(fileConfig);
    config.applyEnvironmentOverrides(process.env);
    Log.Configure(config.logging);
    log.info("Starting Discord AS");
    const yamlConfig = yaml.safeLoad(fs.readFileSync(cli.opts.registrationPath, "utf8"));
    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); }
github Half-Shot / matrix-appservice-discord / tools / adminme.ts View on Github external
}

if (!options.userid) {
    console.error("Missing userid parameter. Check -h");
    process.exit(1);
}

const yamlConfig = yaml.safeLoad(fs.readFileSync("discord-registration.yaml", "utf8"));
const registration = AppServiceRegistration.fromObject(yamlConfig);
const config: DiscordBridgeConfig = yaml.safeLoad(fs.readFileSync(options.config, "utf8")) as DiscordBridgeConfig;

if (registration === null) {
    throw new Error("Failed to parse registration file");
}

const clientFactory = new ClientFactory({
    appServiceUserId: `@${registration.sender_localpart}:${config.bridge.domain}`,
    token: registration.as_token,
    url: config.bridge.homeserverUrl,
});
const client = clientFactory.getClientAs();
const intent = new Intent(client, client, {registered: true});

async function run() {
    try {
        await intent.setPowerLevel(options.roomid, options.userid, options.power);
        console.log("Power levels set");
        process.exit(0);
    } catch (err) {
        console.error("Could not apply power levels to room:", err);
        process.exit(1);
    }
github Half-Shot / matrix-appservice-discord / tools / addRoomsToDirectory.ts View on Github external
{
        header: "Options",
        optionList: optionDefinitions,
    },
    ]));
    process.exit(0);
}
const yamlConfig = yaml.safeLoad(fs.readFileSync("./discord-registration.yaml", "utf8"));
const registration = AppServiceRegistration.fromObject(yamlConfig);
const config: DiscordBridgeConfig = yaml.safeLoad(fs.readFileSync(options.config, "utf8")) as DiscordBridgeConfig;

if (registration === null) {
    throw new Error("Failed to parse registration file");
}

const clientFactory = new ClientFactory({
    appServiceUserId: `@${registration.sender_localpart}:${config.bridge.domain}`,
    token: registration.as_token,
    url: config.bridge.homeserverUrl,
});

const bridge = new Bridge({
    controller: {
        onEvent: () => { },
    },
    domain: "rubbish",
    homeserverUrl: true,
    registration: true,
});

const discordstore = new DiscordStore(config.database ? config.database.filename : "discord.db");
github Half-Shot / matrix-appservice-twitter / twitter-as.js View on Github external
run: function (port, config) {

        //Read registration file

    var regObj = yaml.safeLoad(fs.readFileSync("twitter-registration.yaml", 'utf8'));
    regObj = AppServiceRegistration.fromObject(regObj);
    if (regObj === null) {
      throw new Error("Failed to parse registration file");
    }

    var room_handler;

    var clientFactory = new ClientFactory(
      {
        sdk: require("matrix-js-sdk"),
        url: config.bridge.homeserverUrl,
        token: regObj.as_token,
        appServiceUserId: "@" + regObj.sender_localpart + ":" + config.bridge.domain
      }
        );

    bridge = new Bridge({
      homeserverUrl: config.bridge.homeserverUrl,
      domain: config.bridge.domain,
      registration: regObj,
      controller: {
        onUserQuery: userQuery,
        onEvent: (request, context) => { room_handler.passEvent(request, context); },
        onAliasQuery: (alias, aliasLocalpart) => {