alexvanin
f0f31a8415
This commits adds new feature for galchedbot: video requests in the twitch chat via highlighted chat messages. This messages parsed by the bot and added to the video queue, that can be accessed by the dedicated web server. Video queue requires authorization based on random token added to the cookies.
48 lines
821 B
Go
48 lines
821 B
Go
package twitchat
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"strings"
|
|
|
|
"github.com/gempir/go-twitch-irc/v2"
|
|
)
|
|
|
|
type (
|
|
dupHandler struct {
|
|
lastMessage string
|
|
counter int
|
|
dupMinimal int
|
|
}
|
|
)
|
|
|
|
const DupMinimal = 3
|
|
|
|
func DupHandler() PrivateMessageHandler {
|
|
return &dupHandler{
|
|
lastMessage: "",
|
|
counter: 0,
|
|
dupMinimal: DupMinimal,
|
|
}
|
|
}
|
|
|
|
func (h *dupHandler) IsValid(m *twitch.PrivateMessage) bool {
|
|
return true
|
|
}
|
|
|
|
func (h *dupHandler) Handle(m *twitch.PrivateMessage, r Responser) {
|
|
data := strings.Fields(m.Message)
|
|
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)
|
|
r.Say(m.Channel, msg)
|
|
log.Print("chat: ", msg)
|
|
}
|
|
h.counter = 1
|
|
h.lastMessage = data[i]
|
|
}
|
|
}
|
|
}
|