Spaces:
Running
Running
Create database.py
Browse files- database.py +91 -0
database.py
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
# Copyright 2020-2023 (c) Randy W @xtdevs, @xtsea
|
4 |
+
#
|
5 |
+
# from : https://github.com/TeamKillerX
|
6 |
+
# Channel : @RendyProjects
|
7 |
+
# This program is free software: you can redistribute it and/or modify
|
8 |
+
# it under the terms of the GNU Affero General Public License as published by
|
9 |
+
# the Free Software Foundation, either version 3 of the License, or
|
10 |
+
# (at your option) any later version.
|
11 |
+
#
|
12 |
+
# This program is distributed in the hope that it will be useful,
|
13 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
# GNU Affero General Public License for more details.
|
16 |
+
#
|
17 |
+
# You should have received a copy of the GNU Affero General Public License
|
18 |
+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
19 |
+
|
20 |
+
import os
|
21 |
+
from dotenv import load_dotenv
|
22 |
+
from pymongo import MongoClient
|
23 |
+
|
24 |
+
load_dotenv()
|
25 |
+
MONGO_URL = os.environ["MONGO_URL"]
|
26 |
+
|
27 |
+
client_mongo = MongoClient(MONGO_URL)
|
28 |
+
db = client_mongo["tiktokbot"]
|
29 |
+
collection = db["users"]
|
30 |
+
|
31 |
+
RAMDOM_STATUS = [
|
32 |
+
"civilian",
|
33 |
+
"wanted",
|
34 |
+
"undercover",
|
35 |
+
"rogue_agent",
|
36 |
+
"innocent",
|
37 |
+
"fugitive",
|
38 |
+
"covert_operator"
|
39 |
+
]
|
40 |
+
|
41 |
+
def remove_sibyl_system_banned(user_id):
|
42 |
+
update_doc = {
|
43 |
+
"sibyl_ban": None,
|
44 |
+
"reason_sibyl": None,
|
45 |
+
"is_banned_sibly": None,
|
46 |
+
"date_joined_sib": None,
|
47 |
+
"sibyl_userid": None
|
48 |
+
}
|
49 |
+
return collection.update_one({"user_id": user_id}, {"$unset": update_doc}, upsert=True)
|
50 |
+
|
51 |
+
def new_sibyl_system_banned(user_id, name, reason, date_joined):
|
52 |
+
update_doc = {
|
53 |
+
"sibyl_ban": name,
|
54 |
+
"reason_sibyl": reason,
|
55 |
+
"is_banned_sibly": True,
|
56 |
+
"date_joined_sib": date_joined,
|
57 |
+
"sibyl_userid": user_id
|
58 |
+
}
|
59 |
+
return collection.update_one({"user_id": user_id}, {"$set": update_doc}, upsert=True)
|
60 |
+
|
61 |
+
def get_sibyl_system_banned(user_id):
|
62 |
+
user = collection.find_one({"user_id": user_id})
|
63 |
+
if user:
|
64 |
+
sibyl_name = user.get("sibyl_ban")
|
65 |
+
reason = user.get("reason_sibyl")
|
66 |
+
is_banned = user.get("is_banned_sibly")
|
67 |
+
date_joined = user.get("date_joined_sib")
|
68 |
+
sibyl_user_id = user.get("sibyl_userid")
|
69 |
+
return sibyl_name, reason, is_banned, date_joined, sibyl_user_id
|
70 |
+
else:
|
71 |
+
return None
|
72 |
+
|
73 |
+
def get_all_banned():
|
74 |
+
banned_users = []
|
75 |
+
|
76 |
+
users = collection.find({})
|
77 |
+
|
78 |
+
for user_id in users:
|
79 |
+
reason = user_id.get("reason_sibyl")
|
80 |
+
user_id = user_id.get("sibyl_userid")
|
81 |
+
banned_users.append({"user_id": user_id, "reason": reason})
|
82 |
+
return banned_users
|
83 |
+
|
84 |
+
def get_all_api_keys():
|
85 |
+
user = collection.find({})
|
86 |
+
api_keys = []
|
87 |
+
for x in user:
|
88 |
+
api_key = x.get("ryuzaki_api_key")
|
89 |
+
if api_key:
|
90 |
+
api_keys.append(api_key)
|
91 |
+
return api_keys
|