53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package discord
|
|
|
|
import (
|
|
"git.jojodev.com/minecraft/mcm-discord/database"
|
|
"git.jojodev.com/minecraft/mcm-discord/socket"
|
|
"github.com/Karitham/corde"
|
|
)
|
|
|
|
type Storer interface {
|
|
ApplicationByID(int64) (*database.Application, error)
|
|
ApplicationsByPlayerUsername(string) ([]*database.Application, error)
|
|
ApplicationsByUsername(string) ([]*database.Application, error)
|
|
ApplicationsByUsernameCount(string) (int64, error)
|
|
ApplicationUpdateAccepted(*bool, int64) error
|
|
PlayersByUsername(string) ([]*database.Player, error)
|
|
PlayersByUsernameApplicationNotNull(string) ([]*database.Player, error)
|
|
PlayersByUsernameApplicationNotNullCount(string) (int64, error)
|
|
PlayersByDiscordIsNull() ([]*database.Player, error)
|
|
PlayerUpdateApplication(int64, int64) error
|
|
PlayerUpdateDiscordID(string, int64) error
|
|
}
|
|
|
|
type Discord struct {
|
|
store Storer
|
|
sock *socket.Socket
|
|
Mux *corde.Mux
|
|
}
|
|
|
|
func New(store Storer, sock *socket.Socket, publicKey, appID, botToken string) *Discord {
|
|
m := corde.NewMux(publicKey, corde.SnowflakeFromString(appID), botToken)
|
|
|
|
d := &Discord{
|
|
store: store,
|
|
sock: sock,
|
|
Mux: m,
|
|
}
|
|
|
|
m.Route("app", func(m *corde.Mux) {
|
|
// Info
|
|
m.Command("search", d.search)
|
|
m.Command("info", d.info)
|
|
|
|
// Action
|
|
m.Command("accept", d.accept)
|
|
m.Command("deny", d.deny)
|
|
m.Command("clear", d.clear)
|
|
})
|
|
// Sync
|
|
m.Command("sync", nil)
|
|
|
|
return d
|
|
}
|