randydev commited on
Commit
501c814
1 Parent(s): d0bbe79

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +104 -10
main.py CHANGED
@@ -58,18 +58,20 @@ from fastapi.staticfiles import StaticFiles
58
  from fastapi.templating import Jinja2Templates
59
  from fastapi.responses import FileResponse
60
 
 
 
61
  from RyuzakiLib.hackertools.chatgpt import RendyDevChat
62
  from RyuzakiLib.hackertools.openai import OpenAiToken
63
  from RyuzakiLib.mental import BadWordsList
64
 
65
  import logging
66
- import database as db
67
  import functions as code
68
 
69
  logging.basicConfig(level=logging.ERROR)
70
 
71
  # I DON'T KNOW LIKE THIS HACKER
72
  load_dotenv()
 
73
  REVERSE_IMAGE_API = os.environ["REVERSE_IMAGE_API"]
74
  OCR_API_KEY = os.environ["OCR_API_KEY"]
75
  ONLY_DEVELOPER_API_KEYS = os.environ["ONLY_DEVELOPER_API_KEYS"]
@@ -82,6 +84,10 @@ SOURCE_TIKTOK_WTF_URL = os.environ["SOURCE_TIKTOK_WTF_URL"]
82
  SOURCE_TIKTOK_TECH_URL = os.environ["SOURCE_TIKTOK_TECH_URL"]
83
  DEVELOPER_ID = os.environ["DEVELOPER_ID"]
84
 
 
 
 
 
85
  description = """
86
  - Ryuzaki Library: [Library Here](https://github.com/TeamKillerX/RyuzakiLib)
87
 
@@ -110,6 +116,94 @@ def validate_api_key_only_devs(api_key: str = Header(...)):
110
  if api_key not in ONLY_DEVELOPER_API_KEYS:
111
  raise HTTPException(status_code=401, detail="Invalid API key")
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  @app.post("/ryuzaki/profile-clone")
114
  def profile_clone(
115
  user_id: int,
@@ -122,11 +216,11 @@ def profile_clone(
122
  if user_id != int(DEVELOPER_ID):
123
  return {"status": "false", "message": "Only Developer"}
124
 
125
- first_name, _, profile_id, _ = db.get_profile_clone(user_id)
126
  if first_name and profile_id:
127
  return {"status": "false", "message": "User is already profile"}
128
  try:
129
- db.new_profile_clone(
130
  user_id=user_id,
131
  first_name=first_name,
132
  last_name=last_name,
@@ -151,7 +245,7 @@ def get_profile_clone(
151
  user_id: int = Query(..., description="User ID in query parameter"),
152
  api_key: None = Depends(validate_api_key)
153
  ):
154
- first_name, last_name, profile_id, bio = db.get_profile_clone(user_id)
155
  if last_name is None:
156
  last_name_str = ""
157
  else:
@@ -176,7 +270,7 @@ def get_profile_clone(
176
 
177
  @app.get("/ryuzaki/getbanlist")
178
  def sibyl_get_all_banlist():
179
- banned_users = db.get_all_banned()
180
  return {
181
  "status": "True",
182
  "randydev": {
@@ -199,10 +293,10 @@ def sibyl_system_delete(
199
  api_key: None = Depends(validate_api_key_only_devs)
200
  ):
201
  try:
202
- _, _, _, _, sibyl_user_id = db.get_sibyl_system_banned(user_id)
203
 
204
  if sibyl_user_id:
205
- db.remove_sibyl_system_banned(user_id)
206
  return {"status": "true", "message": f"Successfully removed {user_id} from the Sibyl ban list."}
207
  else:
208
  return {"status": "false", "message": "Not found user"}
@@ -220,13 +314,13 @@ def sibyl_system_ban(
220
 
221
  try:
222
  date_joined = str(dt.now())
223
- sibyl_ban = random.choice(db.RAMDOM_STATUS)
224
  _, _, is_banned, _, sibyl_user_id = get_sibyl_system_banned(user_id)
225
 
226
  if sibyl_user_id and is_banned:
227
  return {"status": "false", "message": "User is already banned"}
228
 
229
- db.new_sibyl_system_banned(user_id, sibyl_ban, reason, date_joined)
230
 
231
  return {
232
  "status": "true",
@@ -247,7 +341,7 @@ def sibyl_system(
247
  user_id: int = Query(..., description="User ID in query parameter"),
248
  api_key: None = Depends(validate_api_key)
249
  ):
250
- sibyl_name, reason, is_banned, date_joined, sibyl_user_id = db.get_sibyl_system_banned(user_id)
251
  if sibyl_name and reason and is_banned and date_joined and sibyl_user_id:
252
  return {
253
  "status": "true",
 
58
  from fastapi.templating import Jinja2Templates
59
  from fastapi.responses import FileResponse
60
 
61
+ from pymongo import MongoClient
62
+
63
  from RyuzakiLib.hackertools.chatgpt import RendyDevChat
64
  from RyuzakiLib.hackertools.openai import OpenAiToken
65
  from RyuzakiLib.mental import BadWordsList
66
 
67
  import logging
 
68
  import functions as code
69
 
70
  logging.basicConfig(level=logging.ERROR)
71
 
72
  # I DON'T KNOW LIKE THIS HACKER
73
  load_dotenv()
74
+ MONGO_URL = os.environ["MONGO_URL"]
75
  REVERSE_IMAGE_API = os.environ["REVERSE_IMAGE_API"]
76
  OCR_API_KEY = os.environ["OCR_API_KEY"]
77
  ONLY_DEVELOPER_API_KEYS = os.environ["ONLY_DEVELOPER_API_KEYS"]
 
84
  SOURCE_TIKTOK_TECH_URL = os.environ["SOURCE_TIKTOK_TECH_URL"]
85
  DEVELOPER_ID = os.environ["DEVELOPER_ID"]
86
 
87
+ client_mongo = MongoClient(MONGO_URL)
88
+ db = client_mongo["tiktokbot"]
89
+ collection = db["users"]
90
+
91
  description = """
