diff --git a/events/loginEvent.py b/events/loginEvent.py index 0646814..64574c6 100644 --- a/events/loginEvent.py +++ b/events/loginEvent.py @@ -9,6 +9,7 @@ import traceback from helpers import logHelper as log from helpers import chatHelper as chat from constants import privileges +import time def handle(tornadoRequest): # Data to return @@ -108,6 +109,15 @@ def handle(tornadoRequest): # Check restricted mode (and eventually send message) responseToken.checkRestricted() + # Send message if donor expires soon + if responseToken.privileges & privileges.USER_DONOR > 0: + expireDate = userHelper.getDonorExpire(responseToken.userID) + if expireDate-int(time.time()) <= 86400*3: + expireDays = round((expireDate-int(time.time()))/86400) + expireIn = "{} days".format(expireDays) if expireDays > 1 else "less than 24 hours" + responseToken.enqueue(serverPackets.notification("Your donor tag expires in {}! When your donor tag expires, you won't have any of the donor privileges, like yellow username, custom badge and discord custom role and username color! If you wish to keep supporting Ripple and you don't want to lose your donor privileges, you can donate again by clicking on 'Support us' on Ripple's website.".format(expireIn))) + + # Set silence end UNIX time in token responseToken.silenceEndTime = userHelper.getSilenceEnd(userID) diff --git a/helpers/userHelper.py b/helpers/userHelper.py index a9abf59..7be8373 100644 --- a/helpers/userHelper.py +++ b/helpers/userHelper.py @@ -626,4 +626,15 @@ def cacheUserIDs(): """Cache userIDs in glob.userIDCache, used later with getID().""" data = glob.db.fetchAll("SELECT id, username FROM users WHERE privileges & {} > 0".format(privileges.USER_NORMAL)) for i in data: - glob.userIDCache[i["username"]] = i["id"] \ No newline at end of file + glob.userIDCache[i["username"]] = i["id"] + +def getDonorExpire(userID): + """ + Return userID's donor expiration UNIX timestamp + :param userID: + :return: donor expiration UNIX timestamp + """ + data = glob.db.fetch("SELECT donor_expire FROM users WHERE id = %s LIMIT 1", [userID]) + if data is not None: + return data["donor_expire"] + return 0 \ No newline at end of file