spam:add using emoji
This commit is contained in:
@@ -149,7 +149,7 @@ If you want to change them - check available options in the help message (`!pm h
|
|||||||
> The following section is visible to the mailbox owners only
|
> The following section is visible to the mailbox owners only
|
||||||
|
|
||||||
* **`!pm spam:list`** - Show comma-separated spamlist of the room, eg: `spammer@example.com,*@spammer.org,spam@*`
|
* **`!pm spam:list`** - Show comma-separated spamlist of the room, eg: `spammer@example.com,*@spammer.org,spam@*`
|
||||||
* **`!pm spam:add`** - Mark an email address (or pattern) as spam
|
* **`!pm spam:add`** - Mark an email address (or pattern) as spam (or you can react to the email with emoji: ⛔️,🛑, or 🚫)
|
||||||
* **`!pm spam:remove`** - Unmark an email address (or pattern) as spam
|
* **`!pm spam:remove`** - Unmark an email address (or pattern) as spam
|
||||||
* **`!pm spam:reset`** - Reset spamlist
|
* **`!pm spam:reset`** - Reset spamlist
|
||||||
|
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ func (b *Bot) initCommands() commandList {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: commandSpamlistAdd,
|
key: commandSpamlistAdd,
|
||||||
description: "Mark an email address (or pattern) as spam",
|
description: "Mark an email address (or pattern) as spam (or you can react to the email with emoji: ⛔️,🛑, or 🚫)",
|
||||||
allowed: b.allowOwner,
|
allowed: b.allowOwner,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
43
bot/reaction.go
Normal file
43
bot/reaction.go
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package bot
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"maunium.net/go/mautrix/event"
|
||||||
|
|
||||||
|
"gitlab.com/etke.cc/postmoogle/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
var supportedReactions = map[string]string{
|
||||||
|
"⛔️": commandSpamlistAdd,
|
||||||
|
"🛑": commandSpamlistAdd,
|
||||||
|
"🚫": commandSpamlistAdd,
|
||||||
|
"spam": commandSpamlistAdd,
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bot) handleReaction(ctx context.Context) {
|
||||||
|
evt := eventFromContext(ctx)
|
||||||
|
content := evt.Content.AsReaction()
|
||||||
|
action, ok := supportedReactions[content.GetRelatesTo().Key]
|
||||||
|
if !ok { // cannot do anything with it
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
srcID := content.GetRelatesTo().EventID
|
||||||
|
srcEvt, err := b.lp.GetClient().GetEvent(evt.RoomID, srcID)
|
||||||
|
if err != nil {
|
||||||
|
b.Error(ctx, evt.RoomID, "cannot find event %s: %v", srcID, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
utils.ParseContent(evt, event.EventMessage)
|
||||||
|
|
||||||
|
switch action {
|
||||||
|
case commandSpamlistAdd:
|
||||||
|
sender := utils.EventField[string](&srcEvt.Content, eventFromKey)
|
||||||
|
if sender == "" {
|
||||||
|
b.Error(ctx, evt.RoomID, "cannot get sender of the email")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
b.runSpamlistAdd(ctx, []string{commandSpamlistAdd, utils.EventField[string](&srcEvt.Content, eventFromKey)})
|
||||||
|
}
|
||||||
|
}
|
||||||
23
bot/sync.go
23
bot/sync.go
@@ -21,7 +21,14 @@ func (b *Bot) initSync() {
|
|||||||
event.EventMessage,
|
event.EventMessage,
|
||||||
func(_ mautrix.EventSource, evt *event.Event) {
|
func(_ mautrix.EventSource, evt *event.Event) {
|
||||||
go b.onMessage(evt)
|
go b.onMessage(evt)
|
||||||
})
|
},
|
||||||
|
)
|
||||||
|
b.lp.OnEventType(
|
||||||
|
event.EventReaction,
|
||||||
|
func(_ mautrix.EventSource, evt *event.Event) {
|
||||||
|
go b.onReaction(evt)
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// joinPermit is called by linkpearl when processing "invite" events and deciding if rooms should be auto-joined or not
|
// joinPermit is called by linkpearl when processing "invite" events and deciding if rooms should be auto-joined or not
|
||||||
@@ -69,6 +76,20 @@ func (b *Bot) onMessage(evt *event.Event) {
|
|||||||
b.handle(ctx)
|
b.handle(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Bot) onReaction(evt *event.Event) {
|
||||||
|
// ignore own messages
|
||||||
|
if evt.Sender == b.lp.GetClient().UserID {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// mautrix 0.15.x migration
|
||||||
|
if b.ignoreBefore >= evt.Timestamp {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := newContext(evt)
|
||||||
|
b.handleReaction(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
// onBotJoin handles the "bot joined the room" event
|
// onBotJoin handles the "bot joined the room" event
|
||||||
func (b *Bot) onBotJoin(ctx context.Context) {
|
func (b *Bot) onBotJoin(ctx context.Context) {
|
||||||
evt := eventFromContext(ctx)
|
evt := eventFromContext(ctx)
|
||||||
|
|||||||
Reference in New Issue
Block a user