Update main.py
Browse files
main.py
CHANGED
|
@@ -30,6 +30,7 @@ from app.gs_code import GSCodeApp
|
|
| 30 |
from app.gm_crate import GmailLogic
|
| 31 |
from app.gs_daily import GSDailyApp
|
| 32 |
from app.invite_logic import DiscordInviteLogic
|
|
|
|
| 33 |
|
| 34 |
xs_app = XoSoApp()
|
| 35 |
lq_app = ClLqApp()
|
|
@@ -45,6 +46,7 @@ ios_app = IOSAppFetcher()
|
|
| 45 |
gs_code_app = GSCodeApp()
|
| 46 |
invite_app = DiscordInviteLogic()
|
| 47 |
ht_random_app = HentaiRandomApp()
|
|
|
|
| 48 |
|
| 49 |
API_KEY = os.getenv("API_KEY")
|
| 50 |
START_TIME = time.time()
|
|
@@ -88,13 +90,13 @@ async def lifespan(app: FastAPI):
|
|
| 88 |
await asyncio.gather(
|
| 89 |
invite_app.start(), lq_app.start(), gs_app.start(),
|
| 90 |
gs_code_app.start(), hentai_app.start(), ht_random_app.start(),
|
| 91 |
-
bypass_app.start(), ios_app.start(), xs_app.start(), tik_direct.start(), yt_cdn.start()
|
| 92 |
)
|
| 93 |
yield
|
| 94 |
await asyncio.gather(
|
| 95 |
invite_app.stop(), lq_app.stop(), gs_app.stop(),
|
| 96 |
gs_code_app.stop(), hentai_app.stop(), ht_random_app.stop(),
|
| 97 |
-
bypass_app.stop(), ios_app.stop(), xs_app.stop(), tik_direct.stop(), yt_cdn.stop()
|
| 98 |
)
|
| 99 |
|
| 100 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
@@ -142,45 +144,32 @@ def system_status():
|
|
| 142 |
"total_ram_mb": round(memory.total / 1024 / 1024, 2)
|
| 143 |
}
|
| 144 |
|
| 145 |
-
@app.
|
| 146 |
-
async def
|
| 147 |
-
|
| 148 |
-
if not
|
| 149 |
-
raise HTTPException(status_code=503, detail="Không load được từ điển, thử lại sau")
|
| 150 |
-
|
| 151 |
-
tu_truoc = request.tu_truoc.strip().lower()
|
| 152 |
-
if len(tu_truoc.split()) != 2:
|
| 153 |
-
raise HTTPException(status_code=400, detail="Từ trước phải đúng 2 âm tiết (cách nhau bằng space)")
|
| 154 |
-
|
| 155 |
-
# Lấy âm tiết cuối
|
| 156 |
-
am_cuoi = tu_truoc.split()[-1]
|
| 157 |
-
|
| 158 |
-
used_set = set(t.lower() for t in (request.used or []))
|
| 159 |
-
|
| 160 |
-
candidates = []
|
| 161 |
-
for tu in tudien:
|
| 162 |
-
if tu not in used_set:
|
| 163 |
-
am_dau = tu.split()[0]
|
| 164 |
-
if am_dau == am_cuoi:
|
| 165 |
-
candidates.append(tu)
|
| 166 |
-
|
| 167 |
-
if not candidates:
|
| 168 |
return {
|
| 169 |
"ok": False,
|
| 170 |
-
"
|
| 171 |
}
|
| 172 |
|
| 173 |
-
#
|
| 174 |
-
|
| 175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
|
| 177 |
return {
|
| 178 |
"ok": True,
|
| 179 |
-
"
|
| 180 |
-
"
|
| 181 |
-
"so_tu_con_lai_uoc_tinh": len(candidates) # bonus info
|
| 182 |
}
|
| 183 |
|
|
|
|
| 184 |
@app.get("/api/v1/invites/discord")
|
| 185 |
async def get_new_invite():
|
| 186 |
res = await invite_app.get_invite()
|
|
|
|
| 30 |
from app.gm_crate import GmailLogic
|
| 31 |
from app.gs_daily import GSDailyApp
|
| 32 |
from app.invite_logic import DiscordInviteLogic
|
| 33 |
+
from app.noi_tu import NoiTuApp
|
| 34 |
|
| 35 |
xs_app = XoSoApp()
|
| 36 |
lq_app = ClLqApp()
|
|
|
|
| 46 |
gs_code_app = GSCodeApp()
|
| 47 |
invite_app = DiscordInviteLogic()
|
| 48 |
ht_random_app = HentaiRandomApp()
|
| 49 |
+
noitu_app = NoiTuApp()
|
| 50 |
|
| 51 |
API_KEY = os.getenv("API_KEY")
|
| 52 |
START_TIME = time.time()
|
|
|
|
| 90 |
await asyncio.gather(
|
| 91 |
invite_app.start(), lq_app.start(), gs_app.start(),
|
| 92 |
gs_code_app.start(), hentai_app.start(), ht_random_app.start(),
|
| 93 |
+
bypass_app.start(), ios_app.start(), xs_app.start(), tik_direct.start(), yt_cdn.start(), noitu_app.start()
|
| 94 |
)
|
| 95 |
yield
|
| 96 |
await asyncio.gather(
|
| 97 |
invite_app.stop(), lq_app.stop(), gs_app.stop(),
|
| 98 |
gs_code_app.stop(), hentai_app.stop(), ht_random_app.stop(),
|
| 99 |
+
bypass_app.stop(), ios_app.stop(), xs_app.stop(), tik_direct.stop(), yt_cdn.stop(), noitu_app.stop()
|
| 100 |
)
|
| 101 |
|
| 102 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
| 144 |
"total_ram_mb": round(memory.total / 1024 / 1024, 2)
|
| 145 |
}
|
| 146 |
|
| 147 |
+
@app.get("/api/v1/noitu/2-word")
|
| 148 |
+
async def play_noi_tu(word: str = Query(..., description="Từ để nối (ví dụ: 'học sinh')")):
|
| 149 |
+
# 1. Kiểm tra từ đầu vào có hợp lệ trong từ điển không
|
| 150 |
+
if not noitu_app.is_valid_word(word):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
return {
|
| 152 |
"ok": False,
|
| 153 |
+
"error": "Từ này không có trong từ điển tiếng Việt."
|
| 154 |
}
|
| 155 |
|
| 156 |
+
# 2. Tìm từ nối tiếp
|
| 157 |
+
bot_word = noitu_app.get_next_word(word)
|
| 158 |
+
|
| 159 |
+
if not bot_word:
|
| 160 |
+
return {
|
| 161 |
+
"ok": True,
|
| 162 |
+
"bot_word": None,
|
| 163 |
+
"message": "Bạn thắng rồi! Mình không tìm được từ nào để nối tiếp."
|
| 164 |
+
}
|
| 165 |
|
| 166 |
return {
|
| 167 |
"ok": True,
|
| 168 |
+
"bot_word": bot_word,
|
| 169 |
+
"input_word": word
|
|
|
|
| 170 |
}
|
| 171 |
|
| 172 |
+
|
| 173 |
@app.get("/api/v1/invites/discord")
|
| 174 |
async def get_new_invite():
|
| 175 |
res = await invite_app.get_invite()
|