mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-01 01:09:22 +01:00
classes: make User, Channel TS a property for type-safety (#594)
This commit is contained in:
parent
f20fa5e995
commit
e3a935d0b7
23
classes.py
23
classes.py
@ -47,12 +47,29 @@ class ChannelState(structures.IRCCaseInsensitiveDict):
|
|||||||
|
|
||||||
return self._data[key]
|
return self._data[key]
|
||||||
|
|
||||||
|
class TSObject():
|
||||||
|
"""Base class for classes containing a type-normalized timestamp."""
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self._ts = int(time.time())
|
||||||
|
|
||||||
class User():
|
@property
|
||||||
|
def ts(self):
|
||||||
|
return self._ts
|
||||||
|
|
||||||
|
@ts.setter
|
||||||
|
def ts(self, value):
|
||||||
|
if (not isinstance(value, int)) and (not isinstance(value, float)):
|
||||||
|
log.warning('TSObject: Got bad type for TS, converting from %s to int',
|
||||||
|
type(value), stack_info=True)
|
||||||
|
value = int(value)
|
||||||
|
self._ts = value
|
||||||
|
|
||||||
|
class User(TSObject):
|
||||||
"""PyLink IRC user class."""
|
"""PyLink IRC user class."""
|
||||||
def __init__(self, irc, nick, ts, uid, server, ident='null', host='null',
|
def __init__(self, irc, nick, ts, uid, server, ident='null', host='null',
|
||||||
realname='PyLink dummy client', realhost='null',
|
realname='PyLink dummy client', realhost='null',
|
||||||
ip='0.0.0.0', manipulatable=False, opertype='IRC Operator'):
|
ip='0.0.0.0', manipulatable=False, opertype='IRC Operator'):
|
||||||
|
super().__init__()
|
||||||
self._nick = nick
|
self._nick = nick
|
||||||
self.lower_nick = irc.to_lower(nick)
|
self.lower_nick = irc.to_lower(nick)
|
||||||
|
|
||||||
@ -1977,15 +1994,15 @@ class Server():
|
|||||||
|
|
||||||
IrcServer = Server
|
IrcServer = Server
|
||||||
|
|
||||||
class Channel(structures.CamelCaseToSnakeCase, structures.CopyWrapper):
|
class Channel(TSObject, structures.CamelCaseToSnakeCase, structures.CopyWrapper):
|
||||||
"""PyLink IRC channel class."""
|
"""PyLink IRC channel class."""
|
||||||
|
|
||||||
def __init__(self, irc, name=None):
|
def __init__(self, irc, name=None):
|
||||||
|
super().__init__()
|
||||||
# Initialize variables, such as the topic, user list, TS, who's opped, etc.
|
# Initialize variables, such as the topic, user list, TS, who's opped, etc.
|
||||||
self.users = set()
|
self.users = set()
|
||||||
self.modes = set()
|
self.modes = set()
|
||||||
self.topic = ''
|
self.topic = ''
|
||||||
self.ts = int(time.time())
|
|
||||||
self.prefixmodes = {'op': set(), 'halfop': set(), 'voice': set(),
|
self.prefixmodes = {'op': set(), 'halfop': set(), 'voice': set(),
|
||||||
'owner': set(), 'admin': set()}
|
'owner': set(), 'admin': set()}
|
||||||
self._irc = irc
|
self._irc = irc
|
||||||
|
Loading…
Reference in New Issue
Block a user