Update go-twitch-irc library revision from v1 to v2
This commit is contained in:
parent
601747352a
commit
17db60dea1
7 changed files with 27 additions and 18 deletions
|
@ -1,5 +1,9 @@
|
|||
# Changelog
|
||||
|
||||
## 4.0.1 - 2019-07-22
|
||||
### Changed
|
||||
- Twitch chat library version from v1 to v2
|
||||
|
||||
## 4.0.0 - 2019-06-23
|
||||
### Added
|
||||
- Twitch chat module
|
||||
|
|
2
go.mod
2
go.mod
|
@ -2,7 +2,7 @@ module galched-bot
|
|||
|
||||
require (
|
||||
github.com/bwmarrin/discordgo v0.19.0
|
||||
github.com/gempir/go-twitch-irc v1.1.0
|
||||
github.com/gempir/go-twitch-irc/v2 v2.2.0
|
||||
github.com/pkg/errors v0.8.1
|
||||
github.com/stretchr/testify v1.3.0 // indirect
|
||||
go.uber.org/atomic v1.3.2 // indirect
|
||||
|
|
2
go.sum
2
go.sum
|
@ -4,6 +4,8 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
|
|||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/gempir/go-twitch-irc v1.1.0 h1:Q9gQGI/3yJzYwlYDlFsGJzWfpaqubMExfmBXNpOC6W0=
|
||||
github.com/gempir/go-twitch-irc v1.1.0/go.mod h1:Pc661rsUSmkQXvI9W2bNyLt4ZrMAgHZPnVwMQEJ0fdo=
|
||||
github.com/gempir/go-twitch-irc/v2 v2.2.0 h1:9iYRr/PkT5tqnD9J0awBXtwS4R4DatA5cMQbsua6OvM=
|
||||
github.com/gempir/go-twitch-irc/v2 v2.2.0/go.mod h1:0HXoEr9l7gNjwajosptV0w0xGpHeU6gsD7JDlfvjTYI=
|
||||
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
|
||||
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
version = "4.0.0"
|
||||
version = "4.0.1"
|
||||
twitchUser = "galchedbot"
|
||||
twitchIRCRoom = "galched"
|
||||
discordTokenPath = "./tokens/.discordtoken"
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/gempir/go-twitch-irc"
|
||||
"github.com/gempir/go-twitch-irc/v2"
|
||||
)
|
||||
|
||||
type (
|
||||
|
@ -18,7 +18,7 @@ type (
|
|||
|
||||
const DupMinimal = 3
|
||||
|
||||
func DupHandler() MessageHandler {
|
||||
func DupHandler() PrivateMessageHandler {
|
||||
return &dupHandler{
|
||||
lastMessage: "",
|
||||
counter: 0,
|
||||
|
@ -30,15 +30,15 @@ func (h *dupHandler) IsValid(m string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (h *dupHandler) Handle(ch string, u *twitch.User, m *twitch.Message, client *twitch.Client) {
|
||||
data := strings.Fields(m.Text)
|
||||
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)
|
||||
client.Say(ch, msg)
|
||||
r.Say(m.Channel, msg)
|
||||
log.Print("chat: ", msg)
|
||||
}
|
||||
h.counter = 1
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
package twitchat
|
||||
|
||||
import (
|
||||
"github.com/gempir/go-twitch-irc"
|
||||
"github.com/gempir/go-twitch-irc/v2"
|
||||
)
|
||||
|
||||
type (
|
||||
MessageHandler interface {
|
||||
Responser interface {
|
||||
Say(channel, message string)
|
||||
}
|
||||
|
||||
PrivateMessageHandler interface {
|
||||
IsValid(string) bool
|
||||
Handle(ch string, u *twitch.User, m *twitch.Message, client *twitch.Client)
|
||||
Handle(m *twitch.PrivateMessage, r Responser)
|
||||
}
|
||||
)
|
||||
|
|
|
@ -3,15 +3,14 @@ package twitchat
|
|||
import (
|
||||
"galched-bot/modules/settings"
|
||||
|
||||
"github.com/gempir/go-twitch-irc"
|
||||
_ "github.com/gempir/go-twitch-irc"
|
||||
"github.com/gempir/go-twitch-irc/v2"
|
||||
)
|
||||
|
||||
type (
|
||||
TwitchIRC struct {
|
||||
username string
|
||||
chat *twitch.Client
|
||||
handlers []MessageHandler
|
||||
handlers []PrivateMessageHandler
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -23,7 +22,7 @@ func New(s *settings.Settings) (*TwitchIRC, error) {
|
|||
irc.handlers = append(irc.handlers, DupHandler())
|
||||
|
||||
irc.chat = twitch.NewClient(s.TwitchUser, s.TwitchToken)
|
||||
irc.chat.OnNewMessage(irc.MessageHandler)
|
||||
irc.chat.OnPrivateMessage(irc.PrivateMessageHandler)
|
||||
irc.chat.Join(s.TwitchIRCRoom)
|
||||
|
||||
return irc, nil
|
||||
|
@ -41,13 +40,13 @@ func (c *TwitchIRC) Stop() error {
|
|||
return c.chat.Disconnect()
|
||||
}
|
||||
|
||||
func (c *TwitchIRC) MessageHandler(ch string, u twitch.User, m twitch.Message) {
|
||||
if u.Username == c.username {
|
||||
func (c *TwitchIRC) PrivateMessageHandler(msg twitch.PrivateMessage) {
|
||||
if msg.User.Name == c.username {
|
||||
return
|
||||
}
|
||||
for i := range c.handlers {
|
||||
if c.handlers[i].IsValid(m.Text) {
|
||||
c.handlers[i].Handle(ch, &u, &m, c.chat)
|
||||
if c.handlers[i].IsValid(msg.Message) {
|
||||
c.handlers[i].Handle(&msg, c.chat)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue