Skip to content

Commit 3af1bec

Browse files
committed
Add client class registration
1 parent 9bfdbca commit 3af1bec

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

cloudbot/client.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77

88
logger = logging.getLogger("cloudbot")
99

10+
CLIENTS = {}
11+
12+
13+
def client(_type):
14+
def _decorate(cls):
15+
CLIENTS[_type] = cls
16+
cls._type = _type
17+
return cls
18+
19+
return lambda cls: _decorate(cls)
20+
1021

1122
class Client:
1223
"""
@@ -22,6 +33,8 @@ class Client:
2233
:type permissions: PermissionManager
2334
"""
2435

36+
_type = None
37+
2538
def __init__(self, bot, name, nick, *, channels=None, config=None):
2639
"""
2740
:type bot: cloudbot.bot.CloudBot
@@ -155,3 +168,7 @@ def is_nick_valid(self, nick):
155168
@property
156169
def connected(self):
157170
raise NotImplementedError
171+
172+
@property
173+
def type(self):
174+
return self._type

cloudbot/clients/irc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from functools import partial
88
from ssl import SSLContext
99

10-
from cloudbot.client import Client
10+
from cloudbot.client import Client, client
1111
from cloudbot.event import Event, EventType, IrcOutEvent
1212
from cloudbot.util import async_util
1313
from cloudbot.util.parsers.irc import Message
@@ -50,6 +50,7 @@ def decode(bytestring):
5050
return bytestring.decode('utf-8', errors='ignore')
5151

5252

53+
@client("irc")
5354
class IrcClient(Client):
5455
"""
5556
An implementation of Client for IRC.

0 commit comments

Comments
 (0)