Erster Discord Versuch

This commit is contained in:
daru
2022-07-17 19:42:49 +02:00
parent fd0f8bc8e2
commit 3efd003424
7 changed files with 95 additions and 13 deletions

26
ober.go
View File

@@ -435,6 +435,15 @@ func Register(ctx *fasthttp.RequestCtx) {
ctx.SetStatusCode(fasthttp.StatusExpectationFailed)
return
}
// check user discord id
if register.DiscordID != 0 && discc != nil {
_, err = discc.User(fmt.Sprint(register.DiscordID != 0))
if err != nil {
ctx.WriteString("Discord user id is kaputt")
ctx.SetStatusCode(fasthttp.StatusExpectationFailed)
return
}
}
// REGISTER
user := UserData{
Username: register.Username,
@@ -499,6 +508,16 @@ func RegisterUpdate(ctx *fasthttp.RequestCtx) {
if regUpdate.Secret != "" {
user.Secret = regUpdate.Secret
}
// check user discord id
if regUpdate.DiscordID != 0 && discc != nil {
_, err = discc.User(fmt.Sprint(regUpdate.DiscordID))
if err != nil {
ctx.WriteString("Discord user id is kaputt")
ctx.SetStatusCode(fasthttp.StatusExpectationFailed)
return
}
}
user.DiscordID = regUpdate.DiscordID
err = SaveUser(user)
@@ -795,6 +814,7 @@ func processUpdateAppointmentReq(ctx *fasthttp.RequestCtx, update bool) {
for i, appointment := range appoints {
var appData *Appointment
var found bool
fresh := false
if update {
// kann sich (noch) nicht in der Vergagenheit verabreden
@@ -816,7 +836,7 @@ func processUpdateAppointmentReq(ctx *fasthttp.RequestCtx, update bool) {
}
// save appointment and get list
appData, err = AddUserToAppointment(username, appointment.Anime, appointment.Time)
appData, fresh, err = AddUserToAppointment(username, appointment.Anime, appointment.Time)
} else {
found, err = CheckAnimeExistInDb(appointment.Anime)
if err != nil {
@@ -836,6 +856,10 @@ func processUpdateAppointmentReq(ctx *fasthttp.RequestCtx, update bool) {
return
}
appoints[i].Users = appData.Users
if update && fresh {
SendAppointBroadcast(username, appData)
}
}
data, err := json.Marshal(appoints)