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:
co-authored by
Claude Opus 4.6
parent
42b1642932
commit
8076d860c7
+29
-16
@@ -53,14 +53,14 @@ authRouter.post('/login', rateLimit(60_000, 10), async (c) => {
|
|||||||
}).from(schema.bots).where(eq(schema.bots.publicKey, pubkey)).limit(1)
|
}).from(schema.bots).where(eq(schema.bots.publicKey, pubkey)).limit(1)
|
||||||
|
|
||||||
if (rows.length === 0) {
|
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)) {
|
if (isCreatorPubkey(pubkey)) {
|
||||||
const id = nanoid(12)
|
const id = nanoid(12)
|
||||||
const secret = randomBytes(32).toString('hex')
|
const secret = randomBytes(32).toString('hex')
|
||||||
await db.insert(schema.bots).values({
|
await db.insert(schema.bots).values({
|
||||||
id,
|
id,
|
||||||
name: 'the_creator',
|
name: 'the_creator',
|
||||||
webhookUrl: 'http://human.local/',
|
webhookUrl: 'http://poll.local/',
|
||||||
avatarSeed: 'the_creator',
|
avatarSeed: 'the_creator',
|
||||||
archetype: 'the_creator',
|
archetype: 'the_creator',
|
||||||
secretHash: createHash('sha256').update(secret).digest('hex'),
|
secretHash: createHash('sha256').update(secret).digest('hex'),
|
||||||
@@ -84,7 +84,7 @@ authRouter.post('/login', rateLimit(60_000, 10), async (c) => {
|
|||||||
bestStreak: 0,
|
bestStreak: 0,
|
||||||
tier: 0,
|
tier: 0,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
isHuman: true,
|
isHuman: false,
|
||||||
customization: null,
|
customization: null,
|
||||||
satsWon: 0,
|
satsWon: 0,
|
||||||
satsWagered: 0,
|
satsWagered: 0,
|
||||||
@@ -96,13 +96,20 @@ authRouter.post('/login', rateLimit(60_000, 10), async (c) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const bot = rows[0]
|
const bot = rows[0]
|
||||||
const isHuman = bot.webhookUrl === 'http://human.local/'
|
|
||||||
|
|
||||||
// Auto-upgrade: if creator logs in, ensure archetype is always the_creator
|
// Auto-upgrade: if creator logs in, ensure archetype + bot mode are correct
|
||||||
if (isCreatorPubkey(pubkey) && bot.archetype !== "the_creator") {
|
if (isCreatorPubkey(pubkey)) {
|
||||||
await db.update(schema.bots).set({ archetype: "the_creator" }).where(eq(schema.bots.id, bot.id))
|
const fixes: Record<string, string> = {}
|
||||||
bot.archetype = "the_creator"
|
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({
|
return c.json({
|
||||||
exists: true,
|
exists: true,
|
||||||
@@ -411,13 +418,19 @@ authRouter.post('/nostr/session', rateLimit(60_000, 10), async (c) => {
|
|||||||
if (rows.length > 0) {
|
if (rows.length > 0) {
|
||||||
const bot = rows[0]
|
const bot = rows[0]
|
||||||
botId = bot.id
|
botId = bot.id
|
||||||
const isHuman = bot.webhookUrl === 'http://human.local/'
|
// Auto-upgrade: if creator logs in, ensure archetype + bot mode are correct
|
||||||
|
if (isCreatorPubkey(pubkey)) {
|
||||||
// Auto-upgrade creator archetype
|
const fixes: Record<string, string> = {}
|
||||||
if (isCreatorPubkey(pubkey) && bot.archetype !== "the_creator") {
|
if (bot.archetype !== "the_creator") fixes.archetype = "the_creator"
|
||||||
await db.update(schema.bots).set({ archetype: "the_creator" }).where(eq(schema.bots.id, bot.id))
|
if (bot.webhookUrl === "http://human.local/") fixes.webhookUrl = "http://poll.local/"
|
||||||
bot.archetype = "the_creator"
|
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 = {
|
botData = {
|
||||||
id: bot.id,
|
id: bot.id,
|
||||||
@@ -445,7 +458,7 @@ authRouter.post('/nostr/session', rateLimit(60_000, 10), async (c) => {
|
|||||||
await db.insert(schema.bots).values({
|
await db.insert(schema.bots).values({
|
||||||
id,
|
id,
|
||||||
name: 'the_creator',
|
name: 'the_creator',
|
||||||
webhookUrl: 'http://human.local/',
|
webhookUrl: 'http://poll.local/',
|
||||||
avatarSeed: 'the_creator',
|
avatarSeed: 'the_creator',
|
||||||
archetype: 'the_creator',
|
archetype: 'the_creator',
|
||||||
secretHash: createHash('sha256').update(secret).digest('hex'),
|
secretHash: createHash('sha256').update(secret).digest('hex'),
|
||||||
@@ -468,7 +481,7 @@ authRouter.post('/nostr/session', rateLimit(60_000, 10), async (c) => {
|
|||||||
bestStreak: 0,
|
bestStreak: 0,
|
||||||
tier: 0,
|
tier: 0,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
isHuman: true,
|
isHuman: false,
|
||||||
customization: null,
|
customization: null,
|
||||||
satsWon: 0,
|
satsWon: 0,
|
||||||
satsWagered: 0,
|
satsWagered: 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user