fix: creator auto-creates as bot (poll mode), auto-upgrade existing human records

The creator was being registered with webhookUrl='http://human.local/' and
isHuman=true. Now uses poll.local and isHuman=false. The auto-upgrade logic
on login also converts any existing creator record from human to bot mode.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-13 22:28:43 +00:00
co-authored by Claude Opus 4.6
parent 42b1642932
commit 8076d860c7
+29 -16
View File
@@ -53,14 +53,14 @@ authRouter.post('/login', rateLimit(60_000, 10), async (c) => {
}).from(schema.bots).where(eq(schema.bots.publicKey, pubkey)).limit(1)
if (rows.length === 0) {
// Auto-create human fighter for the Creator if not registered
// Auto-create bot for the Creator if not registered
if (isCreatorPubkey(pubkey)) {
const id = nanoid(12)
const secret = randomBytes(32).toString('hex')
await db.insert(schema.bots).values({
id,
name: 'the_creator',
webhookUrl: 'http://human.local/',
webhookUrl: 'http://poll.local/',
avatarSeed: 'the_creator',
archetype: 'the_creator',
secretHash: createHash('sha256').update(secret).digest('hex'),
@@ -84,7 +84,7 @@ authRouter.post('/login', rateLimit(60_000, 10), async (c) => {
bestStreak: 0,
tier: 0,
isActive: true,
isHuman: true,
isHuman: false,
customization: null,
satsWon: 0,
satsWagered: 0,
@@ -96,14 +96,21 @@ authRouter.post('/login', rateLimit(60_000, 10), async (c) => {
}
const bot = rows[0]
const isHuman = bot.webhookUrl === 'http://human.local/'
// Auto-upgrade: if creator logs in, ensure archetype is always the_creator
if (isCreatorPubkey(pubkey) && bot.archetype !== "the_creator") {
await db.update(schema.bots).set({ archetype: "the_creator" }).where(eq(schema.bots.id, bot.id))
bot.archetype = "the_creator"
// Auto-upgrade: if creator logs in, ensure archetype + bot mode are correct
if (isCreatorPubkey(pubkey)) {
const fixes: Record<string, string> = {}
if (bot.archetype !== "the_creator") fixes.archetype = "the_creator"
if (bot.webhookUrl === "http://human.local/") fixes.webhookUrl = "http://poll.local/"
if (Object.keys(fixes).length > 0) {
await db.update(schema.bots).set(fixes).where(eq(schema.bots.id, bot.id))
if (fixes.archetype) bot.archetype = "the_creator"
if (fixes.webhookUrl) bot.webhookUrl = "http://poll.local/"
}
}
const isHuman = bot.webhookUrl === 'http://human.local/'
return c.json({
exists: true,
bot: {
@@ -411,14 +418,20 @@ authRouter.post('/nostr/session', rateLimit(60_000, 10), async (c) => {
if (rows.length > 0) {
const bot = rows[0]
botId = bot.id
const isHuman = bot.webhookUrl === 'http://human.local/'
// Auto-upgrade creator archetype
if (isCreatorPubkey(pubkey) && bot.archetype !== "the_creator") {
await db.update(schema.bots).set({ archetype: "the_creator" }).where(eq(schema.bots.id, bot.id))
bot.archetype = "the_creator"
// Auto-upgrade: if creator logs in, ensure archetype + bot mode are correct
if (isCreatorPubkey(pubkey)) {
const fixes: Record<string, string> = {}
if (bot.archetype !== "the_creator") fixes.archetype = "the_creator"
if (bot.webhookUrl === "http://human.local/") fixes.webhookUrl = "http://poll.local/"
if (Object.keys(fixes).length > 0) {
await db.update(schema.bots).set(fixes).where(eq(schema.bots.id, bot.id))
if (fixes.archetype) bot.archetype = "the_creator"
if (fixes.webhookUrl) bot.webhookUrl = "http://poll.local/"
}
}
const isHuman = bot.webhookUrl === 'http://human.local/'
botData = {
id: bot.id,
name: bot.name,
@@ -445,7 +458,7 @@ authRouter.post('/nostr/session', rateLimit(60_000, 10), async (c) => {
await db.insert(schema.bots).values({
id,
name: 'the_creator',
webhookUrl: 'http://human.local/',
webhookUrl: 'http://poll.local/',
avatarSeed: 'the_creator',
archetype: 'the_creator',
secretHash: createHash('sha256').update(secret).digest('hex'),
@@ -468,7 +481,7 @@ authRouter.post('/nostr/session', rateLimit(60_000, 10), async (c) => {
bestStreak: 0,
tier: 0,
isActive: true,
isHuman: true,
isHuman: false,
customization: null,
satsWon: 0,
satsWagered: 0,