Fix username with spaces breaking commands

This commit is contained in:
Giuseppe Guerra 2017-08-11 01:33:14 +02:00
parent 0229fc4e65
commit 5d73682a71

View File

@ -86,7 +86,7 @@ def alert(fro, chan, message):
def alertUser(fro, chan, message): def alertUser(fro, chan, message):
target = message[0].lower() target = message[0].lower()
targetToken = glob.tokens.getTokenFromUsername(target, safe=True) targetToken = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True)
if targetToken is not None: if targetToken is not None:
targetToken.enqueue(serverPackets.notification(' '.join(message[1:]))) targetToken.enqueue(serverPackets.notification(' '.join(message[1:])))
return False return False
@ -132,7 +132,7 @@ def kick(fro, chan, message):
return "Nope." return "Nope."
# Get target token and make sure is connected # Get target token and make sure is connected
tokens = glob.tokens.getTokenFromUsername(target, safe=True, _all=True) tokens = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True, _all=True)
if len(tokens) == 0: if len(tokens) == 0:
return "{} is not online".format(target) return "{} is not online".format(target)
@ -185,7 +185,7 @@ def silence(fro, chan, message):
return "Invalid silence time. Max silence time is 7 days." return "Invalid silence time. Max silence time is 7 days."
# Send silence packet to target if he's connected # Send silence packet to target if he's connected
targetToken = glob.tokens.getTokenFromUsername(target) targetToken = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True)
if targetToken is not None: if targetToken is not None:
# user online, silence both in db and with packet # user online, silence both in db and with packet
targetToken.silence(silenceTime, reason, userID) targetToken.silence(silenceTime, reason, userID)
@ -210,7 +210,7 @@ def removeSilence(fro, chan, message):
return "{}: user not found".format(target) return "{}: user not found".format(target)
# Send new silence end packet to user if he's online # Send new silence end packet to user if he's online
targetToken = glob.tokens.getTokenFromUsername(target) targetToken = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True)
if targetToken is not None: if targetToken is not None:
# User online, remove silence both in db and with packet # User online, remove silence both in db and with packet
targetToken.silence(0, "", userID) targetToken.silence(0, "", userID)
@ -236,7 +236,7 @@ def ban(fro, chan, message):
userUtils.ban(targetUserID) userUtils.ban(targetUserID)
# Send ban packet to the user if he's online # Send ban packet to the user if he's online
targetToken = glob.tokens.getTokenFromUsername(target) targetToken = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True)
if targetToken is not None: if targetToken is not None:
targetToken.enqueue(serverPackets.loginBanned()) targetToken.enqueue(serverPackets.loginBanned())
@ -277,7 +277,7 @@ def restrict(fro, chan, message):
userUtils.restrict(targetUserID) userUtils.restrict(targetUserID)
# Send restricted mode packet to this user if he's online # Send restricted mode packet to this user if he's online
targetToken = glob.tokens.getTokenFromUsername(target) targetToken = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True)
if targetToken is not None: if targetToken is not None:
targetToken.setRestricted() targetToken.setRestricted()
@ -726,7 +726,7 @@ def report(fro, chan, message):
# Get the token if possible # Get the token if possible
chatlog = "" chatlog = ""
token = glob.tokens.getTokenFromUsername(target) token = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True)
if token is not None: if token is not None:
chatlog = token.getMessagesBufferString() chatlog = token.getMessagesBufferString()