Update battle_arena.py
Browse files- 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 |
-
|
| 83 |
-
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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=
|
| 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 |
|