fix: bot name and id return, websocket

This commit is contained in:
Lala, Shahd
2026-05-31 21:28:04 +00:00
committed by LQ63
parent 35d7e0dc85
commit 587e34babc
6 changed files with 21 additions and 7 deletions
@@ -51,7 +51,7 @@ class BotAccount extends PanacheEntityBase:
@JoinColumn(name = "owner_id", nullable = false)
var owner: UserAccount = uninitialized
@Column(unique = true, nullable = false, length = 256)
@Column(unique = true, nullable = false, length = 1024)
var token: String = uninitialized
var rating: Int = 1500
@@ -153,9 +153,10 @@ class AccountService:
val bot = new BotAccount()
bot.name = botName
bot.owner = owner
bot.token = generateBotToken(bot.id)
bot.token = UUID.randomUUID().toString
bot.createdAt = Instant.now()
botAccountRepository.persist(bot)
bot.token = generateBotToken(bot.id, bot.name)
log.infof("Bot account %s created for owner %s", botName, ownerId.toString)
Right(bot)
@@ -194,7 +195,7 @@ class AccountService:
case Some(bot) =>
if bot.owner.id != ownerId then Left(AccountError.NotAuthorized)
else
bot.token = generateBotToken(botId)
bot.token = generateBotToken(botId, bot.name)
botAccountRepository.persist(bot)
Right(bot)
@@ -228,12 +229,13 @@ class AccountService:
officialBotAccountRepository.delete(botId)
Right(())
private def generateBotToken(botId: UUID): String =
private def generateBotToken(botId: UUID, botName: String): String =
Jwt
.issuer("nowchess")
.subject(botId.toString)
.expiresAt(Long.MaxValue)
.claim("type", "bot")
.claim("name", botName)
.sign()
@Transactional