Skip to content

Commit

Permalink
Make realname and username configurable
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
Katorone authored and johnmaguire committed Aug 27, 2019
1 parent 1e7a69b commit 5e88a01
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
14 changes: 14 additions & 0 deletions cardinal.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
help='set this flag to get a password prompt for '
'identifying')

arg_parser.add_argument('-u', '--username', metavar='username',
help='username (ident) of the bot')

arg_parser.add_argument('-r', '--realname', metavar='realname',
help='Real name of the bot')

arg_parser.add_argument('-i', '--network', metavar='network',
help='network to connect to')

Expand All @@ -58,6 +64,8 @@
spec = ConfigSpec()
spec.add_option('nickname', basestring, 'Cardinal')
spec.add_option('password', basestring, None)
spec.add_option('username', basestring, None)
spec.add_option('realname', basestring, None)
spec.add_option('network', basestring, 'irc.freenode.net')
spec.add_option('port', int, 6667)
spec.add_option('server_password', basestring, None)
Expand Down Expand Up @@ -153,11 +161,17 @@

os.makedirs(directory)

"""If no username is supplied, set it to the nickname. """
if config['username'] is None:
config['username'] = config['nickname']

# Instance a new factory, and connect with/without SSL
logger.debug("Instantiating CardinalBotFactory")
factory = CardinalBotFactory(config['network'], config['server_password'],
config['channels'],
config['nickname'], config['password'],
config['username'],
config['realname'],
config['plugins'],
storage_path)

Expand Down
28 changes: 25 additions & 3 deletions cardinal/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ def password(self):
def password(self, value):
self.factory.server_password = value

@property
def username(self):
return self.factory.username

@username.setter
def username(self, value):
self.factory.username = value

@property
def realname(self):
return self.factory.realname

@realname.setter
def realname(self, value):
self.factory.realname = value

@property
def reloads(self):
return self.factory.reloads
Expand Down Expand Up @@ -451,17 +467,21 @@ class CardinalBotFactory(protocol.ClientFactory):
"""Maximum time in connections before reconnection attempt"""

def __init__(self, network, server_password=None, channels=None,
nickname='Cardinal', password=None, plugins=None,
storage=None):
nickname='Cardinal', password=None, username=None,
realname=None, plugins=None, storage=None):
"""Boots the bot, triggers connection, and initializes logging.
Keyword arguments:
network -- A string containing the server to connect to.
channels -- A list of channels to connect to.
nickname -- A string with the nick to connect as.
password -- A string with NickServ password, if any.
username -- A string with the ident to be used.
realname -- A string containing the real name field.
plugins -- A list of plugins to load on boot.
storage -- A string containing path to storage directory.
"""

if plugins is None:
plugins = []

Expand All @@ -471,9 +491,11 @@ def __init__(self, network, server_password=None, channels=None,
self.logger = logging.getLogger(__name__)
self.network = network.lower()
self.server_password = server_password
self.password = password
self.channels = channels
self.nickname = nickname
self.password = password
self.username = username
self.realname = realname
self.plugins = plugins
self.storage_path = storage

Expand Down
2 changes: 2 additions & 0 deletions config/config.docker.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"nickname": "Cardinal",
"password": "NICKSERV PASSWORD",
"username": "cardinal",
"realname": "Another IRC bot",
"network": "irc.darkscience.net",
"server_password": "SERVER PASSWORD (IF NECESSARY)",
"port": 6697,
Expand Down
2 changes: 2 additions & 0 deletions config/config.example.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"nickname": "Cardinal",
"password": "NICKSERV PASSWORD",
"username": "cardinal",
"realname": "Another IRC bot",
"network": "irc.darkscience.net",
"server_password": "SERVER PASSWORD (IF NECESSARY)",
"port": 6697,
Expand Down

0 comments on commit 5e88a01

Please sign in to comment.