diff --git a/redminebot.py b/redminebot.py index d3c07c7..89fca71 100755 --- a/redminebot.py +++ b/redminebot.py @@ -9,15 +9,26 @@ import xml.dom.minidom from time import mktime, localtime import iso8601 +import ConfigParser - -# IRC configuration - -default_server = "irc.eu.freenode.net" -default_nickname = "agirbot" +# Help configuration. help_list = ["help", "faq", "aide"] hello_list = ["hello", "yo", "bonjour", "salut"] -registered = True + +# Load configuration. +configurationFilename="/etc/redminebot/redminebot.conf" +if os.path.isfile(configurationFilename): + config = ConfigParser.RawConfigParser() + config.read(configurationFilename) + + default_server=config.get('IRCSection', 'irc.server') + default_nickname=config.get('IRCSection', 'irc.nickname'); + registered=config.get('IRCSection', 'irc.registered'); + password=config.get('IRCSection', 'irc.password'); +else: + print "Missing configuration file." + sys.exit() + ######################### ### Class Definitions ### @@ -72,12 +83,10 @@ class Bot(object): self.ircsock.send("USER {0} {0} {0} :Robot Agir April" ".\n".format(self.botnick)) # bot authentication self.ircsock.send("NICK {}\n".format(self.botnick)) # Assign the nick to the bot. - if os.path.isfile("password.txt"): - with open("password.txt", 'r') as f: - password = f.read() - if registered == True: - print("PRIVMSG {} {} {}".format("NickServ","IDENTIFY",password)) - self.ircsock.send("PRIVMSG {} :{} {} {}".format("NickServ","IDENTIFY", self.botnick, password)) + + if not password.strip() and registered == True: + print("PRIVMSG {} {} {}".format("NickServ","IDENTIFY",password)) + self.ircsock.send("PRIVMSG {} :{} {} {}".format("NickServ","IDENTIFY", self.botnick, password)) def add_project(self, project): project.set_ircsock ( self.ircsock )