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
|
# Changelog
|
||||||
|
|
||||||
|
## 4.0.1 - 2019-07-22
|
||||||
|
### Changed
|
||||||
|
- Twitch chat library version from v1 to v2
|
||||||
|
|
||||||
## 4.0.0 - 2019-06-23
|
## 4.0.0 - 2019-06-23
|
||||||
### Added
|
### Added
|
||||||
- Twitch chat module
|
- Twitch chat module
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -2,7 +2,7 @@ module galched-bot
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/bwmarrin/discordgo v0.19.0
|
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/pkg/errors v0.8.1
|
||||||
github.com/stretchr/testify v1.3.0 // indirect
|
github.com/stretchr/testify v1.3.0 // indirect
|
||||||
go.uber.org/atomic v1.3.2 // 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/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 h1:Q9gQGI/3yJzYwlYDlFsGJzWfpaqubMExfmBXNpOC6W0=
|
||||||
github.com/gempir/go-twitch-irc v1.1.0/go.mod h1:Pc661rsUSmkQXvI9W2bNyLt4ZrMAgHZPnVwMQEJ0fdo=
|
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 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
|
||||||
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
version = "4.0.0"
|
version = "4.0.1"
|
||||||
twitchUser = "galchedbot"
|
twitchUser = "galchedbot"
|
||||||
twitchIRCRoom = "galched"
|
twitchIRCRoom = "galched"
|
||||||
discordTokenPath = "./tokens/.discordtoken"
|
discordTokenPath = "./tokens/.discordtoken"
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gempir/go-twitch-irc"
|
"github.com/gempir/go-twitch-irc/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
@ -18,7 +18,7 @@ type (
|
||||||
|
|
||||||
const DupMinimal = 3
|
const DupMinimal = 3
|
||||||
|
|
||||||
func DupHandler() MessageHandler {
|
func DupHandler() PrivateMessageHandler {
|
||||||
return &dupHandler{
|
return &dupHandler{
|
||||||
lastMessage: "",
|
lastMessage: "",
|
||||||
counter: 0,
|
counter: 0,
|
||||||
|
@ -30,15 +30,15 @@ func (h *dupHandler) IsValid(m string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *dupHandler) Handle(ch string, u *twitch.User, m *twitch.Message, client *twitch.Client) {
|
func (h *dupHandler) Handle(m *twitch.PrivateMessage, r Responser) {
|
||||||
data := strings.Fields(m.Text)
|
data := strings.Fields(m.Message)
|
||||||
for i := range data {
|
for i := range data {
|
||||||
if data[i] == h.lastMessage {
|
if data[i] == h.lastMessage {
|
||||||
h.counter++
|
h.counter++
|
||||||
} else {
|
} else {
|
||||||
if h.counter >= h.dupMinimal {
|
if h.counter >= h.dupMinimal {
|
||||||
msg := fmt.Sprintf("%d %s подряд", h.counter, h.lastMessage)
|
msg := fmt.Sprintf("%d %s подряд", h.counter, h.lastMessage)
|
||||||
client.Say(ch, msg)
|
r.Say(m.Channel, msg)
|
||||||
log.Print("chat: ", msg)
|
log.Print("chat: ", msg)
|
||||||
}
|
}
|
||||||
h.counter = 1
|
h.counter = 1
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
package twitchat
|
package twitchat
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gempir/go-twitch-irc"
|
"github.com/gempir/go-twitch-irc/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
MessageHandler interface {
|
Responser interface {
|
||||||
|
Say(channel, message string)
|
||||||
|
}
|
||||||
|
|
||||||
|
PrivateMessageHandler interface {
|
||||||
IsValid(string) bool
|
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 (
|
import (
|
||||||
"galched-bot/modules/settings"
|
"galched-bot/modules/settings"
|
||||||
|
|
||||||
"github.com/gempir/go-twitch-irc"
|
"github.com/gempir/go-twitch-irc/v2"
|
||||||
_ "github.com/gempir/go-twitch-irc"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
TwitchIRC struct {
|
TwitchIRC struct {
|
||||||
username string
|
username string
|
||||||
chat *twitch.Client
|
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.handlers = append(irc.handlers, DupHandler())
|
||||||
|
|
||||||
irc.chat = twitch.NewClient(s.TwitchUser, s.TwitchToken)
|
irc.chat = twitch.NewClient(s.TwitchUser, s.TwitchToken)
|
||||||
irc.chat.OnNewMessage(irc.MessageHandler)
|
irc.chat.OnPrivateMessage(irc.PrivateMessageHandler)
|
||||||
irc.chat.Join(s.TwitchIRCRoom)
|
irc.chat.Join(s.TwitchIRCRoom)
|
||||||
|
|
||||||
return irc, nil
|
return irc, nil
|
||||||
|
@ -41,13 +40,13 @@ func (c *TwitchIRC) Stop() error {
|
||||||
return c.chat.Disconnect()
|
return c.chat.Disconnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TwitchIRC) MessageHandler(ch string, u twitch.User, m twitch.Message) {
|
func (c *TwitchIRC) PrivateMessageHandler(msg twitch.PrivateMessage) {
|
||||||
if u.Username == c.username {
|
if msg.User.Name == c.username {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for i := range c.handlers {
|
for i := range c.handlers {
|
||||||
if c.handlers[i].IsValid(m.Text) {
|
if c.handlers[i].IsValid(msg.Message) {
|
||||||
c.handlers[i].Handle(ch, &u, &m, c.chat)
|
c.handlers[i].Handle(&msg, c.chat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue