handle messages

This commit is contained in:
lyx0 2021-10-14 00:19:35 +02:00
parent d9f32c1276
commit 9423fe789e
3 changed files with 26 additions and 4 deletions

View file

@ -3,6 +3,7 @@ package bot
import (
twitch "github.com/gempir/go-twitch-irc/v2"
cfg "github.com/lyx0/nourybot/pkg/config"
"github.com/lyx0/nourybot/pkg/config/commands"
log "github.com/sirupsen/logrus"
)
@ -24,6 +25,10 @@ func NewBot(cfg *cfg.Config) *Bot {
func (b *Bot) Connect() error {
log.Info("fn Connect")
b.twitchClient.OnPrivateMessage(func(message twitch.PrivateMessage) {
commands.HandleCommand(message, b.twitchClient)
})
err := b.twitchClient.Connect()
if err != nil {
log.Error("Error Connecting from Twitch: ", err)
@ -45,8 +50,11 @@ func (b *Bot) Say(channel string, message string) {
b.twitchClient.Say(channel, message)
}
func (b *Bot) OnPrivateMessage(callback func(message *twitch.PrivateMessage)) {
log.Info(callback)
func (b *Bot) OnPrivateMessage(message *twitch.PrivateMessage) {
log.Info("fn OnPrivateMessage")
tc := b.twitchClient
commands.HandleCommand(*message, tc)
}
func (b *Bot) Join(channel string) {

View file

@ -2,7 +2,7 @@ package main
import (
"github.com/lyx0/nourybot/cmd/bot"
config "github.com/lyx0/nourybot/pkg/config"
"github.com/lyx0/nourybot/pkg/config"
)
func main() {
@ -11,7 +11,7 @@ func main() {
nb.Join("nourybot")
nb.Say("nourybot", "test")
nb.Say("nourybot", "HeyGuys")
nb.Connect()
}

View file

@ -0,0 +1,14 @@
package commands
import (
"github.com/gempir/go-twitch-irc/v2"
log "github.com/sirupsen/logrus"
)
func HandleCommand(message twitch.PrivateMessage, twitchClient *twitch.Client) {
log.Info("fn HandleCommand")
switch message.Message {
case "xd":
twitchClient.Say(message.Channel, "xd")
}
}