.BANCHO. Add notification when donor tag is expiring soon

This commit is contained in:
Nyo 2016-09-25 19:05:31 +02:00
parent 4b6e621a70
commit 121d19aaa7
2 changed files with 22 additions and 1 deletions

View File

@ -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)

View File

@ -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"]
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