From c7c5528588e11eaf38ad21e76d4f488eec28ffc5 Mon Sep 17 00:00:00 2001 From: Nyo Date: Sun, 13 Nov 2016 12:23:45 +0100 Subject: [PATCH] .BANCHO. .FIX. Fix /away command, add support for /away command on IRC --- helpers/chatHelper.py | 14 +++++++++++++- irc/ircserver.py | 13 +++++-------- objects/osuToken.py | 16 +++++++++++++++- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/helpers/chatHelper.py b/helpers/chatHelper.py index cd0986c..ca004e7 100644 --- a/helpers/chatHelper.py +++ b/helpers/chatHelper.py @@ -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) \ No newline at end of file + 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 \ No newline at end of file diff --git a/irc/ircserver.py b/irc/ircserver.py index 5b65a31..cd680fc 100644 --- a/irc/ircserver.py +++ b/irc/ircserver.py @@ -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] diff --git a/objects/osuToken.py b/objects/osuToken.py index b087719..87efa35 100644 --- a/objects/osuToken.py +++ b/objects/osuToken.py @@ -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) \ No newline at end of file + 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 \ No newline at end of file