From 1d4350c4fd00e7f8012781992ab73a1b73f396d2 Mon Sep 17 00:00:00 2001 From: James Lu Date: Sat, 19 Mar 2016 17:01:39 -0700 Subject: [PATCH] classes: provide IrcChannel objects with their own name using KeyedDefaultdict Closes #171. --- classes.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/classes.py b/classes.py index ec379a8..84c18d7 100644 --- a/classes.py +++ b/classes.py @@ -13,7 +13,6 @@ import time import socket import threading import ssl -from collections import defaultdict import hashlib from copy import deepcopy @@ -112,7 +111,7 @@ class Irc(): internal=True, desc=self.serverdata.get('serverdesc') or self.botdata['serverdesc'])} self.users = {} - self.channels = defaultdict(IrcChannel) + self.channels = utils.KeyedDefaultdict(IrcChannel) # This sets the list of supported channel and user modes: the default # RFC1459 modes are implied. Named modes are used here to make @@ -568,7 +567,7 @@ class IrcServer(): class IrcChannel(): """PyLink IRC channel class.""" - def __init__(self): + def __init__(self, name=None): # Initialize variables, such as the topic, user list, TS, who's opped, etc. self.users = set() self.modes = {('n', None), ('t', None)} @@ -581,6 +580,9 @@ class IrcChannel(): # should set this. self.topicset = False + # Saves the channel name (may be useful to plugins, etc.) + self.name = name + def __repr__(self): return 'IrcChannel(%s)' % self.__dict__