2019-06-23 13:12:35 +00:00
|
|
|
package twitchat
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"strings"
|
|
|
|
|
2019-07-20 19:14:07 +00:00
|
|
|
"github.com/gempir/go-twitch-irc/v2"
|
2019-06-23 13:12:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
dupHandler struct {
|
|
|
|
lastMessage string
|
|
|
|
counter int
|
|
|
|
dupMinimal int
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
const DupMinimal = 3
|
|
|
|
|
2019-07-20 19:14:07 +00:00
|
|
|
func DupHandler() PrivateMessageHandler {
|
2019-06-23 13:12:35 +00:00
|
|
|
return &dupHandler{
|
|
|
|
lastMessage: "",
|
|
|
|
counter: 0,
|
|
|
|
dupMinimal: DupMinimal,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *dupHandler) IsValid(m string) bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2019-07-20 19:14:07 +00:00
|
|
|
func (h *dupHandler) Handle(m *twitch.PrivateMessage, r Responser) {
|
|
|
|
data := strings.Fields(m.Message)
|
2019-06-23 13:12:35 +00:00
|
|
|
for i := range data {
|
|
|
|
if data[i] == h.lastMessage {
|
|
|
|
h.counter++
|
|
|
|
} else {
|
|
|
|
if h.counter >= h.dupMinimal {
|
|
|
|
msg := fmt.Sprintf("%d %s подряд", h.counter, h.lastMessage)
|
2019-07-20 19:14:07 +00:00
|
|
|
r.Say(m.Channel, msg)
|
2019-06-23 13:12:35 +00:00
|
|
|
log.Print("chat: ", msg)
|
|
|
|
}
|
|
|
|
h.counter = 1
|
|
|
|
h.lastMessage = data[i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|