瀏覽代碼

fix: 使用带下划线的优惠码预约

kotoyuuko 2 周之前
父節點
當前提交
02b3919727
共有 2 個文件被更改,包括 9 次插入9 次删除
  1. 8 8
      src/command/handlers/bookEvent.ts
  2. 1 1
      src/command/index.ts

+ 8 - 8
src/command/handlers/bookEvent.ts

@@ -87,7 +87,7 @@ export async function handleBookEvent(ctx: Context, env: Env): Promise<void> {
           }
           keyboard.text(
             `${coupon.code} (${discountText})`,
-            `select_coupon_${eventId}_${slotIndex}_${coupon.code}`
+            `select_coupon:${eventId}:${slotIndex}:${coupon.code}`
           );
           if (index < coupons.length - 1) {
             keyboard.row();
@@ -95,7 +95,7 @@ export async function handleBookEvent(ctx: Context, env: Env): Promise<void> {
         });
         // Add option to book without coupon
         keyboard.row();
-        keyboard.text('不使用优惠码', `select_coupon_${eventId}_${slotIndex}_none`);
+        keyboard.text('不使用优惠码', `select_coupon:${eventId}:${slotIndex}:none`);
 
         await ctx.reply(
           `请选择要使用的优惠码:\n\n` +
@@ -168,16 +168,16 @@ export async function handleCouponSelection(
   action: string
 ): Promise<void> {
   try {
-    // Parse action: select_coupon_{event_id}_{slot_index}_{coupon_code}
-    const parts = action.split('_');
-    if (parts.length < 5 || parts[0] !== 'select' || parts[1] !== 'coupon') {
+    // Parse action: select_coupon:{event_id}:{slot_index}:{coupon_code}
+    const parts = action.split(':');
+    if (parts.length < 4 || parts[0] !== 'select_coupon') {
       await ctx.editMessageText("无效的优惠码选择");
       return;
     }
 
-    const eventId = parts[2];
-    const slotIndex = parseInt(parts[3]);
-    const couponCode = parts[4] === 'none' ? undefined : parts[4];
+    const eventId = parts[1];
+    const slotIndex = parseInt(parts[2]);
+    const couponCode = parts[3] === 'none' ? undefined : parts[3];
 
     // Get user credentials from KV storage
     const telegramUserId = ctx.from?.id.toString();

+ 1 - 1
src/command/index.ts

@@ -97,7 +97,7 @@ export function setupCommands(bot: Bot<ConversationFlavor<Context>>, env: Env) {
   });
 
   // Handle callback queries for coupon selection
-  bot.callbackQuery(/select_coupon_\d+_\d+_\w+/, async (ctx) => {
+  bot.callbackQuery(/select_coupon:\d+:\d+:.+/, async (ctx) => {
     if (ctx.callbackQuery.data) {
       await handleCouponSelection(ctx, env, ctx.callbackQuery.data);
       await ctx.answerCallbackQuery();