2022-08-09 01:09:53 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/gempir/go-twitch-irc/v3"
|
|
|
|
"github.com/lyx0/nourybot/internal/data"
|
|
|
|
"github.com/lyx0/nourybot/pkg/commands/decapi"
|
|
|
|
"github.com/lyx0/nourybot/pkg/common"
|
|
|
|
)
|
|
|
|
|
2022-08-09 22:49:48 +02:00
|
|
|
func (app *Application) AddChannel(login string, message twitch.PrivateMessage) {
|
2022-08-09 01:09:53 +02:00
|
|
|
userId, err := decapi.GetIdByLogin(login)
|
|
|
|
if err != nil {
|
|
|
|
app.Logger.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
channel := &data.Channel{
|
|
|
|
Login: login,
|
|
|
|
TwitchID: userId,
|
|
|
|
}
|
|
|
|
|
|
|
|
err = app.Models.Channels.Insert(channel)
|
|
|
|
if err != nil {
|
2022-08-09 21:24:46 +02:00
|
|
|
reply := fmt.Sprintf("Something went wrong FeelsBadMan %s", err)
|
|
|
|
common.Send(message.Channel, reply, app.TwitchClient)
|
|
|
|
return
|
|
|
|
} else {
|
2022-08-10 22:06:36 +02:00
|
|
|
app.TwitchClient.Join(login)
|
2022-08-09 21:24:46 +02:00
|
|
|
reply := fmt.Sprintf("Added channel %s", login)
|
|
|
|
common.Send(message.Channel, reply, app.TwitchClient)
|
|
|
|
return
|
2022-08-09 01:09:53 +02:00
|
|
|
}
|
2022-08-09 19:50:46 +02:00
|
|
|
}
|
2022-08-09 01:09:53 +02:00
|
|
|
|
2022-08-09 23:19:08 +02:00
|
|
|
func (app *Application) GetAllChannels() {
|
|
|
|
channel, err := app.Models.Channels.GetAll()
|
|
|
|
if err != nil {
|
|
|
|
app.Logger.Error(err)
|
2022-08-10 18:16:39 +02:00
|
|
|
return
|
2022-08-09 23:19:08 +02:00
|
|
|
}
|
|
|
|
app.Logger.Infow("All channels:",
|
|
|
|
"channel", channel)
|
|
|
|
}
|
|
|
|
|
2022-08-09 22:49:48 +02:00
|
|
|
func (app *Application) DeleteChannel(login string, message twitch.PrivateMessage) {
|
2022-08-09 19:50:46 +02:00
|
|
|
err := app.Models.Channels.Delete(login)
|
|
|
|
if err != nil {
|
|
|
|
common.Send(message.Channel, "Something went wrong FeelsBadMan", app.TwitchClient)
|
|
|
|
app.Logger.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-08-10 22:06:36 +02:00
|
|
|
app.TwitchClient.Depart(login)
|
|
|
|
|
2022-08-09 19:50:46 +02:00
|
|
|
reply := fmt.Sprintf("Deleted channel %s", login)
|
|
|
|
common.Send(message.Channel, reply, app.TwitchClient)
|
2022-08-09 01:09:53 +02:00
|
|
|
}
|
2022-08-10 18:16:39 +02:00
|
|
|
|
|
|
|
func (app *Application) InitialJoin() {
|
|
|
|
channel, err := app.Models.Channels.GetJoinable()
|
|
|
|
if err != nil {
|
|
|
|
app.Logger.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range channel {
|
|
|
|
app.TwitchClient.Join(v)
|
|
|
|
app.Logger.Infow("Joining channel:",
|
|
|
|
"channel", v)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|