Update for MPS 0.9.1.

This commit is contained in:
gnuxie
2024-04-06 20:03:34 +01:00
parent 1884e1b456
commit 069dec2b9d
4 changed files with 11 additions and 2 deletions
+4 -1
View File
@@ -82,7 +82,10 @@ export class FirstMessageIsImageProtection extends AbstractProtection implements
const roomID = room.toRoomIDOrAlias();
if (!this.justJoined[roomID]) this.justJoined[roomID] = [];
if (Value.Check(RoomMessage, event)) {
const msgtype = event.content?.['msgtype'] || 'm.text';
if (!('msgtype' in event.content)) {
return Ok(undefined);
}
const msgtype = event.content['msgtype'] || 'm.text';
const formattedBody = event.content !== undefined && 'formatted_body' in event.content ? event.content?.['formatted_body'] || '' : '';
const isMedia = msgtype === 'm.image' || msgtype === 'm.video' || formattedBody.toLowerCase().includes('<img');
if (isMedia && this.justJoined[roomID].includes(event['sender'])) {
+3
View File
@@ -64,6 +64,9 @@ export class MessageIsMediaProtection extends AbstractProtection implements Prot
public async handleTimelineEvent(room: MatrixRoomID, event: RoomEvent): Promise<ActionResult<void>> {
if (Value.Check(RoomMessage, event)) {
if (!('msgtype' in event.content)) {
return Ok(undefined);
}
const msgtype = event.content?.['msgtype'] || 'm.text';
const formattedBody = event.content !== undefined && 'formatted_body' in event.content ? event.content?.['formatted_body'] || '' : '';
const isMedia = msgtype === 'm.image' || msgtype === 'm.video' || formattedBody.toLowerCase().includes('<img');
+1 -1
View File
@@ -63,7 +63,7 @@ export class MessageIsVoiceProtection extends AbstractProtection implements Prot
public async handleTimelineEvent(room: MatrixRoomID, event: RoomEvent): Promise<ActionResult<void>> {
const roomID = room.toRoomIDOrAlias();
if (Value.Check(RoomMessage, event)) {
if (event.content?.msgtype !== 'm.audio') {
if (!('msgtype' in event.content) || event.content?.msgtype !== 'm.audio') {
return Ok(undefined);
}
await this.draupnir.managementRoomOutput.logMessage(LogLevel.INFO, "MessageIsVoice", `Redacting event from ${event['sender']} for posting a voice message. ${Permalinks.forEvent(roomID, event['event_id'], [serverName(this.draupnir.clientUserID)])}`);
+3
View File
@@ -88,6 +88,9 @@ export class WordListProtection extends AbstractProtection implements Protection
public async handleTimelineEvent(room: MatrixRoomID, event: RoomEvent): Promise<ActionResult<void>> {
const minsBeforeTrusting = this.draupnir.config.protections.wordlist.minutesBeforeTrusting;
if (Value.Check(RoomMessage, event)) {
if (!('msgtype' in event.content)) {
return Ok(undefined);
}
const message = (event.content !== undefined && 'formatted_body' in event.content && event.content?.['formatted_body']) || event.content?.['body'];
if (!message === undefined) {
return Ok(undefined);