diff --git a/commands/megis.js b/commands/megis.js index ec1dcdf..9879b00 100644 --- a/commands/megis.js +++ b/commands/megis.js @@ -40,15 +40,13 @@ const command = { }); } - const timeMs = new Date().getTime(); - const timeoutMs = new Date(user.megis.updatedAt).getTime() + timeout; if (user) { + const timeMs = new Date().getTime(); + const timeoutMs = new Date(user.megis.updatedAt).getTime() + timeout; if (timeMs < timeoutMs) { await client.say( msg.channelName, - `${ - msg.displayName - }, remember kids, only one megis per hour! (on timeout for ${Math.floor( + `${msg.displayName}, Two cans per day... (on timeout for ${Math.floor( Math.abs(timeoutMs - timeMs) / 1000 / 60 )} minutes 🕒 ) ` ); @@ -76,7 +74,7 @@ const command = { await client.say( msg.channelName, - `${msg.displayName}, +${megis}! ${megisTypes[megis]} Total megis: ${updateUser.megis.megis}` + `${msg.displayName}, +${megis} megis! ${megisTypes[megis]} Total megis: ${updateUser.megis.megis}` ); }, }; diff --git a/prisma/migrations/20230208172423_init/migration.sql b/prisma/migrations/20230208172423_init/migration.sql new file mode 100644 index 0000000..ec779fc --- /dev/null +++ b/prisma/migrations/20230208172423_init/migration.sql @@ -0,0 +1,23 @@ +-- CreateTable +CREATE TABLE "User" ( + "id" TEXT NOT NULL PRIMARY KEY, + "userId" TEXT NOT NULL, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL +); + +-- CreateTable +CREATE TABLE "Megis" ( + "id" TEXT NOT NULL PRIMARY KEY, + "userId" TEXT NOT NULL, + "megis" INTEGER NOT NULL, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + CONSTRAINT "Megis_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE +); + +-- CreateIndex +CREATE UNIQUE INDEX "User_userId_key" ON "User"("userId"); + +-- CreateIndex +CREATE UNIQUE INDEX "Megis_userId_key" ON "Megis"("userId"); diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml new file mode 100644 index 0000000..e5e5c47 --- /dev/null +++ b/prisma/migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added in your version-control system (i.e. Git) +provider = "sqlite" \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index b1c5eb1..ec53362 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -21,7 +21,7 @@ model User { model Megis { id String @id @default(uuid()) - User User @relation(fields: [userId], references: [id]) + User User @relation(fields: [userId], references: [id], onDelete: Cascade) userId String @unique megis Int