Add delete action for single message

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2020-12-27 14:42:51 +01:00
parent 7047a2399b
commit 3a3959c79c
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D
3 changed files with 41 additions and 5 deletions

32
action_delete.go Normal file
View file

@ -0,0 +1,32 @@
package main
import (
"fmt"
"github.com/go-irc/irc"
"github.com/pkg/errors"
)
func init() {
registerAction(func(c *irc.Client, m *irc.Message, ruleDef *rule, r *ruleAction) error {
if r.DeleteMessage == nil || !*r.DeleteMessage {
return nil
}
msgID, ok := m.Tags.GetTag("id")
if !ok || msgID == "" {
return nil
}
return errors.Wrap(
c.WriteMessage(&irc.Message{
Command: "PRIVMSG",
Params: []string{
m.Params[0],
fmt.Sprintf("/delete %s", msgID),
},
}),
"sending delete",
)
})
}

View file

@ -169,11 +169,12 @@ func (r *rule) Matches(m *irc.Message, event *string) bool {
} }
type ruleAction struct { type ruleAction struct {
Ban *string `yaml:"ban"` Ban *string `yaml:"ban"`
CounterStep *int64 `yaml:"counter_step"` CounterStep *int64 `yaml:"counter_step"`
Counter *string `yaml:"counter"` Counter *string `yaml:"counter"`
Respond *string `yaml:"respond"` DeleteMessage *bool `yaml:"delete_message"`
Timeout *time.Duration `yaml:"timeout"` Respond *string `yaml:"respond"`
Timeout *time.Duration `yaml:"timeout"`
} }
func loadConfig(filename string) error { func loadConfig(filename string) error {

View file

@ -23,6 +23,9 @@ rules: # See below for examples
- counter: "counterid" # String to identify the counter, applies templating - counter: "counterid" # String to identify the counter, applies templating
counter_step: 1 # Integer, can be negative or positive, default: +1 counter_step: 1 # Integer, can be negative or positive, default: +1
# Issue a delete on the message caught
- delete_message: true # Bool, set to true to delete
# Send responding message to the channel the original message was received in # Send responding message to the channel the original message was received in
- respond: 'Hello chatter' # String, applies templating - respond: 'Hello chatter' # String, applies templating