-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bot #1113
Bot #1113
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pull request introduces a new bot application with user management functionality. It includes database schema setup, API routes for CRUD operations on users, and Discord bot integration. The code is generally well-structured, but there are a few areas where error handling and data validation could be improved. Additionally, some database operations could benefit from using transactions for better data integrity. Overall, it's a solid foundation for the bot application, but with room for some refinements in robustness and user experience.
Thanks for using MentatBot. Reply with feedback or to ask MentatBot to review other parts of the PR. Please give feedback with emoji reacts.
bot/src/routes/users.ts
Outdated
.post("/users/create", zValidator("json", UserQuerySchema), async (c) => { | ||
const data = c.req.valid("json"); | ||
|
||
if (!data.address) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding input validation for the address field to ensure it's a valid Ethereum address format.
bot/src/routes/users.ts
Outdated
const db = drizzle(sql); | ||
|
||
// Check if the user already exists | ||
const existingUser = await db.select().from(users).where(eq(users.address, data.address)).limit(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good practice to use a transaction here to ensure atomicity of the check and insert operations.
bot/src/routes/users.ts
Outdated
|
||
// Insert new user if not exists | ||
const result = await db | ||
.insert(users) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider returning more detailed user information in the response, not just the created_at timestamp.
bot/src/routes/users.ts
Outdated
const sql = neon(process.env.DATABASE_URL!); | ||
const db = drizzle(sql); | ||
|
||
const result = await db.update(users).set(data).where(eq(users.address, address)).returning(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be helpful to return a more specific error message if the update fails for reasons other than the user not being found.
bot/src/commands/createUser.ts
Outdated
await interaction.deferReply(); | ||
|
||
try { | ||
await client.users.users.create.$post({ json: { address, discord: discordId, telegram } }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding error handling to catch specific types of errors (e.g., network errors, validation errors) and provide more informative error messages to the user.
bot/src/db/schema.ts
Outdated
|
||
export const users = pgTable("users", { | ||
id: serial("id").primaryKey(), | ||
address: text("address"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider making the address field unique to prevent duplicate entries for the same wallet address.
closes #982