3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-12-25 04:02:45 +01:00

prs+IrcUser: add incoming (handle_away) and outgoing (awayClient) AWAY handling

This commit is contained in:
James Lu 2015-08-12 04:17:01 -07:00
parent 7bccb37ddf
commit 1a57dfcdc3
3 changed files with 41 additions and 0 deletions

View File

@ -21,6 +21,7 @@ class IrcUser():
self.identified = False self.identified = False
self.channels = set() self.channels = set()
self.away = ''
def __repr__(self): def __repr__(self):
return repr(self.__dict__) return repr(self.__dict__)

View File

@ -297,6 +297,16 @@ def numericServer(irc, source, numeric, text):
"locally by InspIRCd servers, so there is no " "locally by InspIRCd servers, so there is no "
"need for PyLink to send numerics directly yet.") "need for PyLink to send numerics directly yet.")
def awayClient(irc, source, text):
"""<irc object> <numeric> <text>
Sends an AWAY message with text <text> from PyLink client <numeric>.
<text> can be an empty string to unset AWAY status."""
if text:
_send(irc, source, 'AWAY %s :%s' % (int(time.time()), text))
else:
_send(irc, source, 'AWAY')
def connect(irc): def connect(irc):
ts = irc.start_ts ts = irc.start_ts
@ -664,3 +674,13 @@ def handle_fname(irc, numeric, command, args):
def handle_endburst(irc, numeric, command, args): def handle_endburst(irc, numeric, command, args):
return {} return {}
def handle_away(irc, numeric, command, args):
# <- :1MLAAAAIG AWAY 1439371390 :Auto-away
try:
ts = args[0]
irc.users[numeric].away = text = args[1]
return {'text': text, 'ts': ts}
except IndexError: # User is unsetting away status
irc.users[numeric].away = ''
return {'text': ''}

View File

@ -231,6 +231,16 @@ def pingServer(irc, source=None, target=None):
def numericServer(irc, source, numeric, target, text): def numericServer(irc, source, numeric, target, text):
_send(irc, source, '%s %s %s' % (numeric, target, text)) _send(irc, source, '%s %s %s' % (numeric, target, text))
def awayClient(irc, source, text):
"""<irc object> <numeric> <text>
Sends an AWAY message with text <text> from PyLink client <numeric>.
<text> can be an empty string to unset AWAY status."""
if text:
_send(irc, source, 'AWAY :%s' % text)
else:
_send(irc, source, 'AWAY')
def connect(irc): def connect(irc):
ts = irc.start_ts ts = irc.start_ts
@ -649,3 +659,13 @@ def handle_472(irc, numeric, command, args):
' desyncs, try adding the line "loadmodule "extensions/%s.so";" to ' ' desyncs, try adding the line "loadmodule "extensions/%s.so";" to '
'your IRCd configuration.', irc.name, setter, badmode, 'your IRCd configuration.', irc.name, setter, badmode,
charlist[badmode]) charlist[badmode])
def handle_away(irc, numeric, command, args):
# <- :6ELAAAAAB AWAY :Auto-away
try:
irc.users[numeric].away = text = args[0]
except IndexError: # User is unsetting away status
irc.users[numeric].away = text = ''
return {'text': text}