From a084101ced3b5c451938b74d5edaabeec3373be6 Mon Sep 17 00:00:00 2001 From: Thor77 Date: Sun, 23 Jul 2017 17:45:44 +0200 Subject: [PATCH] Add Clients.apply_events to apply events to a Clients-collection --- tsstats/client.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tsstats/client.py b/tsstats/client.py index 1e624a1..362e205 100644 --- a/tsstats/client.py +++ b/tsstats/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- - +# TODO: Implement action for set_nick event import datetime import logging from collections import MutableMapping @@ -23,6 +23,28 @@ class Clients(MutableMapping): self.store = dict() 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): ''' Add a Client to the collection