2023-09-07 22:34:53 +02:00
|
|
|
package data
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
ErrRecordNotFound = errors.New("record not found")
|
|
|
|
ErrChannelRecordAlreadyExists = errors.New("channel already in database")
|
|
|
|
ErrEditConflict = errors.New("edit conflict")
|
|
|
|
ErrCommandRecordAlreadyExists = errors.New("command already exists")
|
|
|
|
ErrLastFMUserRecordAlreadyExists = errors.New("lastfm connection already set")
|
|
|
|
ErrUserAlreadyExists = errors.New("user already in database")
|
|
|
|
)
|
|
|
|
|
|
|
|
// struct Models wraps the models, making them callable
|
|
|
|
// as app.models.Channels.Get(login)
|
|
|
|
type Models struct {
|
|
|
|
Channels interface {
|
2023-10-10 19:07:49 +02:00
|
|
|
Insert(login, id string) error
|
2023-09-07 22:34:53 +02:00
|
|
|
Get(login string) (*Channel, error)
|
|
|
|
GetAll() ([]*Channel, error)
|
|
|
|
GetJoinable() ([]string, error)
|
|
|
|
Delete(login string) error
|
|
|
|
}
|
|
|
|
Users interface {
|
|
|
|
Insert(login, twitchId string) error
|
|
|
|
Get(login string) (*User, error)
|
|
|
|
Check(twitchId string) (*User, error)
|
|
|
|
SetLevel(login string, level int) error
|
|
|
|
GetLevel(twitchId string) (int, error)
|
|
|
|
SetLocation(twitchId, location string) error
|
|
|
|
GetLocation(twitchId string) (string, error)
|
|
|
|
SetLastFM(login, lastfmUser string) error
|
|
|
|
GetLastFM(login string) (string, error)
|
|
|
|
Delete(login string) error
|
|
|
|
}
|
|
|
|
Commands interface {
|
2023-12-10 23:50:59 +01:00
|
|
|
Get(name, channel string) (*Command, error)
|
2023-12-03 17:24:42 +01:00
|
|
|
GetAll() ([]*Command, error)
|
2023-12-17 18:48:46 +01:00
|
|
|
GetAllChannel(channel string) ([]*Command, error)
|
2023-09-07 22:34:53 +02:00
|
|
|
Insert(command *Command) error
|
|
|
|
Update(command *Command) error
|
2023-12-10 23:50:59 +01:00
|
|
|
SetCategory(name, channel, category string) error
|
|
|
|
SetLevel(name, channel string, level int) error
|
|
|
|
SetHelp(name, channel, helptext string) error
|
|
|
|
Delete(name, channel string) error
|
2023-09-07 22:34:53 +02:00
|
|
|
}
|
|
|
|
Timers interface {
|
|
|
|
Get(name string) (*Timer, error)
|
2023-10-04 00:05:38 +02:00
|
|
|
GetIdentifier(name string) (string, error)
|
2023-09-07 22:34:53 +02:00
|
|
|
Insert(timer *Timer) error
|
|
|
|
Update(timer *Timer) error
|
|
|
|
GetAll() ([]*Timer, error)
|
|
|
|
Delete(name string) error
|
|
|
|
}
|
2023-10-05 23:11:11 +02:00
|
|
|
Uploads interface {
|
|
|
|
Insert(twitchLogin, twitchID, twitchMessage, twitchChannel, filehoster, downloadURL, identifier string)
|
|
|
|
UpdateUploadURL(identifier, uploadURL string)
|
|
|
|
}
|
2023-10-10 16:07:35 +02:00
|
|
|
CommandsLogs interface {
|
|
|
|
Insert(twitchLogin, twitchId, twitchChannel, twitchMessage, commandName string, uLvl int, identifier, rawMsg string)
|
|
|
|
}
|
2023-10-10 16:49:00 +02:00
|
|
|
SentMessagesLogs interface {
|
2023-10-10 17:51:12 +02:00
|
|
|
Insert(twitchChannel, twitchMessage, ctxCommandName, ctxUser, ctxUserID, ctxMsg, identifier, ctxRaw string)
|
2023-10-10 16:49:00 +02:00
|
|
|
}
|
2023-09-07 22:34:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewModels(db *sql.DB) Models {
|
|
|
|
return Models{
|
2023-10-10 16:49:00 +02:00
|
|
|
Channels: ChannelModel{DB: db},
|
|
|
|
Users: UserModel{DB: db},
|
|
|
|
Commands: CommandModel{DB: db},
|
|
|
|
Timers: TimerModel{DB: db},
|
|
|
|
Uploads: UploadModel{DB: db},
|
|
|
|
CommandsLogs: CommandsLogModel{DB: db},
|
|
|
|
SentMessagesLogs: SentMessagesLogModel{DB: db},
|
2023-09-07 22:34:53 +02:00
|
|
|
}
|
|
|
|
}
|