How to use the matrix-appservice-bridge.Logging.get 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 matrix-org / matrix-appservice-slack / src / SlackRTMHandler.ts View on Github external
private createRtmClient(token: string, logLabel: string): RTMClient {
        const LOG_LEVELS = ["debug", "info", "warn", "error", "silent"];
        const connLog = Logging.get(`RTM-${logLabel.substr(0, LOG_TEAM_LEN)}`);
        const logLevel = LOG_LEVELS.indexOf(this.main.config.rtm!.log_level || "silent");
        const rtm = new RTMClient(token, {
            logLevel: LogLevel.DEBUG, // We will filter this ourselves.
            logger: {
                getLevel: () => LogLevel.DEBUG,
                setLevel: () => {},
                setName: () => {}, // We handle both of these ourselves.
                debug: logLevel <= 0 ? connLog.debug.bind(connLog) : () => {},
                warn: logLevel <= 1 ? connLog.warn.bind(connLog) : () => {},
                info: logLevel <= 2 ? connLog.info.bind(connLog) : () => {},
                error: logLevel <= 3 ? connLog.error.bind(connLog) : () => {},
            } as Logger,
        });

        rtm.on("error", (error) => {
            // We must handle this lest the process be killed.
github matrix-org / matrix-bifrost / src / MatrixRoomHandler.ts View on Github external
IUserStateChanged,
    IChatStringState,
    IChatTyping,
    IStoreRemoteUser,
    IChatReadReceipt,
} from "./purple/PurpleEvents";
import { ProfileSync } from "./ProfileSync";
import { Util } from "./Util";
import { ProtoHacks } from "./ProtoHacks";
import { Store } from "./Store";
import { Deduplicator } from "./Deduplicator";
import { Config } from "./Config";
import * as entityDecode from "parse-entities";
import { MessageFormatter } from "./MessageFormatter";
import { IEventRequest, IEventRequestData } from "./MatrixTypes";
const log = Logging.get("MatrixRoomHandler");

const ACCOUNT_LOCK_MS = 1000;
const EVENT_MAPPING_SIZE = 16384;

/**
 * Handles creation and handling of rooms.
 */
export class MatrixRoomHandler {
    private bridge: Bridge;
    private accountRoomLock: Set;
    private remoteEventIdMapping: Map; // remote_id -> event_id
    private roomCreationLock: Map>;
    constructor(
        private purple: IPurpleInstance,
        private profileSync: ProfileSync,
        private store: Store,
github matrix-org / matrix-bifrost / src / AutoRegistration.ts View on Github external
import { IConfigAutoReg } from "./Config";
import { Bridge, MatrixUser } from "matrix-appservice-bridge";
import * as request from "request-promise-native";
import { Util } from "./Util";
import { Logging } from "matrix-appservice-bridge";
import { Store } from "./Store";
import { IPurpleInstance } from "./purple/IPurpleInstance";
import { IPurpleAccount } from "./purple/IPurpleAccount";
import { PurpleProtocol } from "./purple/PurpleProtocol";
import { MUSER_TYPE_ACCOUNT } from "./StoreTypes";
const log = Logging.get("AutoRegistration");

export interface IAutoRegHttpOpts {
    method: string;
    usernameResult: string|null;
}

export interface IAutoRegStep {
    type: "http"|"executable"|"implicit";
    path: string;
    opts: IAutoRegHttpOpts|undefined;
    parameters: {[key: string]: string}; // key -> parameter value
    paramsToStore: string[];
    headers: {[key: string]: string}; // key -> value
}

export class AutoRegistration {
github matrix-org / matrix-appservice-slack / src / SlackClientFactory.ts View on Github external
import { Datastore, TeamEntry } from "./datastore/Models";
import { WebClient, WebClientOptions, LogLevel, Logger } from "@slack/web-api";
import { Logging } from "matrix-appservice-bridge";
import { TeamInfoResponse, AuthTestResponse, UsersInfoResponse } from "./SlackResponses";

const webLog = Logging.get("slack-api");
const log = Logging.get("SlackClientFactory");

/**
 * This class holds clients for slack teams and individuals users
 * who are puppeting their accounts.
 */

interface RequiredConfigOptions {
    slack_client_opts?: WebClientOptions;
}

export class SlackClientFactory {
    private teamClients: Map = new Map();
    private puppets: Map = new Map();
    constructor(private datastore: Datastore, private config?: RequiredConfigOptions, private onRemoteCall?: (method: string) => void) {

    }
github matrix-org / matrix-bifrost / src / xmppjs / XJSInstance.ts View on Github external
IStoreRemoteUser,
    IChatReadReceipt,
    IChatStringState,
    IEventBody} from "../purple/PurpleEvents";
import { IBasicProtocolMessage, IMessageAttachment } from "../MessageFormatter";
import { PresenceCache } from "./PresenceCache";
import { Metrics } from "../Metrics";
import { ServiceHandler } from "./ServiceHandler";
import { XJSConnection } from "./XJSConnection";
import { AutoRegistration } from "../AutoRegistration";
import { XmppJsGateway } from "./XJSGateway";
import { IStza } from "./Stanzas";
import { Util } from "../Util";

const xLog = Logging.get("XMPP-conn");
const log = Logging.get("XmppJsInstance");

class XmppProtocol extends PurpleProtocol {
    constructor() {
        super({
            id: "xmpp-js",
            name: "XMPP.js Protocol Plugin",
            homepage: "N/A",
            summary: "Fake purple protocol plugin for xmpp.js",
        }, false, false);
    }

    public getMxIdForProtocol(
            senderId: string,
            domain: string,
            prefix: string = "") {
        const j = jid(senderId);
github matrix-org / matrix-appservice-slack / src / AdminCommands.ts View on Github external
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import { Logging } from "matrix-appservice-bridge";
import * as yargs from "yargs";
import { AdminCommand, ResponseCallback } from "./AdminCommand";
import { Main } from "./Main";
import { BridgedRoom } from "./BridgedRoom";

const log = Logging.get("AdminCommands");

const RoomIdCommandOption = {
    alias: "R",
    demandOption: true,
    description: "Matrix Room ID",
};

export class AdminCommands {
    private yargs: yargs.Argv;
    private commands = [
            this.list,
            this.show,
            this.link,
            this.unlink,
            this.join,
            this.leave,
github matrix-org / matrix-bifrost / src / ProfileSync.ts View on Github external
import { IPurpleAccount, IProfileProvider } from "./purple/IPurpleAccount";
import * as _fs from "fs";
import * as path from "path";
import { PurpleProtocol } from "./purple/PurpleProtocol";
import { Logging, MatrixUser, Bridge, Intent } from "matrix-appservice-bridge";
import { Config } from "./Config";
import { Store, BifrostRemoteUser } from "./Store";
const log = Logging.get("ProfileSync");

export class ProfileSync {
    constructor(private bridge: Bridge, private config: Config, private store: Store) {

    }

    public async updateProfile(
        protocol: PurpleProtocol,
        senderId: string,
        account: IProfileProvider,
        force: boolean = false,
        senderIdToLookup?: string,
    ) {
        senderIdToLookup = senderIdToLookup ? senderIdToLookup : senderId;
        const {matrixUser, remoteUser} = await this.getOrCreateStoreUsers(protocol, senderId);
        const lastCheck = matrixUser.get("last_check");
github matrix-org / matrix-appservice-slack / src / TeamSyncer.ts View on Github external
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import { Logging } from "matrix-appservice-bridge";
import { BridgedRoom } from "./BridgedRoom";
import { Main } from "./Main";
import { ConversationsInfoResponse, UsersInfoResponse, ConversationsListResponse, ConversationsInfo,
    UsersListResponse, ConversationsMembersResponse } from "./SlackResponses";
import { WebClient } from "@slack/web-api";
import PQueue from "p-queue";
import { ISlackUser } from "./BaseSlackHandler";

const log = Logging.get("TeamSyncer");

export interface ITeamSyncConfig {
    channels?: {
        enabled: boolean;
        whitelist?: string[];
        blacklist?: string[];
        alias_prefix?: string;
    };
    users?: {
        enabled: boolean;
    };
}

const TEAM_SYNC_CONCURRENCY = 1;
const TEAM_SYNC_ITEM_CONCURRENCY = 5;
const JOIN_CONCURRENCY = 5;
github matrix-org / matrix-appservice-slack / src / Main.ts View on Github external
import { AdminCommands } from "./AdminCommands";
import * as Provisioning from "./Provisioning";
import { INTERNAL_ID_LEN } from "./BaseSlackHandler";
import { SlackRTMHandler } from "./SlackRTMHandler";
import { ConversationsInfoResponse, ConversationsOpenResponse, AuthTestResponse } from "./SlackResponses";

import { Datastore, TeamEntry, RoomEntry } from "./datastore/Models";
import { NedbDatastore } from "./datastore/NedbDatastore";
import { PgDatastore } from "./datastore/postgres/PgDatastore";
import { SlackClientFactory } from "./SlackClientFactory";
import { Response } from "express";
import { SlackRoomStore } from "./SlackRoomStore";
import * as QuickLRU from "quick-lru";
import PQueue from "p-queue";

const log = Logging.get("Main");

const RECENT_EVENTID_SIZE = 20;
const STARTUP_TEAM_INIT_CONCURRENCY = 10;
export const METRIC_SENT_MESSAGES = "sent_messages";

export interface ISlackTeam {
    id: string;
    domain: string;
    name: string;
}

interface MetricsLabels { [labelName: string]: string; }

export class Main {

    public get botIntent(): Intent {
github matrix-org / matrix-bifrost / src / Config.ts View on Github external
import { IAutoRegStep } from "./AutoRegistration";
import { IRoomAlias } from "./RoomAliasSet";
import { IXJSBackendOpts } from "./xmppjs/XJSBackendOpts";
import { Logging } from "matrix-appservice-bridge";

const log = Logging.get("Config");

export class Config {

    public readonly bridge: IConfigBridge = {
        domain: "",
        homeserverUrl: "",
        mediaserverUrl: undefined,
        userPrefix: "_purple_",
        userStoreFile: "user-store.db",
        roomStoreFile: "room-store.db",
    };

    public readonly purple: IConfigPurple = {
        backendOpts: undefined,
        backend: "node-purple",
        enableDebug: false,