Update main.py
Browse files
main.py
CHANGED
|
@@ -53,8 +53,9 @@ START_TIME = time.time()
|
|
| 53 |
order_cache = TTLCache(maxsize=100, ttl=86400)
|
| 54 |
|
| 55 |
class NoiTuRequest(BaseModel):
|
| 56 |
-
|
| 57 |
-
|
|
|
|
| 58 |
|
| 59 |
class ProductItem(BaseModel):
|
| 60 |
name: str
|
|
@@ -144,40 +145,19 @@ def system_status():
|
|
| 144 |
"total_ram_mb": round(memory.total / 1024 / 1024, 2)
|
| 145 |
}
|
| 146 |
|
| 147 |
-
@app.
|
| 148 |
-
async def
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
# 2. Kiểm tra từ có trong từ điển không
|
| 159 |
-
if not noitu_app.is_valid_word(word):
|
| 160 |
-
return {
|
| 161 |
-
"ok": False,
|
| 162 |
-
"error": f"Từ '{word}' không có trong hệ thống từ điển."
|
| 163 |
-
}
|
| 164 |
-
|
| 165 |
-
# 3. Bot tìm từ nối
|
| 166 |
-
bot_word = noitu_app.get_next_word(word)
|
| 167 |
-
|
| 168 |
-
if not bot_word:
|
| 169 |
-
return {
|
| 170 |
-
"ok": True,
|
| 171 |
-
"bot_word": None,
|
| 172 |
-
"message": "Bạn thắng! Bot không tìm được từ nối tiếp."
|
| 173 |
-
}
|
| 174 |
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
"input": word,
|
| 178 |
-
"bot_word": bot_word
|
| 179 |
-
}
|
| 180 |
-
|
| 181 |
|
| 182 |
@app.get("/api/v1/invites/discord")
|
| 183 |
async def get_new_invite():
|
|
|
|
| 53 |
order_cache = TTLCache(maxsize=100, ttl=86400)
|
| 54 |
|
| 55 |
class NoiTuRequest(BaseModel):
|
| 56 |
+
before: str
|
| 57 |
+
answer: str
|
| 58 |
+
list: List[str]
|
| 59 |
|
| 60 |
class ProductItem(BaseModel):
|
| 61 |
name: str
|
|
|
|
| 145 |
"total_ram_mb": round(memory.total / 1024 / 1024, 2)
|
| 146 |
}
|
| 147 |
|
| 148 |
+
@app.post("/api/v1/noitu/check")
|
| 149 |
+
async def api_noitu_check(
|
| 150 |
+
data: NoiTuRequest,
|
| 151 |
+
apikey: Optional[str] = Query(None),
|
| 152 |
+
x_api_key: Optional[str] = Header(None, alias="X-API-Key")
|
| 153 |
+
):
|
| 154 |
+
# Kiểm tra API KEY
|
| 155 |
+
key = x_api_key or apikey
|
| 156 |
+
if not API_KEY or key != API_KEY:
|
| 157 |
+
raise HTTPException(status_code=403, detail="API key invalid. Go touch grass")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
|
| 159 |
+
# Trả về kết quả check từ trọng tài
|
| 160 |
+
return noitu_app.validate_turn(data.before, data.answer, data.list)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
|
| 162 |
@app.get("/api/v1/invites/discord")
|
| 163 |
async def get_new_invite():
|