Skip to content

Commit

Permalink
Fix registering first client to bot
Browse files Browse the repository at this point in the history
when bot creation is triggered by NetworkStore update.
  • Loading branch information
rtnpro committed Mar 23, 2016
1 parent f48bdd9 commit 6dd53ab
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions ircb/bouncer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
from collections import defaultdict
import logging
import logging.config
from ircb.connection import Connection
Expand Down Expand Up @@ -92,7 +93,7 @@ class Bouncer(object):

def __init__(self):
self.bots = {}
self.clients = {}
self.clients = defaultdict(set)
NetworkStore.on('create', self.on_network_create)
NetworkStore.on('update', self.on_network_update)

Expand Down Expand Up @@ -220,22 +221,19 @@ def register_bot(self, network_id, bot):
if existing_bot:
existing_bot.protocol.transport.close()
del self.bots[key]
bot.clients = self.clients.get(key, set())
bot.clients = self.clients[key]
self.bots[key] = bot
logger.debug('Bots: %s', self.bots)

def register_client(self, network_id, client):
key = network_id
clients = self.clients.get(key)
if clients is None:
clients = set()
self.clients[key] = clients
clients = self.clients[key]
clients.add(client)
logger.debug('Registered new client: %s, %s', key, clients)

def unregister_client(self, network_id, client):
key = network_id
clients = self.clients.get(key)
clients = self.clients[key]
logger.debug('Unregistering client: {}'.format(client))
try:
clients.remove(client)
Expand Down

0 comments on commit 6dd53ab

Please sign in to comment.