Add Clients.apply_events
to apply events to a Clients-collection
This commit is contained in:
parent
da2b773bf6
commit
a084101ced
|
@ -1,5 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
# TODO: Implement action for set_nick event
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
from collections import MutableMapping
|
from collections import MutableMapping
|
||||||
|
@ -23,6 +23,28 @@ class Clients(MutableMapping):
|
||||||
self.store = dict()
|
self.store = dict()
|
||||||
self.update(dict(*args, **kwargs))
|
self.update(dict(*args, **kwargs))
|
||||||
|
|
||||||
|
def apply_events(self, events):
|
||||||
|
'''
|
||||||
|
Apply events to this Client-collection
|
||||||
|
|
||||||
|
:param events: list of events to apply
|
||||||
|
:type events: list
|
||||||
|
'''
|
||||||
|
for event in events:
|
||||||
|
# find corresponding client
|
||||||
|
client = self.setdefault(
|
||||||
|
event.identifier, Client(event.identifier)
|
||||||
|
)
|
||||||
|
if event.action == 'set_nick':
|
||||||
|
# omit, not implemented, nick action for now
|
||||||
|
continue
|
||||||
|
if event.arg_is_client:
|
||||||
|
# if arg is client, replace identifier with Client-obj
|
||||||
|
event = event._replace(
|
||||||
|
arg=self.setdefault(event.arg, Client(event.arg))
|
||||||
|
)
|
||||||
|
client.__getattribute__(event.action)(event.arg)
|
||||||
|
|
||||||
def __add__(self, client):
|
def __add__(self, client):
|
||||||
'''
|
'''
|
||||||
Add a Client to the collection
|
Add a Client to the collection
|
||||||
|
|
Loading…
Reference in New Issue