Skip to content

Commit

Permalink
[from now] 2024/03/01 07:56:38
Browse files Browse the repository at this point in the history
diff --git a/package.json b/package.json
index 314a7bc..b2819a2 100644
--- a/package.json
+++ b/package.json
@@ -7,6 +7,7 @@
     "up": "drizzle-kit up:sqlite --schema=src/schema.ts"
   },
   "dependencies": {
+    "dayjs": "^1.11.10",
     "discord-api-types": "^0.37.70",
     "discord-interactions": "^3.4.0",
     "drizzle-orm": "^0.29.4",
diff --git a/src/index.ts b/src/index.ts
index 1aec815..b05c807 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -8,6 +8,7 @@ import checkinModal from "./interactions/modalSubmits/checkinModal";
 import { verifyDiscordInteraction } from "./middleware/verifyDiscordInteraction";
 import { CheckinsRepository } from "./repositories/checkinsRepository";
 import { UsersRepository } from "./repositories/usersRepository";
+import { errorResponse } from "./responses/errorResponse";

 type Bindings = {
   DB: D1Database;
@@ -18,28 +19,34 @@ const app = new Hono<{ Bindings: Bindings }>();
 app.post("/interaction", verifyDiscordInteraction, async (c) => {
   const body = await c.req.json();

-  switch (body.type) {
-    case InteractionType.APPLICATION_COMMAND:
-      return c.json(
-        await handleApplicationCommands({
-          intentObj: body,
-          userRepository: new UsersRepository(c.env.DB),
-          checkinsRepository: new CheckinsRepository(c.env.DB),
-          commands: [checkinCommand, mokumokuStartCommand],
-        }),
-      );
-    case InteractionType.MODAL_SUBMIT:
-      return c.json(
-        await handleModalSubmits({
-          intentObj: body,
-          userRepository: new UsersRepository(c.env.DB),
-          checkinsRepository: new CheckinsRepository(c.env.DB),
-          modals: [checkinModal],
-        }),
-      );
-    default:
-      throw new Error("Invalid interaction");
+  try {
+    switch (body.type) {
+      case InteractionType.APPLICATION_COMMAND:
+        return c.json(
+          await handleApplicationCommands({
+            intentObj: body,
+            userRepository: new UsersRepository(c.env.DB),
+            checkinsRepository: new CheckinsRepository(c.env.DB),
+            commands: [checkinCommand, mokumokuStartCommand],
+          }),
+        );
+      case InteractionType.MODAL_SUBMIT:
+        return c.json(
+          await handleModalSubmits({
+            intentObj: body,
+            userRepository: new UsersRepository(c.env.DB),
+            checkinsRepository: new CheckinsRepository(c.env.DB),
+            modals: [checkinModal],
+          }),
+        );
+      default:
+        throw new Error("Invalid interaction");
+    }
+  } catch (e) {
+    console.error(e);
+    return c.json(errorResponse(e instanceof Error ? e.message : "Unknown error"));
   }
 });

+
 export default app;
diff --git a/src/interactions/applicationCommands/mokumokuStart.ts b/src/interactions/applicationCommands/mokumokuStart.ts
index 433a218..84726bc 100644
--- a/src/interactions/applicationCommands/mokumokuStart.ts
+++ b/src/interactions/applicationCommands/mokumokuStart.ts
@@ -1,8 +1,15 @@
+import dayjs from "dayjs";
+import tz from "dayjs/plugin/timezone";
+import utc from "dayjs/plugin/utc";
 import { MOKUMOKU_START_COMMAND_NAME } from "../../constants";
 import { buildMokumokuCommandResponse as buildMokumokuStartCommandResponse } from "../../responses/mokumokuStartCommandResponse";

+dayjs.extend(utc)
+dayjs.extend(tz);
+
 const handler = async () => {
-  return buildMokumokuStartCommandResponse({ date: "2024/02/29" });
+  const today = dayjs.tz("Asia/Tokyo").format("YYYY/MM/DD");
+  return buildMokumokuStartCommandResponse({ date: today });
   /*
   その他メモ
   * スタートしたという事実をDBに保存する?
diff --git a/src/responses/mokumokuStartCommandResponse.ts b/src/responses/mokumokuStartCommandResponse.ts
index 99a161f..92a90df 100644
--- a/src/responses/mokumokuStartCommandResponse.ts
+++ b/src/responses/mokumokuStartCommandResponse.ts
@@ -24,9 +24,9 @@ export const buildMokumokuCommandResponse = ({
                 "**`13:00〜13:15`** チェックイン(自己紹介・やること共有)\n**`13:15〜15:00`** もくもく作業\n**`15:00〜15:30`** LT or テックトーク\n**`15:30〜17:50`** もくもく作業\n**`17:50〜18:00`** やったこと共有 & 片付け\n**`18:00〜`**           懇親会(希望者のみ)\n",
             },
             {
-              name: "📝 `/checkin` コマンド",
+              name: "📝 checkinコマンド",
               value:
-                "投稿欄に `/chekcin` とコマンドを入力してEnterを押すと、モーダルが表示されます。そのモーダルに自己紹介と今日のやることを入力して送信してください。",
+                "メッセージ欄に`/chekcin` と入力してEnterを押すと、モーダルが表示されます。そのモーダルに自己紹介と今日やることを入力して送信すると、チェックインが投稿されます。",
             },
           ],
         },
  • Loading branch information
kawamataryo committed Feb 29, 2024
1 parent f512515 commit ef324d2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 24 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"up": "drizzle-kit up:sqlite --schema=src/schema.ts"
},
"dependencies": {
"dayjs": "^1.11.10",
"discord-api-types": "^0.37.70",
"discord-interactions": "^3.4.0",
"drizzle-orm": "^0.29.4",
Expand Down
50 changes: 29 additions & 21 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import checkinModal from "./interactions/modalSubmits/checkinModal";
import { verifyDiscordInteraction } from "./middleware/verifyDiscordInteraction";
import { CheckinsRepository } from "./repositories/checkinsRepository";
import { UsersRepository } from "./repositories/usersRepository";
import { errorResponse } from "./responses/errorResponse";

type Bindings = {
DB: D1Database;
Expand All @@ -18,27 +19,34 @@ const app = new Hono<{ Bindings: Bindings }>();
app.post("/interaction", verifyDiscordInteraction, async (c) => {
const body = await c.req.json();

switch (body.type) {
case InteractionType.APPLICATION_COMMAND:
return c.json(
await handleApplicationCommands({
intentObj: body,
userRepository: new UsersRepository(c.env.DB),
checkinsRepository: new CheckinsRepository(c.env.DB),
commands: [checkinCommand, mokumokuStartCommand],
}),
);
case InteractionType.MODAL_SUBMIT:
return c.json(
await handleModalSubmits({
intentObj: body,
userRepository: new UsersRepository(c.env.DB),
checkinsRepository: new CheckinsRepository(c.env.DB),
modals: [checkinModal],
}),
);
default:
throw new Error("Invalid interaction");
try {
switch (body.type) {
case InteractionType.APPLICATION_COMMAND:
return c.json(
await handleApplicationCommands({
intentObj: body,
userRepository: new UsersRepository(c.env.DB),
checkinsRepository: new CheckinsRepository(c.env.DB),
commands: [checkinCommand, mokumokuStartCommand],
}),
);
case InteractionType.MODAL_SUBMIT:
return c.json(
await handleModalSubmits({
intentObj: body,
userRepository: new UsersRepository(c.env.DB),
checkinsRepository: new CheckinsRepository(c.env.DB),
modals: [checkinModal],
}),
);
default:
throw new Error("Invalid interaction");
}
} catch (e) {
console.error(e);
return c.json(
errorResponse(e instanceof Error ? e.message : "Unknown error"),
);
}
});

Expand Down
9 changes: 8 additions & 1 deletion src/interactions/applicationCommands/mokumokuStart.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import dayjs from "dayjs";
import tz from "dayjs/plugin/timezone";
import utc from "dayjs/plugin/utc";
import { MOKUMOKU_START_COMMAND_NAME } from "../../constants";
import { buildMokumokuCommandResponse as buildMokumokuStartCommandResponse } from "../../responses/mokumokuStartCommandResponse";

dayjs.extend(utc);
dayjs.extend(tz);

const handler = async () => {
return buildMokumokuStartCommandResponse({ date: "2024/02/29" });
const today = dayjs.tz("Asia/Tokyo").format("YYYY/MM/DD");
return buildMokumokuStartCommandResponse({ date: today });
/*
その他メモ
* スタートしたという事実をDBに保存する?
Expand Down
4 changes: 2 additions & 2 deletions src/responses/mokumokuStartCommandResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export const buildMokumokuCommandResponse = ({
"**`13:00〜13:15`** チェックイン(自己紹介・やること共有)\n**`13:15〜15:00`** もくもく作業\n**`15:00〜15:30`** LT or テックトーク\n**`15:30〜17:50`** もくもく作業\n**`17:50〜18:00`** やったこと共有 & 片付け\n**`18:00〜`** 懇親会(希望者のみ)\n",
},
{
name: "📝 `/checkin` コマンド",
name: "📝 checkinコマンド",
value:
"投稿欄に `/chekcin` とコマンドを入力してEnterを押すと、モーダルが表示されます。そのモーダルに自己紹介と今日のやることを入力して送信してください。",
"メッセージ欄に`/chekcin` と入力してEnterを押すと、モーダルが表示されます。そのモーダルに自己紹介と今日やることを入力して送信すると、チェックインが投稿されます。",
},
],
},
Expand Down

0 comments on commit ef324d2

Please sign in to comment.