Add Whisper / RawMessage actions

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2021-05-26 15:36:03 +02:00
parent 477f07c963
commit 9c2aef9c5f
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D
4 changed files with 84 additions and 0 deletions

29
action_raw.go Normal file
View file

@ -0,0 +1,29 @@
package main
import (
"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.RawMessage == nil {
return nil
}
rawMsg, err := formatMessage(*r.RawMessage, m, ruleDef, nil)
if err != nil {
return errors.Wrap(err, "preparing raw message")
}
msg, err := irc.ParseMessage(rawMsg)
if err != nil {
return errors.Wrap(err, "parsing raw message")
}
return errors.Wrap(
c.WriteMessage(msg),
"sending raw message",
)
})
}

42
action_whisper.go Normal file
View file

@ -0,0 +1,42 @@
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.WhisperTo == nil || r.WhisperMessage == nil {
return nil
}
to, err := formatMessage(*r.WhisperTo, m, ruleDef, nil)
if err != nil {
return errors.Wrap(err, "preparing whisper receiver")
}
msg, err := formatMessage(*r.WhisperMessage, m, ruleDef, nil)
if err != nil {
return errors.Wrap(err, "preparing whisper message")
}
channel := "#tmijs" // As a fallback, copied from tmi.js
if len(config.Channels) > 0 {
channel = fmt.Sprintf("#%s", config.Channels[0])
}
return errors.Wrap(
c.WriteMessage(&irc.Message{
Command: "PRIVMSG",
Params: []string{
channel,
fmt.Sprintf("/w %s %s", to, msg),
},
}),
"sending whisper",
)
})
}

View file

@ -302,8 +302,13 @@ type ruleAction struct {
DeleteMessage *bool `json:"delete_message" yaml:"delete_message"`
RawMessage *string `json:"raw_message" yaml:"raw_message"`
Respond *string `json:"respond" yaml:"respond"`
RespondFallback *string `json:"respond_fallback" yaml:"respond_fallback"`
Timeout *time.Duration `json:"timeout" yaml:"timeout"`
WhisperMessage *string `json:"whisper_message" yaml:"whisper_message"`
WhisperTo *string `json:"whisper_to" yaml:"whisper_to"`
}

View file

@ -57,6 +57,9 @@ rules: # See below for examples
# Issue a delete on the message caught
- delete_message: true # Bool, set to true to delete
# Send raw IRC message to Twitch servers
- raw_message: 'PRIVMSG #{{ .channel }} :Test' # String, applies templating
# Send responding message to the channel the original message was received in
- respond: 'Hello chatter' # String, applies templating
respond_fallback: 'Oh noes' # String, text to send if the template function causes
@ -65,6 +68,11 @@ rules: # See below for examples
# Issue a timeout on the user who wrote the chat-line
- timeout: 1s # Duration value: 1s / 1m / 1h
# Send a whisper (ATTENTION: You need to have a known / verified bot for this!)
# Without being known / verified your whisper will just silently get dropped by Twitch
- whisper_to: '{{ .username }}' # String, username to send to, applies templating
whisper_message: 'Ohai!' # String, message to send, applies templating
# Add a cooldown to the command (not to trigger counters twice, ...)
cooldown: 1s # Duration value: 1s / 1m / 1h