chrly/lib/worker/handlers.go

57 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package worker
import (
"elyby/minecraft-skinsystem/lib/data"
"elyby/minecraft-skinsystem/lib/services"
)
func handleChangeUsername(model usernameChanged) (bool) {
if (model.OldUsername == "") {
services.Logger.IncCounter("worker.change_username.empty_old_username")
record := data.SkinItem{
UserId: model.AccountId,
Username: model.NewUsername,
}
record.Save()
return true
}
record, err := data.FindSkinByUsername(model.OldUsername)
if (err != nil) {
services.Logger.IncCounter("worker.change_username.username_not_found")
// TODO: я не уверен, что это валидное поведение
// Суть в том, что здесь может возникнуть ошибка в том случае, если записи в базе нету
// а значит его нужно, как минимум, зарегистрировать
return true
}
record.Username = model.NewUsername
record.Save()
services.Logger.IncCounter("worker.change_username.processed")
return true
}
func handleSkinChanged(model skinChanged) (bool) {
record, err := data.FindSkinById(model.AccountId)
if (err != nil) {
services.Logger.IncCounter("worker.skin_changed.id_not_found")
return true
}
record.SkinId = model.SkinId
record.Hash = model.Hash
record.Is1_8 = model.Is1_8
record.IsSlim = model.IsSlim
record.Url = model.Url
record.Save()
services.Logger.IncCounter("worker.skin_changed.processed")
return true
}