Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add matrix-protection-suite skeleton for spam police (for illustration or serious purposes) #70

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

Gnuxie
Copy link

@Gnuxie Gnuxie commented May 15, 2024

(uhh, i also added typescript, eslint, and prettier).

Next steps: breaking out the message scanning into protections i guess.

Comment on lines +113 to +130
// FIXME: You probably want to create your own class that impleemnts the `ProtectionsConfig`
// interface (Ctrl+click on MjolnirProtectionsConfig to drill down and find it).
// As this one reuses a state event used by Mjolnir to store it.
// You don't need to though.
const protectionsConfigResult = await MjolnirProtectionsConfig.create(
new BotSDKMatrixAccountData<MjolnirEnabledProtectionsEvent>(
MjolnirEnabledProtectionsEventType,
MjolnirEnabledProtectionsEvent,
client,
),
loggableConfigTracker,
{
missingProtectionCB: makeMissingProtectionCB(),
},
);
if (isError(protectionsConfigResult)) {
return protectionsConfigResult;
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently are reusing MjolnirProtectionsConfig

Comment on lines +18 to +50
export class SpamPoliceBot {
private handleTimelineEventListener = this.handleTimelineEvent.bind(this);
public constructor(
/** The userID for the main bot user. */
public readonly clientUserID: StringUserID,
public readonly managementRoomID: StringRoomID,
public readonly protectedRoomsSet: ProtectedRoomsSet,
// note for jjj: This is the MatrixClient from the bot-sdk, but only allows
// you to do actions that interact with Matrix, rather than listen for events.
// we restrict that on purpose so that people don't add adhoc listeners to it,
// which can easily get lost and become untracked / leaky etc.
public readonly client: MatrixSendClient,
// This provides the same functionality as the client, but each individual
// request into its own capability that can be provided to keep the scope
// of client dependencies restricted. (This really really helps when testing them).
// It will also help if you want the actions to go through a different client if
// say one server is down as you have suggested. Since you can easily implement
// your own client platform.
public readonly clientPlatform: ClientPlatform,
// These are used to access the various revision issuers.
public readonly roomStateManager: RoomStateManager,
public readonly policyRoomManager: PolicyRoomManager,
public readonly roomMembershipManager: RoomMembershipManager,
// This gives access to the list of joined rooms and also timelien events.
private readonly clientRooms: ClientRooms,
) {
this.clientRooms.on("timeline", this.handleTimelineEventListener);
}

private handleTimelineEvent(roomID: StringRoomID, event: RoomEvent): void {
this.protectedRoomsSet.handleTimelineEvent(roomID, event);
}
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the context object i was talking about that you'd want to give to protections

Comment on lines +97 to +99
// for jjj: the clientsInRoomMap handles all event ingress into MPS for us,
// and in turn informs the various room state managers so that they are up to date
clientsInRoomMap.handleTimelineEvent(roomID, event);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sets up one syncing client to inform the clientsInRoomMap about new events. The ClientsInRoomMap from MPS is the source for all events in MPS.

}

// async run ({client, roomId, event, mxid, displayname, blacklist}){
async run(datapoints) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i honestly couldn't figure out how to break this down to make an example protection, it seems like there's so many different things being done in this one handle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant