mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
handle messages
This commit is contained in:
parent
d9f32c1276
commit
9423fe789e
|
@ -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) {
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
14
pkg/config/commands/commands.go
Normal file
14
pkg/config/commands/commands.go
Normal 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")
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue