Skip to content
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

Merged
merged 21 commits into from
Aug 20, 2024
Merged

Bot #1113

merged 21 commits into from
Aug 20, 2024

Conversation

ponderingdemocritus
Copy link
Contributor

@ponderingdemocritus ponderingdemocritus commented Jul 12, 2024

  • adds new app

closes #982

Copy link

vercel bot commented Jul 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
eternum ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 20, 2024 1:54pm

Copy link
Contributor

@mentatbot mentatbot bot left a 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.

.post("/users/create", zValidator("json", UserQuerySchema), async (c) => {
const data = c.req.valid("json");

if (!data.address) {
Copy link
Contributor

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.

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);
Copy link
Contributor

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.


// Insert new user if not exists
const result = await db
.insert(users)
Copy link
Contributor

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.

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();
Copy link
Contributor

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.

await interaction.deferReply();

try {
await client.users.users.create.$post({ json: { address, discord: discordId, telegram } });
Copy link
Contributor

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.


export const users = pgTable("users", {
id: serial("id").primaryKey(),
address: text("address"),
Copy link
Contributor

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.

@ponderingdemocritus ponderingdemocritus merged commit 1f73e89 into main Aug 20, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bot] New app - Discussion
1 participant