92
  - Ryuzaki Library: [Library Here](https://github.com/TeamKillerX/RyuzakiLib)
93
 
 
116
  if api_key not in ONLY_DEVELOPER_API_KEYS:
117
  raise HTTPException(status_code=401, detail="Invalid API key")
118
 
119
+ RAMDOM_STATUS = [
120
+ "civilian",
121
+ "wanted",
122
+ "undercover",
123
+ "rogue_agent",
124
+ "innocent",
125
+ "fugitive",
126
+ "covert_operator"
127
+ ]
128
+
129
+ def remove_sibyl_system_banned(user_id):
130
+ update_doc = {
131
+ "sibyl_ban": None,
132
+ "reason_sibyl": None,
133
+ "is_banned_sibly": None,
134
+ "date_joined_sib": None,
135
+ "sibyl_userid": None
136
+ }
137
+ return collection.update_one({"user_id": user_id}, {"$unset": update_doc}, upsert=True)
138
+
139
+ def new_sibyl_system_banned(user_id, name, reason, date_joined):
140
+ update_doc = {
141
+ "sibyl_ban": name,
142
+ "reason_sibyl": reason,
143
+ "is_banned_sibly": True,
144
+ "date_joined_sib": date_joined,
145
+ "sibyl_userid": user_id
146
+ }
147
+ return collection.update_one({"user_id": user_id}, {"$set": update_doc}, upsert=True)
148
+
149
+ def get_sibyl_system_banned(user_id):
150
+ user = collection.find_one({"user_id": user_id})
151
+ if user:
152
+ sibyl_name = user.get("sibyl_ban")
153
+ reason = user.get("reason_sibyl")
154
+ is_banned = user.get("is_banned_sibly")
155
+ date_joined = user.get("date_joined_sib")
156
+ sibyl_user_id = user.get("sibyl_userid")
157
+ return sibyl_name, reason, is_banned, date_joined, sibyl_user_id
158
+ else:
159
+ return None
160
+
161
+ def get_all_banned():
162
+ banned_users = []
163
+
164
+ users = collection.find({})
165
+
166
+ for user_id in users:
167
+ reason = user_id.get("reason_sibyl")
168
+ user_id = user_id.get("sibyl_userid")
169
+ banned_users.append({"user_id": user_id, "reason": reason})
170
+ return banned_users
171
+
172
+ def get_all_api_keys():
173
+ user = collection.find({})
174
+ api_keys = []
175
+ for x in user:
176
+ api_key = x.get("ryuzaki_api_key")
177
+ if api_key:
178
+ api_keys.append(api_key)
179
+ return api_keys
180
+
181
+ def new_profile_clone(
182
+ user_id,
183
+ first_name,
184
+ last_name=None,
185
+ profile_id=None,
186
+ bio=None
187
+ ):
188
+ update_doc = {
189
+ "first_name_2": first_name,
190
+ "last_name_2": last_name,
191
+ "profile_id_2": profile_id,
192
+ "bio_2": bio
193
+ }
194
+ collection.update_one({"user_id": user_id}, {"$set": update_doc}, upsert=True)
195
+
196
+ def get_profile_clone(user_id):
197
+ user = collection.find_one({"user_id": user_id})
198
+ if user:
199
+ first_name = user.get("first_name_2")
200
+ last_name = user.get("last_name_2")
201
+ profile_id = user.get("profile_id_2")
202
+ bio = user.get("bio_2")
203
+ return first_name, last_name, profile_id, bio
204
+ else:
205
+ return None, None, None, None
206
+
207
  @app.post("/ryuzaki/profile-clone")
208
  def profile_clone(
209
  user_id: int,
 
216
  if user_id != int(DEVELOPER_ID):
217
  return {"status": "false", "message": "Only Developer"}
218
 
219
+ first_name, _, profile_id, _ = get_profile_clone(user_id)
220
  if first_name and profile_id:
221
  return {"status": "false", "message": "User is already profile"}
222
  try:
223
+ new_profile_clone(
224
  user_id=user_id,
225
  first_name=first_name,
226
  last_name=last_name,
 
245
  user_id: int = Query(..., description="User ID in query parameter"),
246
  api_key: None = Depends(validate_api_key)
247
  ):
248
+ first_name, last_name, profile_id, bio = get_profile_clone(user_id)
249
  if last_name is None:
250
  last_name_str = ""
251
  else:
 
270
 
271
  @app.get("/ryuzaki/getbanlist")
272
  def sibyl_get_all_banlist():
273
+ banned_users = get_all_banned()
274
  return {
275
  "status": "True",
276
  "randydev": {
 
293
  api_key: None = Depends(validate_api_key_only_devs)
294
  ):
295
  try:
296
+ _, _, _, _, sibyl_user_id = get_sibyl_system_banned(user_id)
297
 
298
  if sibyl_user_id:
299
+ remove_sibyl_system_banned(user_id)
300
  return {"status": "true", "message": f"Successfully removed {user_id} from the Sibyl ban list."}
301
  else:
302
  return {"status": "false", "message": "Not found user"}
 
314
 
315
  try:
316
  date_joined = str(dt.now())
317
+ sibyl_ban = random.choice(RAMDOM_STATUS)
318
  _, _, is_banned, _, sibyl_user_id = get_sibyl_system_banned(user_id)
319
 
320
  if sibyl_user_id and is_banned:
321
  return {"status": "false", "message": "User is already banned"}
322
 
323
+ new_sibyl_system_banned(user_id, sibyl_ban, reason, date_joined)
324
 
325
  return {
326
  "status": "true",
 
341
  user_id: int = Query(..., description="User ID in query parameter"),
342
  api_key: None = Depends(validate_api_key)
343
  ):
344
+ sibyl_name, reason, is_banned, date_joined, sibyl_user_id = get_sibyl_system_banned(user_id)
345
  if sibyl_name and reason and is_banned and date_joined and sibyl_user_id:
346
  return {
347
  "status": "true",