forked from syntaxbullet/AuroraBot-discord
feat: Implement a generic user timers system with a scheduler to manage cooldowns, effects, and access.
This commit is contained in:
@@ -119,14 +119,16 @@ export const userQuests = pgTable('user_quests', {
|
||||
primaryKey({ columns: [table.userId, table.questId] })
|
||||
]);
|
||||
|
||||
// 8. Cooldowns
|
||||
export const cooldowns = pgTable('cooldowns', {
|
||||
// 8. User Timers (Generic: Cooldowns, Effects, Access)
|
||||
export const userTimers = pgTable('user_timers', {
|
||||
userId: bigint('user_id', { mode: 'bigint' })
|
||||
.references(() => users.id, { onDelete: 'cascade' }).notNull(),
|
||||
actionKey: varchar('action_key', { length: 50 }).notNull(),
|
||||
readyAt: timestamp('ready_at', { withTimezone: true }).notNull(),
|
||||
type: varchar('type', { length: 50 }).notNull(), // 'COOLDOWN', 'EFFECT', 'ACCESS'
|
||||
key: varchar('key', { length: 100 }).notNull(), // 'daily', 'chn_12345', 'xp_boost'
|
||||
expiresAt: timestamp('expires_at', { withTimezone: true }).notNull(),
|
||||
metadata: jsonb('metadata').default({}), // Store channelId, specific buff amounts, etc.
|
||||
}, (table) => [
|
||||
primaryKey({ columns: [table.userId, table.actionKey] })
|
||||
primaryKey({ columns: [table.userId, table.type, table.key] })
|
||||
]);
|
||||
|
||||
// --- RELATIONS ---
|
||||
@@ -143,7 +145,7 @@ export const usersRelations = relations(users, ({ one, many }) => ({
|
||||
inventory: many(inventory),
|
||||
transactions: many(transactions),
|
||||
quests: many(userQuests),
|
||||
cooldowns: many(cooldowns),
|
||||
timers: many(userTimers),
|
||||
}));
|
||||
|
||||
export const itemsRelations = relations(items, ({ many }) => ({
|
||||
@@ -183,9 +185,9 @@ export const userQuestsRelations = relations(userQuests, ({ one }) => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
export const cooldownsRelations = relations(cooldowns, ({ one }) => ({
|
||||
export const userTimersRelations = relations(userTimers, ({ one }) => ({
|
||||
user: one(users, {
|
||||
fields: [cooldowns.userId],
|
||||
fields: [userTimers.userId],
|
||||
references: [users.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user