.BANCHO. .FIX. Fix /away command, add support for /away command on IRC

This commit is contained in:
Nyo 2016-11-13 12:23:45 +01:00
parent 3b150d70cd
commit c7c5528588
3 changed files with 33 additions and 10 deletions

View File

@ -256,6 +256,10 @@ def sendMessage(fro = "", to = "", message = "", token = None, toIRC = True):
# TODO: Make sure the recipient has not disabled PMs for non-friends or he's our friend
# Away check
if recipientToken.awayCheck(userID):
sendMessage(to, fro, "{code}ACTION is away: {message}{code}".format(code=chr(int(1)), message=recipientToken.awayMessage))
# Check message templates (mods/admins only)
if message in messageTemplates.templates and token.admin == True:
sendMessage(fro, to, messageTemplates.templates[message])
@ -357,4 +361,12 @@ def IRCPartChannel(username, channel):
if not userID:
log.warning("{} doesn't exist".format(username))
return
return partChannel(userID, channel)
return partChannel(userID, channel)
def IRCAway(username, message):
userID = userUtils.getID(username)
if not userID:
log.warning("{} doesn't exist".format(username))
return
glob.tokens.getTokenFromUserID(userID).setAwayMessage(message)
return 305 if message == "" else 306

View File

@ -296,7 +296,6 @@ class Client:
# Disconnect other IRC clients from the same user
for _, value in self.server.clients.items():
if value.IRCUsername.lower() == self.IRCUsername.lower() and value != self:
print("DISCONNECTERINOOOOOOOOOOOOOOOOOOOOO")
value.disconnect(quitmsg="Connected from another client")
return
elif command == "USER":
@ -440,7 +439,6 @@ class Client:
# Send the message to bancho and reply
if not recipientIRC.startswith("#"):
print("PMPMPM!!!!!!!!!!")
recipientBancho = chat.fixUsernameForBancho(recipientIRC)
else:
recipientBancho = recipientIRC
@ -489,10 +487,14 @@ class Client:
"""(fake) PONG command handler"""
pass
def awayHandler(self, command, arguments):
response = chat.IRCAway(self.banchoUsername, " ".join(arguments))
self.replyCode(response, "You are no longer marked as being away" if response == 305 else "You have been marked as being away")
def mainHandler(self, command, arguments):
"""Handler for post-login commands"""
handlers = {
#"AWAY": away_handler,
"AWAY": self.awayHandler,
#"ISON": ison_handler,
"JOIN": self.joinHandler,
#"LIST": list_handler,
@ -518,11 +520,6 @@ class Client:
self.replyCode(421, "Unknown command ({})".format(command))
class Server:
def __init__(self, port):
#self.host = socket.getfqdn("127.0.0.1")[:63]

View File

@ -51,6 +51,7 @@ class token:
self.country = 0
self.location = [0,0]
self.awayMessage = ""
self.sentAway = []
self.matchID = -1
self.tillerino = [0,0,-1.0] # beatmap, mods, acc
self.silenceEndTime = 0
@ -426,4 +427,17 @@ class token:
def leaveAllStreams(self):
for i in self.streams:
self.leaveStream(i)
self.leaveStream(i)
def awayCheck(self, userID):
"""
Returns True if userID doesn't know that we are away
Returns False if we are not away or if userID already knows we are away
:param userID: original sender userID
:return:
"""
if self.awayMessage == "" or userID in self.sentAway:
return False
self.sentAway.append(userID)
return True