dcbot/internal/domain/group.go

94 lines
2.0 KiB
Go

package domain
import (
"fmt"
"time"
)
type Group struct {
ID string
ServerID string // Discord server ID
ChannelGainedVillages string
ChannelLostVillages string
ServerKey string // Tribal Wars server key
VersionCode string
CreatedAt time.Time
}
type CreateGroupParams struct {
serverID string
serverKey string
versionCode string
channelGainedVillages string
channelLostVillages string
}
func NewCreateGroupParams(serverID, versionCode, serverKey, channelGainedVillages, channelLostVillages string) (CreateGroupParams, error) {
if serverID == "" {
return CreateGroupParams{}, RequiredError{
Field: "ServerID",
}
}
if versionCode == "" {
return CreateGroupParams{}, RequiredError{
Field: "VersionCode",
}
}
if serverKey == "" {
return CreateGroupParams{}, RequiredError{
Field: "ServerKey",
}
}
return CreateGroupParams{
serverID: serverID,
serverKey: serverKey,
versionCode: versionCode,
channelGainedVillages: channelGainedVillages,
channelLostVillages: channelLostVillages,
}, nil
}
func (c CreateGroupParams) ServerID() string {
return c.serverID
}
func (c CreateGroupParams) VersionCode() string {
return c.versionCode
}
func (c CreateGroupParams) ServerKey() string {
return c.serverKey
}
func (c CreateGroupParams) ChannelGainedVillages() string {
return c.channelGainedVillages
}
func (c CreateGroupParams) ChannelLostVillages() string {
return c.channelLostVillages
}
type ListGroupsParams struct {
ServerIDs []string
}
type GroupLimitReachedError struct {
Current int // current number of groups
Limit int // maximum number of groups
}
func (e GroupLimitReachedError) Error() string {
return fmt.Sprintf("group limit has been reached (%d/%d)", e.Current, e.Limit)
}
func (e GroupLimitReachedError) UserError() string {
return e.Error()
}
func (e GroupLimitReachedError) Code() ErrorCode {
return ErrorCodeValidationError
}