From 088d905196a238dc18cc6d419bdac1c18b6c2f76 Mon Sep 17 00:00:00 2001 From: Thor77 Date: Mon, 24 Jul 2017 14:38:48 +0200 Subject: [PATCH] Convert Client.nick into property to add previous nick to .nick_history on set --- tsstats/client.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tsstats/client.py b/tsstats/client.py index 362e205..edb73e9 100644 --- a/tsstats/client.py +++ b/tsstats/client.py @@ -92,7 +92,7 @@ class Client(object): ''' # public self.identifier = identifier - self.nick = nick + self._nick = nick self.nick_history = set() self.connected = 0 self.onlinetime = datetime.timedelta() @@ -104,6 +104,18 @@ class Client(object): # private self._last_connect = 0 + @property + def nick(self): + return self._nick + + @nick.setter + def nick(self, new_nick): + if self._nick and new_nick != self._nick: + # add old nick to history + self.nick_history.add(self._nick) + # set new nick + self._nick = new_nick + def connect(self, timestamp): ''' Connect client at `timestamp`