Spaces:
Running
Running
Upload main.py
Browse files
main.py
CHANGED
@@ -30,7 +30,6 @@ import io
|
|
30 |
import string
|
31 |
import openai
|
32 |
from io import BytesIO
|
33 |
-
import nest_asyncio
|
34 |
from datetime import datetime as dt
|
35 |
from dotenv import load_dotenv
|
36 |
from bs4 import BeautifulSoup
|
@@ -144,6 +143,14 @@ Please modify your search terms and/or try again later thank you for your unders
|
|
144 |
~ @xtdevs Team
|
145 |
"""
|
146 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
def get_all_api_keys():
|
148 |
user = collection.find({})
|
149 |
api_keys = []
|
@@ -153,6 +160,16 @@ def get_all_api_keys():
|
|
153 |
api_keys.append(api_key)
|
154 |
return api_keys
|
155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
def validate_api_key(api_key: str = Header(...)):
|
157 |
USERS_API_KEYS = get_all_api_keys()
|
158 |
if api_key not in USERS_API_KEYS:
|
@@ -162,6 +179,11 @@ def validate_api_key_only_devs(api_key: str = Header(...)):
|
|
162 |
if api_key not in ONLY_DEVELOPER_API_KEYS:
|
163 |
raise HTTPException(status_code=401, detail="Invalid API key")
|
164 |
|
|
|
|
|
|
|
|
|
|
|
165 |
RAMDOM_STATUS = [
|
166 |
"civilian",
|
167 |
"wanted",
|
@@ -169,9 +191,11 @@ RAMDOM_STATUS = [
|
|
169 |
"rogue_agent",
|
170 |
"innocent",
|
171 |
"fugitive",
|
172 |
-
"covert_operator"
|
|
|
173 |
]
|
174 |
|
|
|
175 |
def remove_sibyl_system_banned(user_id):
|
176 |
update_doc = {
|
177 |
"sibyl_ban": None,
|
@@ -182,6 +206,22 @@ def remove_sibyl_system_banned(user_id):
|
|
182 |
}
|
183 |
return collection.update_one({"user_id": user_id}, {"$unset": update_doc}, upsert=True)
|
184 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
def new_sibyl_system_banned(user_id, name, reason, date_joined):
|
186 |
update_doc = {
|
187 |
"sibyl_ban": name,
|
@@ -208,6 +248,24 @@ def get_sibyl_system_banned(user_id):
|
|
208 |
else:
|
209 |
return None
|
210 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
def get_all_banned():
|
212 |
banned_users = []
|
213 |
|
@@ -438,13 +496,93 @@ def sibyl_system_delete(
|
|
438 |
except Exception as e:
|
439 |
return SuccessResponse(status="False", randydev={"message": "Internal server error."})
|
440 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
441 |
@app.post("/ryuzaki/sibylban", response_model=SuccessResponse, responses={422: {"model": SuccessResponse}})
|
442 |
def sibyl_system_ban(
|
443 |
item: SibylSystemBan,
|
444 |
api_key: None = Depends(validate_api_key)
|
445 |
):
|
446 |
if item.user_id == 1191668125:
|
447 |
-
return
|
448 |
|
449 |
try:
|
450 |
date_joined = str(dt.now())
|
@@ -453,7 +591,6 @@ def sibyl_system_ban(
|
|
453 |
|
454 |
if sibyl_user_id is not None and is_banned:
|
455 |
return SuccessResponse(status="False", randydev={"message": "User is already banned."})
|
456 |
-
|
457 |
new_sibyl_system_banned(item.user_id, sibyl_ban, item.reason, date_joined)
|
458 |
return SuccessResponse(
|
459 |
status="True",
|
@@ -895,19 +1032,16 @@ async def chatgpt_4o(
|
|
895 |
item: ChatgptCustom,
|
896 |
api_key: None = Depends(validate_api_key)
|
897 |
):
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
)
|
909 |
-
except Exception as e:
|
910 |
-
return SuccessResponse(status="False", randydev={"message": str(e)})
|
911 |
|
912 |
@app.post("/ryuzaki/chatgpt-custom", response_model=SuccessResponse, responses={422: {"model": ErrorStatus}})
|
913 |
async def chatgpt_customs(
|
@@ -1578,4 +1712,5 @@ def custom_openapi():
|
|
1578 |
return app.openapi_schema
|
1579 |
|
1580 |
app.openapi = custom_openapi
|
1581 |
-
|
|
|
|
30 |
import string
|
31 |
import openai
|
32 |
from io import BytesIO
|
|
|
33 |
from datetime import datetime as dt
|
34 |
from dotenv import load_dotenv
|
35 |
from bs4 import BeautifulSoup
|
|
|
143 |
~ @xtdevs Team
|
144 |
"""
|
145 |
|
146 |
+
class FedBans(BaseModel):
|
147 |
+
user_id: int
|
148 |
+
hashtag: str
|
149 |
+
reason: str
|
150 |
+
|
151 |
+
class GetsaFedBans(BaseModel):
|
152 |
+
user_id: int
|
153 |
+
|
154 |
def get_all_api_keys():
|
155 |
user = collection.find({})
|
156 |
api_keys = []
|
|
|
160 |
api_keys.append(api_key)
|
161 |
return api_keys
|
162 |
|
163 |
+
def get_all_fedbans_api_keys():
|
164 |
+
user = collection.find({})
|
165 |
+
api_keys = []
|
166 |
+
for x in user:
|
167 |
+
api_key = x.get("fedbans_api_key")
|
168 |
+
if api_key:
|
169 |
+
api_keys.append(api_key)
|
170 |
+
return api_keys
|
171 |
+
|
172 |
+
|
173 |
def validate_api_key(api_key: str = Header(...)):
|
174 |
USERS_API_KEYS = get_all_api_keys()
|
175 |
if api_key not in USERS_API_KEYS:
|
|
|
179 |
if api_key not in ONLY_DEVELOPER_API_KEYS:
|
180 |
raise HTTPException(status_code=401, detail="Invalid API key")
|
181 |
|
182 |
+
def validate_api_key_fedbans(api_key: str = Header(...)):
|
183 |
+
USERS_API_KEYS = get_all_fedbans_api_keys()
|
184 |
+
if api_key not in USERS_API_KEYS:
|
185 |
+
raise HTTPException(status_code=401, detail="Invalid API key")
|
186 |
+
|
187 |
RAMDOM_STATUS = [
|
188 |
"civilian",
|
189 |
"wanted",
|
|
|
191 |
"rogue_agent",
|
192 |
"innocent",
|
193 |
"fugitive",
|
194 |
+
"covert_operator",
|
195 |
+
"spammer",
|
196 |
]
|
197 |
|
198 |
+
|
199 |
def remove_sibyl_system_banned(user_id):
|
200 |
update_doc = {
|
201 |
"sibyl_ban": None,
|
|
|
206 |
}
|
207 |
return collection.update_one({"user_id": user_id}, {"$unset": update_doc}, upsert=True)
|
208 |
|
209 |
+
def new_user_spammers(
|
210 |
+
user_id,
|
211 |
+
hashtag,
|
212 |
+
reason,
|
213 |
+
is_banned: bool,
|
214 |
+
date_joined,
|
215 |
+
):
|
216 |
+
update_doc = {
|
217 |
+
"user_id": user_id,
|
218 |
+
"hashtag": hashtag,
|
219 |
+
"reason": reason,
|
220 |
+
"date_joined": date_joined,
|
221 |
+
"is_banned": is_banned
|
222 |
+
}
|
223 |
+
return collection.update_one({"user_id": user_id}, {"$set": update_doc}, upsert=True)
|
224 |
+
|
225 |
def new_sibyl_system_banned(user_id, name, reason, date_joined):
|
226 |
update_doc = {
|
227 |
"sibyl_ban": name,
|
|
|
248 |
else:
|
249 |
return None
|
250 |
|
251 |
+
def get_fedbans_(user_id):
|
252 |
+
user = collection.find_one({"user_id": user_id})
|
253 |
+
if user:
|
254 |
+
user_id = user.get("user_id")
|
255 |
+
hashtag = user.get("hashtag")
|
256 |
+
reason = user.get("reason")
|
257 |
+
is_banned = user.get("is_banned")
|
258 |
+
date_joined = user.get("date_joined")
|
259 |
+
return [
|
260 |
+
user_id,
|
261 |
+
hashtag,
|
262 |
+
reason,
|
263 |
+
is_banned,
|
264 |
+
date_joined
|
265 |
+
]
|
266 |
+
else:
|
267 |
+
return None
|
268 |
+
|
269 |
def get_all_banned():
|
270 |
banned_users = []
|
271 |
|
|
|
496 |
except Exception as e:
|
497 |
return SuccessResponse(status="False", randydev={"message": "Internal server error."})
|
498 |
|
499 |
+
@app.get("/user/get-fedban", response_model=SuccessResponse, responses={422: {"model": SuccessResponse}})
|
500 |
+
def getfedbans_(payload: GetsaFedBans, api_key: str = Depends(validate_api_key_fedbans)):
|
501 |
+
users_bans = get_fedbans_(payload.user_id)
|
502 |
+
try:
|
503 |
+
if users_bans[3] == True:
|
504 |
+
return SuccessResponse(
|
505 |
+
status="True",
|
506 |
+
randydev={
|
507 |
+
"user_id": users_bans[0],
|
508 |
+
"hashtag": users_bans[1],
|
509 |
+
"reason": users_bans[2],
|
510 |
+
"is_banned": users_bans[3],
|
511 |
+
"date_joined": users_bans[4],
|
512 |
+
"message": f"#GBANNED Successfully banned {payload.user_id} from the fedban list."
|
513 |
+
}
|
514 |
+
)
|
515 |
+
else:
|
516 |
+
return SuccessResponse(
|
517 |
+
status="False",
|
518 |
+
randydev={
|
519 |
+
"user_id": None,
|
520 |
+
"hashtag": None,
|
521 |
+
"reason": None,
|
522 |
+
"is_banned": False,
|
523 |
+
"date_joined": None,
|
524 |
+
"message": f"Not successful"
|
525 |
+
}
|
526 |
+
)
|
527 |
+
except Exception as e:
|
528 |
+
return SuccessResponse(
|
529 |
+
status="False",
|
530 |
+
randydev={
|
531 |
+
"message": "Not successful",
|
532 |
+
"error": str(e)
|
533 |
+
}
|
534 |
+
)
|
535 |
+
|
536 |
+
@app.post("/user/fedban", response_model=SuccessResponse, responses={422: {"model": SuccessResponse}})
|
537 |
+
def fedbans_(payload: FedBans, api_key: str = Depends(validate_api_key_fedbans)):
|
538 |
+
if payload.user_id == 1191668125:
|
539 |
+
return SuccessResponse(status="False", randydev={"message": "Only Developer."})
|
540 |
+
|
541 |
+
date_joined = str(dt.now())
|
542 |
+
if not payload.hashtag.startswith("#"):
|
543 |
+
return SuccessResponse(status="False", randydev={"message": "Invalid hashtag."})
|
544 |
+
|
545 |
+
try:
|
546 |
+
new_user_spammers(
|
547 |
+
user_id=payload.user_id,
|
548 |
+
hashtag=payload.hashtag,
|
549 |
+
reason=payload.reason,
|
550 |
+
is_banned=True,
|
551 |
+
date_joined=date_joined
|
552 |
+
)
|
553 |
+
return SuccessResponse(
|
554 |
+
status="True",
|
555 |
+
randydev={
|
556 |
+
"user_id": payload.user_id,
|
557 |
+
"hashtag": payload.hashtag,
|
558 |
+
"reason": payload.reason,
|
559 |
+
"is_banned": True,
|
560 |
+
"date_joined": date_joined,
|
561 |
+
"message": f"#GBANNED Successfully banned {payload.user_id} from the fedban list."
|
562 |
+
}
|
563 |
+
)
|
564 |
+
except Exception as e:
|
565 |
+
return SuccessResponse(
|
566 |
+
status="False",
|
567 |
+
randydev={
|
568 |
+
"user_id": None,
|
569 |
+
"hashtag": None,
|
570 |
+
"reason": None,
|
571 |
+
"is_banned": False,
|
572 |
+
"date_joined": None,
|
573 |
+
"message": "Not successful",
|
574 |
+
"error": str(e)
|
575 |
+
}
|
576 |
+
)
|
577 |
+
|
578 |
+
|
579 |
@app.post("/ryuzaki/sibylban", response_model=SuccessResponse, responses={422: {"model": SuccessResponse}})
|
580 |
def sibyl_system_ban(
|
581 |
item: SibylSystemBan,
|
582 |
api_key: None = Depends(validate_api_key)
|
583 |
):
|
584 |
if item.user_id == 1191668125:
|
585 |
+
return SuccessResponse(status="False", randydev={"message": "Only Developer."})
|
586 |
|
587 |
try:
|
588 |
date_joined = str(dt.now())
|
|
|
591 |
|
592 |
if sibyl_user_id is not None and is_banned:
|
593 |
return SuccessResponse(status="False", randydev={"message": "User is already banned."})
|
|
|
594 |
new_sibyl_system_banned(item.user_id, sibyl_ban, item.reason, date_joined)
|
595 |
return SuccessResponse(
|
596 |
status="True",
|
|
|
1032 |
item: ChatgptCustom,
|
1033 |
api_key: None = Depends(validate_api_key)
|
1034 |
):
|
1035 |
+
client = Client()
|
1036 |
+
response = client.chat.completions.create(
|
1037 |
+
model="gpt-4o",
|
1038 |
+
messages=[{"role": "user", "content": item.query}],
|
1039 |
+
)
|
1040 |
+
answer = response.choices[0].message.content
|
1041 |
+
return SuccessResponse(
|
1042 |
+
status="True",
|
1043 |
+
randydev={"message": answer}
|
1044 |
+
)
|
|
|
|
|
|
|
1045 |
|
1046 |
@app.post("/ryuzaki/chatgpt-custom", response_model=SuccessResponse, responses={422: {"model": ErrorStatus}})
|
1047 |
async def chatgpt_customs(
|
|
|
1712 |
return app.openapi_schema
|
1713 |
|
1714 |
app.openapi = custom_openapi
|
1715 |
+
|
1716 |
+
app.add_exception_handler(HTTPException, custom_exception_handler)
|