From 3a3959c79c2387adb13ea2c15d7d9dfe2f8ddfb3 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Sun, 27 Dec 2020 14:42:51 +0100 Subject: [PATCH] Add delete action for single message Signed-off-by: Knut Ahlers --- action_delete.go | 32 ++++++++++++++++++++++++++++++++ config.go | 11 ++++++----- wiki/Home.md | 3 +++ 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 action_delete.go diff --git a/action_delete.go b/action_delete.go new file mode 100644 index 0000000..3cb99f5 --- /dev/null +++ b/action_delete.go @@ -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", + ) + }) +} diff --git a/config.go b/config.go index df9fe26..604a95c 100644 --- a/config.go +++ b/config.go @@ -169,11 +169,12 @@ func (r *rule) Matches(m *irc.Message, event *string) bool { } type ruleAction struct { - Ban *string `yaml:"ban"` - CounterStep *int64 `yaml:"counter_step"` - Counter *string `yaml:"counter"` - Respond *string `yaml:"respond"` - Timeout *time.Duration `yaml:"timeout"` + Ban *string `yaml:"ban"` + CounterStep *int64 `yaml:"counter_step"` + Counter *string `yaml:"counter"` + DeleteMessage *bool `yaml:"delete_message"` + Respond *string `yaml:"respond"` + Timeout *time.Duration `yaml:"timeout"` } func loadConfig(filename string) error { diff --git a/wiki/Home.md b/wiki/Home.md index bcd2096..0a0d855 100644 --- a/wiki/Home.md +++ b/wiki/Home.md @@ -23,6 +23,9 @@ rules: # See below for examples - counter: "counterid" # String to identify the counter, applies templating 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 - respond: 'Hello chatter' # String, applies templating