Skip to content

Commit 5e88a01

Browse files
Katoronejohnmaguire
authored andcommitted
Make realname and username configurable
These are only configurable prior to connection to the server. If you modify cardinal.username and/or cardinal.realname, they will be updated if Cardinal reconnects to the server (e.g. due to a server disconnection or calling .dbg_quit)
1 parent 1e7a69b commit 5e88a01

4 files changed

Lines changed: 43 additions & 3 deletions

File tree

cardinal.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
help='set this flag to get a password prompt for '
3434
'identifying')
3535

36+
arg_parser.add_argument('-u', '--username', metavar='username',
37+
help='username (ident) of the bot')
38+
39+
arg_parser.add_argument('-r', '--realname', metavar='realname',
40+
help='Real name of the bot')
41+
3642
arg_parser.add_argument('-i', '--network', metavar='network',
3743
help='network to connect to')
3844

@@ -58,6 +64,8 @@
5864
spec = ConfigSpec()
5965
spec.add_option('nickname', basestring, 'Cardinal')
6066
spec.add_option('password', basestring, None)
67+
spec.add_option('username', basestring, None)
68+
spec.add_option('realname', basestring, None)
6169
spec.add_option('network', basestring, 'irc.freenode.net')
6270
spec.add_option('port', int, 6667)
6371
spec.add_option('server_password', basestring, None)
@@ -153,11 +161,17 @@
153161

154162
os.makedirs(directory)
155163

164+
"""If no username is supplied, set it to the nickname. """
165+
if config['username'] is None:
166+
config['username'] = config['nickname']
167+
156168
# Instance a new factory, and connect with/without SSL
157169
logger.debug("Instantiating CardinalBotFactory")
158170
factory = CardinalBotFactory(config['network'], config['server_password'],
159171
config['channels'],
160172
config['nickname'], config['password'],
173+
config['username'],
174+
config['realname'],
161175
config['plugins'],
162176
storage_path)
163177

cardinal/bot.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ def password(self):
4747
def password(self, value):
4848
self.factory.server_password = value
4949

50+
@property
51+
def username(self):
52+
return self.factory.username
53+
54+
@username.setter
55+
def username(self, value):
56+
self.factory.username = value
57+
58+
@property
59+
def realname(self):
60+
return self.factory.realname
61+
62+
@realname.setter
63+
def realname(self, value):
64+
self.factory.realname = value
65+
5066
@property
5167
def reloads(self):
5268
return self.factory.reloads
@@ -451,17 +467,21 @@ class CardinalBotFactory(protocol.ClientFactory):
451467
"""Maximum time in connections before reconnection attempt"""
452468

453469
def __init__(self, network, server_password=None, channels=None,
454-
nickname='Cardinal', password=None, plugins=None,
455-
storage=None):
470+
nickname='Cardinal', password=None, username=None,
471+
realname=None, plugins=None, storage=None):
456472
"""Boots the bot, triggers connection, and initializes logging.
457473
458474
Keyword arguments:
459475
network -- A string containing the server to connect to.
460476
channels -- A list of channels to connect to.
461477
nickname -- A string with the nick to connect as.
462478
password -- A string with NickServ password, if any.
479+
username -- A string with the ident to be used.
480+
realname -- A string containing the real name field.
463481
plugins -- A list of plugins to load on boot.
482+
storage -- A string containing path to storage directory.
464483
"""
484+
465485
if plugins is None:
466486
plugins = []
467487

@@ -471,9 +491,11 @@ def __init__(self, network, server_password=None, channels=None,
471491
self.logger = logging.getLogger(__name__)
472492
self.network = network.lower()
473493
self.server_password = server_password
474-
self.password = password
475494
self.channels = channels
476495
self.nickname = nickname
496+
self.password = password
497+
self.username = username
498+
self.realname = realname
477499
self.plugins = plugins
478500
self.storage_path = storage
479501

config/config.docker.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"nickname": "Cardinal",
33
"password": "NICKSERV PASSWORD",
4+
"username": "cardinal",
5+
"realname": "Another IRC bot",
46
"network": "irc.darkscience.net",
57
"server_password": "SERVER PASSWORD (IF NECESSARY)",
68
"port": 6697,

config/config.example.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"nickname": "Cardinal",
33
"password": "NICKSERV PASSWORD",
4+
"username": "cardinal",
5+
"realname": "Another IRC bot",
46
"network": "irc.darkscience.net",
57
"server_password": "SERVER PASSWORD (IF NECESSARY)",
68
"port": 6697,

0 commit comments

Comments
 (0)