mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-12-20 20:01:17 +00:00
Add delete action for single message
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
7047a2399b
commit
3a3959c79c
3 changed files with 41 additions and 5 deletions
32
action_delete.go
Normal file
32
action_delete.go
Normal 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",
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
11
config.go
11
config.go
|
@ -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 {
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue