96 lines
2.5 KiB
Go
96 lines
2.5 KiB
Go
package discord
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"git.jojodev.com/minecraft/mcm-discord/database"
|
|
"github.com/Karitham/corde"
|
|
)
|
|
|
|
func appResponse(app *database.Application) *corde.InteractionRespData {
|
|
embed := corde.NewEmbed().
|
|
Color(0x417505).
|
|
Title("Application").
|
|
Thumbnail(corde.Image{
|
|
URL: fmt.Sprintf("https://minotar.net/helm/%s/100.png", app.Username),
|
|
}).
|
|
Field("Username", strings.ReplaceAll(app.Username, "_", `\_`)).
|
|
Field("Age", fmt.Sprint(app.Age)).
|
|
Field("Type of Player", app.PlayerType).
|
|
Field("Ever been Banned", fmt.Sprint(app.EverBanned))
|
|
if app.EverBanned && app.EverBannedExplanation != "" {
|
|
embed.Field("Reason for being banned", app.EverBannedExplanation)
|
|
}
|
|
if app.Reference != "" {
|
|
embed.Field("Reference", app.Reference)
|
|
}
|
|
embed.Field("Read the Rules", app.ReadRules).
|
|
Field("Status", app.Status())
|
|
return corde.NewResp().Embeds(embed.B()).B()
|
|
}
|
|
|
|
func (d Discord) info(w corde.ResponseWriter, i *corde.Interaction) {
|
|
id := i.Data.Options.Int64("app_id")
|
|
username := i.Data.Options.String("username")
|
|
if id == 0 && username == "" {
|
|
w.Respond(corde.NewResp().Content("Info requires an application ID or username.").Ephemeral().B())
|
|
return
|
|
}
|
|
|
|
var app *database.Application
|
|
var err error
|
|
if id != 0 {
|
|
app, err = d.store.ApplicationByID(id)
|
|
if err != nil {
|
|
w.Respond(corde.NewResp().Contentf("No application #%d was found.", id).Ephemeral().B())
|
|
return
|
|
}
|
|
} else {
|
|
apps, err := d.store.ApplicationsByUsername(username)
|
|
if err != nil {
|
|
w.Respond(corde.NewResp().Content("No applications matched.").Ephemeral().B())
|
|
return
|
|
}
|
|
if len(apps) == 0 {
|
|
apps, err = d.store.ApplicationsByPlayerUsername(username)
|
|
if err != nil {
|
|
w.Respond(corde.NewResp().Content("No applications matched.").Ephemeral().B())
|
|
return
|
|
}
|
|
if len(apps) == 1 {
|
|
app = apps[0]
|
|
}
|
|
} else if len(apps) == 1 {
|
|
app = apps[0]
|
|
}
|
|
}
|
|
|
|
w.Respond(appResponse(app))
|
|
}
|
|
|
|
func (d Discord) search(w corde.ResponseWriter, i *corde.Interaction) {
|
|
username := i.Data.Options.String("username")
|
|
|
|
apps, err := d.store.ApplicationsByUsername(username)
|
|
if err != nil {
|
|
w.Respond(corde.NewResp().Content("No applications matched.").Ephemeral().B())
|
|
return
|
|
}
|
|
count, err := d.store.ApplicationsByUsernameCount(username)
|
|
if err != nil {
|
|
w.Respond(corde.NewResp().Content("No applications matched.").Ephemeral().B())
|
|
return
|
|
}
|
|
|
|
var app *database.Application
|
|
if count > 0 {
|
|
if count == 1 {
|
|
app = apps[0]
|
|
} else {
|
|
}
|
|
}
|
|
|
|
w.Respond(appResponse(app))
|
|
}
|