.BANCHO. Add check silence in send message
This commit is contained in:
parent
b1e4314990
commit
4a1d1c6f0e
|
@ -68,3 +68,6 @@ class messageTooLongWarnException(Exception):
|
||||||
|
|
||||||
class messageTooLongException(Exception):
|
class messageTooLongException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class userSilencedException(Exception):
|
||||||
|
pass
|
||||||
|
|
|
@ -55,8 +55,11 @@ def handle(tornadoRequest):
|
||||||
responseToken = glob.tokens.addToken(userID)
|
responseToken = glob.tokens.addToken(userID)
|
||||||
responseTokenString = responseToken.token
|
responseTokenString = responseToken.token
|
||||||
|
|
||||||
# Get silence end
|
# Set silence end UNIX time in token
|
||||||
userSilenceEnd = max(0, userHelper.getSilenceEnd(userID)-int(time.time()))
|
responseToken.silenceEndTime = userHelper.getSilenceEnd(userID)
|
||||||
|
|
||||||
|
# Get only silence remaining seconds
|
||||||
|
silenceSeconds = responseToken.getSilenceSecondsLeft()
|
||||||
|
|
||||||
# Get supporter/GMT
|
# Get supporter/GMT
|
||||||
userRank = userHelper.getRankPrivileges(userID)
|
userRank = userHelper.getRankPrivileges(userID)
|
||||||
|
@ -80,7 +83,7 @@ def handle(tornadoRequest):
|
||||||
responseToken.enqueue(serverPackets.notification("Bancho is in maintenance mode. Only mods/admins have full access to the server.\nType !system maintenance off in chat to turn off maintenance mode."))
|
responseToken.enqueue(serverPackets.notification("Bancho is in maintenance mode. Only mods/admins have full access to the server.\nType !system maintenance off in chat to turn off maintenance mode."))
|
||||||
|
|
||||||
# Send all needed login packets
|
# Send all needed login packets
|
||||||
responseToken.enqueue(serverPackets.silenceEndTime(userSilenceEnd))
|
responseToken.enqueue(serverPackets.silenceEndTime(silenceSeconds))
|
||||||
responseToken.enqueue(serverPackets.userID(userID))
|
responseToken.enqueue(serverPackets.userID(userID))
|
||||||
responseToken.enqueue(serverPackets.protocolVersion())
|
responseToken.enqueue(serverPackets.protocolVersion())
|
||||||
responseToken.enqueue(serverPackets.userSupporterGMT(userSupporter, userGMT))
|
responseToken.enqueue(serverPackets.userSupporterGMT(userSupporter, userGMT))
|
||||||
|
@ -104,6 +107,7 @@ def handle(tornadoRequest):
|
||||||
if value.publicRead == True:
|
if value.publicRead == True:
|
||||||
responseToken.enqueue(serverPackets.channelInfo(key))
|
responseToken.enqueue(serverPackets.channelInfo(key))
|
||||||
|
|
||||||
|
# Send friends list
|
||||||
responseToken.enqueue(serverPackets.friendList(userID))
|
responseToken.enqueue(serverPackets.friendList(userID))
|
||||||
|
|
||||||
# Send main menu icon and login notification if needed
|
# Send main menu icon and login notification if needed
|
||||||
|
|
|
@ -27,6 +27,10 @@ def handle(userToken, packetData):
|
||||||
# Private message packet
|
# Private message packet
|
||||||
packetData = clientPackets.sendPrivateMessage(packetData)
|
packetData = clientPackets.sendPrivateMessage(packetData)
|
||||||
|
|
||||||
|
# Make sure the user is not silenced
|
||||||
|
if userToken.isSilenced() == True:
|
||||||
|
raise exceptions.userSilencedException
|
||||||
|
|
||||||
# Check message length
|
# Check message length
|
||||||
if len(packetData["message"]) > 256:
|
if len(packetData["message"]) > 256:
|
||||||
if userToken.longMessageWarning == True:
|
if userToken.longMessageWarning == True:
|
||||||
|
@ -62,6 +66,9 @@ def handle(userToken, packetData):
|
||||||
|
|
||||||
# Console and file output
|
# Console and file output
|
||||||
log.pm("{} -> {}: {}".format(username, packetData["to"], packetData["message"]))
|
log.pm("{} -> {}: {}".format(username, packetData["to"], packetData["message"]))
|
||||||
|
except exceptions.userSilencedException:
|
||||||
|
userToken.enqueue(serverPackets.silenceEndTime(userToken.getSilenceSecondsLeft()))
|
||||||
|
log.warning("{} tried to send a message during silence".format(username))
|
||||||
except exceptions.tokenNotFoundException:
|
except exceptions.tokenNotFoundException:
|
||||||
# Token not found, user disconnected
|
# Token not found, user disconnected
|
||||||
log.warning("{} tried to send a message to {}, but their token couldn't be found".format(username, packetData["to"]))
|
log.warning("{} tried to send a message to {}, but their token couldn't be found".format(username, packetData["to"]))
|
||||||
|
|
|
@ -28,6 +28,10 @@ def handle(userToken, packetData):
|
||||||
# Receivers
|
# Receivers
|
||||||
who = []
|
who = []
|
||||||
|
|
||||||
|
# Make sure the user is not silenced
|
||||||
|
if userToken.isSilenced() == True:
|
||||||
|
raise exceptions.userSilencedException
|
||||||
|
|
||||||
# Check message length
|
# Check message length
|
||||||
if len(packetData["message"]) > 256:
|
if len(packetData["message"]) > 256:
|
||||||
if userToken.longMessageWarning == True:
|
if userToken.longMessageWarning == True:
|
||||||
|
@ -116,6 +120,9 @@ def handle(userToken, packetData):
|
||||||
|
|
||||||
# Discord log
|
# Discord log
|
||||||
discordBotHelper.sendChatlog("**{fro} @ {to}:** {message}".format(fro=username, to=packetData["to"], message=str(packetData["message"].encode("utf-8"))[2:-1]))
|
discordBotHelper.sendChatlog("**{fro} @ {to}:** {message}".format(fro=username, to=packetData["to"], message=str(packetData["message"].encode("utf-8"))[2:-1]))
|
||||||
|
except exceptions.userSilencedException:
|
||||||
|
userToken.enqueue(serverPackets.silenceEndTime(userToken.getSilenceSecondsLeft()))
|
||||||
|
log.warning("{} tried to send a message during silence".format(username))
|
||||||
except exceptions.channelModeratedException:
|
except exceptions.channelModeratedException:
|
||||||
log.warning("{} tried to send a message to a channel that is in moderated mode ({})".format(username, packetData["to"]))
|
log.warning("{} tried to send a message to a channel that is in moderated mode ({})".format(username, packetData["to"]))
|
||||||
except exceptions.channelUnknownException:
|
except exceptions.channelUnknownException:
|
||||||
|
|
|
@ -32,34 +32,6 @@ class token:
|
||||||
latestTillerino -- beatmap ID of latest song from tillerino bot
|
latestTillerino -- beatmap ID of latest song from tillerino bot
|
||||||
"""
|
"""
|
||||||
|
|
||||||
'''token = ""
|
|
||||||
userID = 0
|
|
||||||
username = ""
|
|
||||||
rank = 0
|
|
||||||
actionID = actions.idle
|
|
||||||
actionText = ""
|
|
||||||
actionMd5 = ""
|
|
||||||
actionMods = 0
|
|
||||||
gameMode = gameModes.std
|
|
||||||
|
|
||||||
country = 0
|
|
||||||
location = [0,0]
|
|
||||||
|
|
||||||
queue = bytes()
|
|
||||||
joinedChannels = []
|
|
||||||
|
|
||||||
spectating = 0
|
|
||||||
spectators = []
|
|
||||||
|
|
||||||
pingTime = 0
|
|
||||||
loginTime = 0
|
|
||||||
|
|
||||||
awayMessage = ""
|
|
||||||
|
|
||||||
matchID = -1
|
|
||||||
|
|
||||||
latestTillerino = 0'''
|
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, __userID, __token = None):
|
def __init__(self, __userID, __token = None):
|
||||||
"""
|
"""
|
||||||
|
@ -93,11 +65,11 @@ class token:
|
||||||
self.awayMessage = ""
|
self.awayMessage = ""
|
||||||
self.matchID = -1
|
self.matchID = -1
|
||||||
self.tillerino = [0,0,-1.0] # beatmap, mods, acc
|
self.tillerino = [0,0,-1.0] # beatmap, mods, acc
|
||||||
|
self.silenceEndTime = 0
|
||||||
self.queue = bytes()
|
self.queue = bytes()
|
||||||
|
|
||||||
self.longMessageWarning = False
|
|
||||||
|
|
||||||
# Spam protection
|
# Spam protection
|
||||||
|
self.longMessageWarning = False
|
||||||
self.spamRate = 0
|
self.spamRate = 0
|
||||||
self.lastMessagetime = 0
|
self.lastMessagetime = 0
|
||||||
|
|
||||||
|
@ -244,13 +216,14 @@ class token:
|
||||||
|
|
||||||
def silence(self, seconds, reason, author = 999):
|
def silence(self, seconds, reason, author = 999):
|
||||||
"""
|
"""
|
||||||
Silences this user (both db and packet)
|
Silences this user (db, packet and token)
|
||||||
|
|
||||||
seconds -- silence length in seconds
|
seconds -- silence length in seconds
|
||||||
reason -- silence reason
|
reason -- silence reason
|
||||||
author -- userID of who has silenced the target. Optional. Default: 999 (fokabot)
|
author -- userID of who has silenced the target. Optional. Default: 999 (fokabot)
|
||||||
"""
|
"""
|
||||||
# Silence user in db
|
# Silence in db and token
|
||||||
|
self.silenceEndTime = int(time.time())+seconds
|
||||||
userHelper.silence(self.userID, seconds, reason, author)
|
userHelper.silence(self.userID, seconds, reason, author)
|
||||||
|
|
||||||
# Send silence packet to target
|
# Send silence packet to target
|
||||||
|
@ -277,3 +250,20 @@ class token:
|
||||||
# Silence the user if needed
|
# Silence the user if needed
|
||||||
if self.spamRate > 10:
|
if self.spamRate > 10:
|
||||||
self.silence(1800, "Spamming (auto spam protection)")
|
self.silence(1800, "Spamming (auto spam protection)")
|
||||||
|
|
||||||
|
def isSilenced(self):
|
||||||
|
"""
|
||||||
|
Returns True if this user is silenced, otherwise False
|
||||||
|
|
||||||
|
return -- True/False
|
||||||
|
"""
|
||||||
|
return self.silenceEndTime-int(time.time()) > 0
|
||||||
|
|
||||||
|
def getSilenceSecondsLeft(self):
|
||||||
|
"""
|
||||||
|
Returns the seconds left for this user's silence
|
||||||
|
(0 if user is not silenced)
|
||||||
|
|
||||||
|
return -- silence seconds left
|
||||||
|
"""
|
||||||
|
return max(0, self.silenceEndTime-int(time.time()))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user