From 17db60dea13a6bd25f8279b3efa8fefcd1904584 Mon Sep 17 00:00:00 2001 From: alexvanin Date: Sat, 20 Jul 2019 22:14:07 +0300 Subject: [PATCH] Update go-twitch-irc library revision from v1 to v2 --- changelog.md | 4 ++++ go.mod | 2 +- go.sum | 2 ++ modules/settings/settings.go | 2 +- modules/twitchat/duphandler.go | 10 +++++----- modules/twitchat/handlers.go | 10 +++++++--- modules/twitchat/twitchat.go | 15 +++++++-------- 7 files changed, 27 insertions(+), 18 deletions(-) diff --git a/changelog.md b/changelog.md index 28361cf..1da0e85 100644 --- a/changelog.md +++ b/changelog.md @@ -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 diff --git a/go.mod b/go.mod index 14d0b5a..ca01272 100644 --- a/go.mod +++ b/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 diff --git a/go.sum b/go.sum index 28ae0a3..bcabf38 100644 --- a/go.sum +++ b/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= diff --git a/modules/settings/settings.go b/modules/settings/settings.go index 0cf6c80..922afc8 100644 --- a/modules/settings/settings.go +++ b/modules/settings/settings.go @@ -6,7 +6,7 @@ import ( ) const ( - version = "4.0.0" + version = "4.0.1" twitchUser = "galchedbot" twitchIRCRoom = "galched" discordTokenPath = "./tokens/.discordtoken" diff --git a/modules/twitchat/duphandler.go b/modules/twitchat/duphandler.go index 01b0b74..b9a1433 100644 --- a/modules/twitchat/duphandler.go +++ b/modules/twitchat/duphandler.go @@ -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 diff --git a/modules/twitchat/handlers.go b/modules/twitchat/handlers.go index a2fdc50..d6c6134 100644 --- a/modules/twitchat/handlers.go +++ b/modules/twitchat/handlers.go @@ -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) } ) diff --git a/modules/twitchat/twitchat.go b/modules/twitchat/twitchat.go index d70c376..ef70f7c 100644 --- a/modules/twitchat/twitchat.go +++ b/modules/twitchat/twitchat.go @@ -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) } } }