Celeskry commited on
Commit
8239c6c
·
verified ·
1 Parent(s): 30dcc56

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +15 -35
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
- tu_truoc: str
57
- used: Optional[List[str]] = None
 
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.get("/api/v1/noitu/2-word")
148
- async def api_noitu(word: str = Query(..., description="Nhập từ 2 tiếng")):
149
- word = word.lower().strip()
150
-
151
- # 1. Kiểm tra định dạng (phải là 2 tiếng)
152
- if len(word.split()) != 2:
153
- return {
154
- "ok": False,
155
- "error": "Vui lòng chỉ nhập từ có 2 tiếng (Ví dụ: 'ân sư')."
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
- return {
176
- "ok": True,
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():