WIP: API usage as main
This commit is contained in:
@@ -27,10 +27,11 @@ db = db_client.get_database(name=db_config["name"])
|
||||
|
||||
collections = db.list_collection_names()
|
||||
|
||||
for collection in ["sent", "banned", "submitted"]:
|
||||
for collection in ["sent", "users", "banned", "submitted"]:
|
||||
if not collection in collections:
|
||||
db.create_collection(collection)
|
||||
|
||||
col_sent = db.get_collection("sent")
|
||||
col_users = db.get_collection("users")
|
||||
col_banned = db.get_collection("banned")
|
||||
col_submitted = db.get_collection("submitted")
|
@@ -1,32 +1,27 @@
|
||||
from time import time
|
||||
from modules.utils import jsonLoad, jsonSave, configGet
|
||||
from datetime import datetime, timezone
|
||||
from modules.utils import configGet
|
||||
from modules.database import col_users, col_banned
|
||||
from pyrogram.types.user_and_chats import User
|
||||
|
||||
def subLimit(user):
|
||||
submit = jsonLoad(configGet("submit", "locations"))
|
||||
submit[str(user.id)] = time()
|
||||
jsonSave(submit, configGet("submit", "locations"))
|
||||
def subLimit(user: User) -> None:
|
||||
if col_users.find_one_and_update({"user": user.id}, {"$set": {"cooldown": datetime.now(tz=timezone.utc)}}) is None:
|
||||
col_users.insert_one({"user": user.id, "cooldown": datetime.now(tz=timezone.utc)})
|
||||
|
||||
def subLimited(user):
|
||||
def subLimited(user: User) -> bool:
|
||||
if user.id == configGet("admin"):
|
||||
return False
|
||||
else:
|
||||
submit = jsonLoad(configGet("submit", "locations"))
|
||||
if str(user.id) in submit:
|
||||
if (time() - submit[str(user.id)]) < configGet("timeout", "submission"):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
db_record = col_users.find_one({"user": user.id})
|
||||
if db_record is None:
|
||||
return False
|
||||
return True if (datetime.now(tz=timezone.utc) - db_record["cooldown"]).total_seconds() < configGet("timeout", "submission") else False
|
||||
|
||||
def subBlock(user):
|
||||
blocked = jsonLoad(configGet("blocked", "locations"))
|
||||
if user not in blocked:
|
||||
blocked.append(user)
|
||||
jsonSave(blocked, configGet("blocked", "locations"))
|
||||
def subBlocked(user: User) -> bool:
|
||||
return False if col_banned.find_one({"user": user.id}) is None else True
|
||||
|
||||
def subUnblock(user):
|
||||
blocked = jsonLoad(configGet("blocked", "locations"))
|
||||
if user in blocked:
|
||||
blocked.remove(user)
|
||||
jsonSave(blocked, configGet("blocked", "locations"))
|
||||
def subBlock(user: User) -> None:
|
||||
if col_banned.find_one({"user": user.id}) is None:
|
||||
col_banned.insert_one({"user": user.id, "date": datetime.now(tz=timezone.utc)})
|
||||
|
||||
def subUnblock(user: User) -> None:
|
||||
col_banned.find_one_and_delete({"user": user.id})
|
Reference in New Issue
Block a user