mayafree commited on
Commit
cb4a4eb
ยท
verified ยท
1 Parent(s): 9a50608

Update battle_arena.py

Browse files
Files changed (1) hide show
  1. battle_arena.py +36 -6
battle_arena.py CHANGED
@@ -74,13 +74,17 @@ async def create_battle_room(
74
  battle_type:
75
  - 'opinion': ๋‹ค์ˆ˜๊ฒฐ ํŒ์ • (์ฃผ๊ด€์  ์˜๊ฒฌ, NPC ์ „์šฉ)
76
  - 'prediction': ์‹ค์ œ ๊ฒฐ๊ณผ ํŒ์ • (๊ฐ๊ด€์  ์˜ˆ์ธก, ์‚ฌ์šฉ์ž ์ „์šฉ)
 
 
77
  """
78
  if not title or len(title) < 10:
79
  return False, "โŒ ์ œ๋ชฉ 10์ž ์ด์ƒ", None
80
  if not option_a or not option_b:
81
  return False, "โŒ ์„ ํƒ์ง€ A/B ํ•„์š”", None
82
- if duration_hours < 1 or duration_hours > 24:
83
- return False, "โŒ ๊ธฐํ•œ 1~24์‹œ๊ฐ„", None
 
 
84
 
85
  # ๐Ÿ”’ NPC๋Š” ๋‹ค์ˆ˜๊ฒฐ ์ฃผ์ œ๋งŒ ๊ฐ€๋Šฅ
86
  if is_npc and battle_type != 'opinion':
@@ -132,7 +136,19 @@ async def create_battle_room(
132
  room_id = (await cursor.fetchone())[0]
133
 
134
  type_emoji = '๐Ÿ’ญ' if battle_type == 'opinion' else '๐Ÿ”ฎ'
135
- return True, f"โœ… {type_emoji} ๋ฐฐํ‹€ ๋ฐฉ ์ƒ์„ฑ! (ID: {room_id})", room_id
 
 
 
 
 
 
 
 
 
 
 
 
136
 
137
 
138
  async def place_bet(
@@ -378,13 +394,17 @@ async def get_active_battles(db_path: str, limit: int = 20) -> List[Dict]:
378
  b['a_ratio'] = 0
379
  b['b_ratio'] = 0
380
 
381
- # ๋‚จ์€ ์‹œ๊ฐ„
382
  end_time = datetime.fromisoformat(b['end_time'])
383
  remaining = end_time - datetime.now()
384
 
385
  if remaining.total_seconds() > 0:
386
  if remaining.days > 0:
387
- b['time_left'] = f"{remaining.days}์ผ"
 
 
 
 
388
  elif remaining.total_seconds() > 3600:
389
  b['time_left'] = f"{int(remaining.total_seconds()//3600)}์‹œ๊ฐ„"
390
  else:
@@ -540,6 +560,16 @@ async def npc_create_battle(db_path: str) -> Tuple[bool, str]:
540
  topic = random.choice(available_topics)
541
  title, option_a, option_b = topic
542
 
 
 
 
 
 
 
 
 
 
 
543
  # ๋ฐฐํ‹€๋ฐฉ ์ƒ์„ฑ
544
  success, message, room_id = await create_battle_room(
545
  db_path,
@@ -548,7 +578,7 @@ async def npc_create_battle(db_path: str) -> Tuple[bool, str]:
548
  title,
549
  option_a,
550
  option_b,
551
- duration_hours=random.choice([3, 6, 12, 24]),
552
  battle_type='opinion'
553
  )
554
 
 
74
  battle_type:
75
  - 'opinion': ๋‹ค์ˆ˜๊ฒฐ ํŒ์ • (์ฃผ๊ด€์  ์˜๊ฒฌ, NPC ์ „์šฉ)
76
  - 'prediction': ์‹ค์ œ ๊ฒฐ๊ณผ ํŒ์ • (๊ฐ๊ด€์  ์˜ˆ์ธก, ์‚ฌ์šฉ์ž ์ „์šฉ)
77
+
78
+ duration_hours: 1์‹œ๊ฐ„ ~ 365์ผ(8760์‹œ๊ฐ„)
79
  """
80
  if not title or len(title) < 10:
81
  return False, "โŒ ์ œ๋ชฉ 10์ž ์ด์ƒ", None
82
  if not option_a or not option_b:
83
  return False, "โŒ ์„ ํƒ์ง€ A/B ํ•„์š”", None
84
+
85
+ # ๐Ÿ”ง 1์‹œ๊ฐ„ ~ 365์ผ(8760์‹œ๊ฐ„) ์ œํ•œ
86
+ if duration_hours < 1 or duration_hours > 8760:
87
+ return False, "โŒ ๊ธฐํ•œ 1์‹œ๊ฐ„~365์ผ", None
88
 
89
  # ๐Ÿ”’ NPC๋Š” ๋‹ค์ˆ˜๊ฒฐ ์ฃผ์ œ๋งŒ ๊ฐ€๋Šฅ
90
  if is_npc and battle_type != 'opinion':
 
136
  room_id = (await cursor.fetchone())[0]
137
 
138
  type_emoji = '๐Ÿ’ญ' if battle_type == 'opinion' else '๐Ÿ”ฎ'
139
+
140
+ # ๐Ÿ“… ๊ธฐํ•œ ํ‘œ์‹œ ๊ฐœ์„ 
141
+ if duration_hours >= 24:
142
+ days = duration_hours // 24
143
+ hours = duration_hours % 24
144
+ if hours > 0:
145
+ duration_str = f"{days}์ผ {hours}์‹œ๊ฐ„"
146
+ else:
147
+ duration_str = f"{days}์ผ"
148
+ else:
149
+ duration_str = f"{duration_hours}์‹œ๊ฐ„"
150
+
151
+ return True, f"โœ… {type_emoji} ๋ฐฐํ‹€ ๋ฐฉ ์ƒ์„ฑ! (ID: {room_id}, ๊ธฐํ•œ: {duration_str})", room_id
152
 
153
 
154
  async def place_bet(
 
394
  b['a_ratio'] = 0
395
  b['b_ratio'] = 0
396
 
397
+ # ๐Ÿ“… ๋‚จ์€ ์‹œ๊ฐ„ ๊ฐœ์„  (์ผ/์‹œ๊ฐ„/๋ถ„ ํ‘œ์‹œ)
398
  end_time = datetime.fromisoformat(b['end_time'])
399
  remaining = end_time - datetime.now()
400
 
401
  if remaining.total_seconds() > 0:
402
  if remaining.days > 0:
403
+ hours = int(remaining.seconds // 3600)
404
+ if hours > 0:
405
+ b['time_left'] = f"{remaining.days}์ผ {hours}์‹œ๊ฐ„"
406
+ else:
407
+ b['time_left'] = f"{remaining.days}์ผ"
408
  elif remaining.total_seconds() > 3600:
409
  b['time_left'] = f"{int(remaining.total_seconds()//3600)}์‹œ๊ฐ„"
410
  else:
 
560
  topic = random.choice(available_topics)
561
  title, option_a, option_b = topic
562
 
563
+ # ๐ŸŽฒ ๋‹ค์–‘ํ•œ ๊ธฐ๊ฐ„ ์„ค์ • (1์ผ~30์ผ)
564
+ duration_hours = random.choice([
565
+ 24, # 1์ผ
566
+ 48, # 2์ผ
567
+ 72, # 3์ผ
568
+ 24*7, # 1์ฃผ์ผ
569
+ 24*14, # 2์ฃผ์ผ
570
+ 24*30, # 1๊ฐœ์›”
571
+ ])
572
+
573
  # ๋ฐฐํ‹€๋ฐฉ ์ƒ์„ฑ
574
  success, message, room_id = await create_battle_room(
575
  db_path,
 
578
  title,
579
  option_a,
580
  option_b,
581
+ duration_hours=duration_hours,
582
  battle_type='opinion'
583
  )
584