How to use the matrix-bot-sdk.Permalinks.forEvent function in matrix-bot-sdk

To help you get started, we’ve selected a few matrix-bot-sdk 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 / mjolnir / src / Mjolnir.ts View on Github external
// themselves.
        if (this.banLists.map(b => b.roomId).includes(roomId)) {
            if (ALL_RULE_TYPES.includes(event['type'])) {
                await this.syncListForRoom(roomId);
            }
        }

        if (Object.keys(this.protectedRooms).includes(roomId)) {
            if (event['sender'] === await this.client.getUserId()) return; // Ignore ourselves

            // Iterate all the protections
            for (const protection of this.protections) {
                try {
                    await protection.handleEvent(this, roomId, event);
                } catch (e) {
                    const eventPermalink = Permalinks.forEvent(roomId, event['event_id']);
                    LogService.error("Mjolnir", "Error handling protection: " + protection.name);
                    LogService.error("Mjolnir", "Failed event: " + eventPermalink);
                    LogService.error("Mjolnir", e);
                    await this.client.sendNotice(config.managementRoom, "There was an error processing an event through a protection - see log for details. Event: " + eventPermalink);
                }
            }

            // Run the event handlers - we always run this after protections so that the protections
            // can flag the event for redaction.
            await this.redactionQueue.handleEvent(roomId, event, this.client);

            if (event['type'] === 'm.room.power_levels' && event['state_key'] === '') {
                // power levels were updated - recheck permissions
                ErrorCache.resetError(roomId, ERROR_KIND_PERMISSION);
                const url = this.protectedRooms[roomId];
                let html = `Power levels changed in <a href="${url}">${roomId}</a> - checking permissions...`;
github matrix-org / mjolnir / src / queues / AutomaticRedactionQueue.ts View on Github external
public async handleEvent(roomId: string, event: any, mjolnirClient: MatrixClient) {
        if (this.isUserQueued(event['sender'])) {
            const permalink = Permalinks.forEvent(roomId, event['event_id']);
            try {
                LogService.info("AutomaticRedactionQueue", `Redacting event because the user is listed as bad: ${permalink}`)
                if (!config.noop) {
                    await mjolnirClient.redactEvent(roomId, event['event_id']);
                } else {
                    await logMessage(LogLevel.WARN, "AutomaticRedactionQueue", `Tried to redact ${permalink} but Mjolnir is running in no-op mode`);
                }
            } catch (e) {
                logMessage(LogLevel.WARN, "AutomaticRedactionQueue", `Unable to redact message: ${permalink}`);
                LogService.warn("AutomaticRedactionQueue", e);
            }
        }
    }
}