Data export, warnings' improvements, bug fixes #35

Merged
profitroll merged 30 commits from dev into master 2023-04-02 23:27:31 +03:00
5 changed files with 75 additions and 6 deletions
Showing only changes of commit 972827d6c2 - Show all commits

View File

@ -82,6 +82,10 @@
"interval": 5, "interval": 5,
"enabled": true, "enabled": true,
"channels": [] "channels": []
},
"warnings_revocation": {
"interval": 6,
"enabled": true
} }
}, },
"locations": { "locations": {

View File

@ -24,6 +24,8 @@ async def cmd_warn(app: Client, msg: Message):
"admin": msg.from_user.id, "admin": msg.from_user.id,
"date": datetime.now(), "date": datetime.now(),
"reason": message, "reason": message,
"active": True,
"revoke_date": None,
} }
) )
if message == "": if message == "":

View File

@ -23,7 +23,7 @@ async def cmd_warnings(app: Client, msg: Message):
return return
try: try:
user_db = col_users.find_one({"user": int(msg.command[1])}) user_db = col_users.find_one({"user": int(msg.command[1]), "active": True})
target_id = user_db["user"] target_id = user_db["user"]
target_name = user_db["tg_name"] target_name = user_db["tg_name"]
except: except:
@ -47,7 +47,7 @@ async def cmd_warnings(app: Client, msg: Message):
) )
return return
warns = col_warnings.count_documents({"user": target_id}) warns = col_warnings.count_documents({"user": target_id, "active": True})
if warns == 0: if warns == 0:
await msg.reply_text( await msg.reply_text(

View File

@ -18,7 +18,12 @@ from pyrogram.enums.chat_members_filter import ChatMembersFilter
from classes.holo_user import HoloUser from classes.holo_user import HoloUser
from modules.utils import configGet, jsonLoad, jsonSave, locale, logWrite from modules.utils import configGet, jsonLoad, jsonSave, locale, logWrite
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
from modules.database import col_applications, col_sponsorships, col_youtube from modules.database import (
col_applications,
col_sponsorships,
col_youtube,
col_warnings,
)
from xmltodict import parse from xmltodict import parse
from requests import get from requests import get
@ -182,6 +187,45 @@ if configGet("enabled", "features", "sponsorships") is True:
logWrite("Sponsorships check performed") logWrite("Sponsorships check performed")
# Revoke old warnings
if configGet("enabled", "features", "warnings") is True:
if configGet("enabled", "scheduler", "warnings_revocation") is True:
@scheduler.scheduled_job(
trigger="date", run_date=datetime.now() + timedelta(seconds=10)
)
@scheduler.scheduled_job(
trigger="interval",
hours=configGet("interval", "scheduler", "warnings_revocation"),
)
async def revoke_warnings():
for warning in list(
col_warnings.find(
{
"active": True,
"date": {"$lt": datetime.now() - timedelta(days=90)},
}
)
):
if (
col_warnings.count_documents(
{
"user": warning["user"],
"active": True,
"date": {"$gt": datetime.now() - timedelta(days=90)},
}
)
== 0
):
col_warnings.update_one(
{"_id": warning["_id"]},
{"$set": {"active": False, "revoke_date": datetime.now()}},
)
logWrite(
f'Revoked warning {str(warning["_id"])} of user {warning["user"]} because no active warnings for the last 90 days found.'
)
# Register all bot commands # Register all bot commands
@scheduler.scheduled_job( @scheduler.scheduled_job(
trigger="date", run_date=datetime.now() + timedelta(seconds=10) trigger="date", run_date=datetime.now() + timedelta(seconds=10)

View File

@ -4,15 +4,23 @@
"user", "user",
"admin", "admin",
"date", "date",
"reason" "reason",
"active",
"revoke_date"
], ],
"properties": { "properties": {
"user": { "user": {
"bsonType": ["int", "long"], "bsonType": [
"int",
"long"
],
"description": "Telegram ID of user" "description": "Telegram ID of user"
}, },
"admin": { "admin": {
"bsonType": ["int", "long"], "bsonType": [
"int",
"long"
],
"description": "Telegram ID of admin" "description": "Telegram ID of admin"
}, },
"date": { "date": {
@ -22,6 +30,17 @@
"reason": { "reason": {
"bsonType": "string", "bsonType": "string",
"description": "Broken rule or admin's comment" "description": "Broken rule or admin's comment"
},
"active": {
"bsonType": "bool",
"description": "Whether warning is still present"
},
"revoke_date": {
"bsonType": [
"date",
"null"
],
"description": "Date when warning got inactive"
} }
} }
} }