.BANCHO. .FIX. Fix /away command, add support for /away command on IRC
This commit is contained in:
parent
3b150d70cd
commit
c7c5528588
|
@ -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
|
# 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)
|
# Check message templates (mods/admins only)
|
||||||
if message in messageTemplates.templates and token.admin == True:
|
if message in messageTemplates.templates and token.admin == True:
|
||||||
sendMessage(fro, to, messageTemplates.templates[message])
|
sendMessage(fro, to, messageTemplates.templates[message])
|
||||||
|
@ -357,4 +361,12 @@ def IRCPartChannel(username, channel):
|
||||||
if not userID:
|
if not userID:
|
||||||
log.warning("{} doesn't exist".format(username))
|
log.warning("{} doesn't exist".format(username))
|
||||||
return
|
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
|
|
@ -296,7 +296,6 @@ class Client:
|
||||||
# Disconnect other IRC clients from the same user
|
# Disconnect other IRC clients from the same user
|
||||||
for _, value in self.server.clients.items():
|
for _, value in self.server.clients.items():
|
||||||
if value.IRCUsername.lower() == self.IRCUsername.lower() and value != self:
|
if value.IRCUsername.lower() == self.IRCUsername.lower() and value != self:
|
||||||
print("DISCONNECTERINOOOOOOOOOOOOOOOOOOOOO")
|
|
||||||
value.disconnect(quitmsg="Connected from another client")
|
value.disconnect(quitmsg="Connected from another client")
|
||||||
return
|
return
|
||||||
elif command == "USER":
|
elif command == "USER":
|
||||||
|
@ -440,7 +439,6 @@ class Client:
|
||||||
|
|
||||||
# Send the message to bancho and reply
|
# Send the message to bancho and reply
|
||||||
if not recipientIRC.startswith("#"):
|
if not recipientIRC.startswith("#"):
|
||||||
print("PMPMPM!!!!!!!!!!")
|
|
||||||
recipientBancho = chat.fixUsernameForBancho(recipientIRC)
|
recipientBancho = chat.fixUsernameForBancho(recipientIRC)
|
||||||
else:
|
else:
|
||||||
recipientBancho = recipientIRC
|
recipientBancho = recipientIRC
|
||||||
|
@ -489,10 +487,14 @@ class Client:
|
||||||
"""(fake) PONG command handler"""
|
"""(fake) PONG command handler"""
|
||||||
pass
|
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):
|
def mainHandler(self, command, arguments):
|
||||||
"""Handler for post-login commands"""
|
"""Handler for post-login commands"""
|
||||||
handlers = {
|
handlers = {
|
||||||
#"AWAY": away_handler,
|
"AWAY": self.awayHandler,
|
||||||
#"ISON": ison_handler,
|
#"ISON": ison_handler,
|
||||||
"JOIN": self.joinHandler,
|
"JOIN": self.joinHandler,
|
||||||
#"LIST": list_handler,
|
#"LIST": list_handler,
|
||||||
|
@ -518,11 +520,6 @@ class Client:
|
||||||
self.replyCode(421, "Unknown command ({})".format(command))
|
self.replyCode(421, "Unknown command ({})".format(command))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Server:
|
class Server:
|
||||||
def __init__(self, port):
|
def __init__(self, port):
|
||||||
#self.host = socket.getfqdn("127.0.0.1")[:63]
|
#self.host = socket.getfqdn("127.0.0.1")[:63]
|
||||||
|
|
|
@ -51,6 +51,7 @@ class token:
|
||||||
self.country = 0
|
self.country = 0
|
||||||
self.location = [0,0]
|
self.location = [0,0]
|
||||||
self.awayMessage = ""
|
self.awayMessage = ""
|
||||||
|
self.sentAway = []
|
||||||
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.silenceEndTime = 0
|
||||||
|
@ -426,4 +427,17 @@ class token:
|
||||||
|
|
||||||
def leaveAllStreams(self):
|
def leaveAllStreams(self):
|
||||||
for i in self.streams:
|
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
|
Loading…
Reference in New Issue
Block a user