Handle empty chat messages
This commit is contained in:
parent
8bdc56faf6
commit
05eead0e1a
|
@ -79,7 +79,7 @@ def partChannel(userID = 0, channel = "", token = None, toIRC = True, kick = Fal
|
||||||
token = glob.tokens.getTokenFromUserID(userID)
|
token = glob.tokens.getTokenFromUserID(userID)
|
||||||
# Make sure the token exists
|
# Make sure the token exists
|
||||||
if token is None:
|
if token is None:
|
||||||
raise exceptions.userNotFoundException
|
raise exceptions.userNotFoundException()
|
||||||
else:
|
else:
|
||||||
token = token
|
token = token
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ def sendMessage(fro = "", to = "", message = "", token = None, toIRC = True):
|
||||||
if token is None:
|
if token is None:
|
||||||
token = glob.tokens.getTokenFromUsername(fro)
|
token = glob.tokens.getTokenFromUsername(fro)
|
||||||
if token is None:
|
if token is None:
|
||||||
raise exceptions.userNotFoundException
|
raise exceptions.userNotFoundException()
|
||||||
else:
|
else:
|
||||||
# token object alredy passed, get its string and its username (fro)
|
# token object alredy passed, get its string and its username (fro)
|
||||||
fro = token.username
|
fro = token.username
|
||||||
|
@ -194,6 +194,11 @@ def sendMessage(fro = "", to = "", message = "", token = None, toIRC = True):
|
||||||
toClient = "#spectator"
|
toClient = "#spectator"
|
||||||
elif to.startswith("#multi_"):
|
elif to.startswith("#multi_"):
|
||||||
toClient = "#multiplayer"
|
toClient = "#multiplayer"
|
||||||
|
|
||||||
|
# Make sure the message is valid
|
||||||
|
if not message.strip():
|
||||||
|
raise exceptions.invalidArgumentsException()
|
||||||
|
|
||||||
# Truncate message if > 2048 characters
|
# Truncate message if > 2048 characters
|
||||||
message = message[:2048]+"..." if len(message) > 2048 else message
|
message = message[:2048]+"..." if len(message) > 2048 else message
|
||||||
|
|
||||||
|
@ -297,6 +302,9 @@ def sendMessage(fro = "", to = "", message = "", token = None, toIRC = True):
|
||||||
except exceptions.userNotFoundException:
|
except exceptions.userNotFoundException:
|
||||||
log.warning("User not connected to IRC/Bancho")
|
log.warning("User not connected to IRC/Bancho")
|
||||||
return 401
|
return 401
|
||||||
|
except exceptions.invalidArgumentsException:
|
||||||
|
log.warning("{} tried to send an invalid message to {}".format(token.username, to))
|
||||||
|
return 404
|
||||||
|
|
||||||
|
|
||||||
""" IRC-Bancho Connect/Disconnect/Join/Part interfaces"""
|
""" IRC-Bancho Connect/Disconnect/Join/Part interfaces"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user