Externalized configuration in /etc/redminebot/ file.

This commit is contained in:
Christian P. MOMON 2019-08-22 01:33:25 +02:00 committed by root
parent 404ec1bd46
commit 0bad25ed8c

View File

@ -9,15 +9,26 @@ import xml.dom.minidom
from time import mktime, localtime from time import mktime, localtime
import iso8601 import iso8601
import ConfigParser
# Help configuration.
# IRC configuration
default_server = "irc.eu.freenode.net"
default_nickname = "agirbot"
help_list = ["help", "faq", "aide"] help_list = ["help", "faq", "aide"]
hello_list = ["hello", "yo", "bonjour", "salut"] 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 ### ### Class Definitions ###
@ -72,12 +83,10 @@ class Bot(object):
self.ircsock.send("USER {0} {0} {0} :Robot Agir April" self.ircsock.send("USER {0} {0} {0} :Robot Agir April"
".\n".format(self.botnick)) # bot authentication ".\n".format(self.botnick)) # bot authentication
self.ircsock.send("NICK {}\n".format(self.botnick)) # Assign the nick to the bot. 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: if not password.strip() and registered == True:
password = f.read() print("PRIVMSG {} {} {}".format("NickServ","IDENTIFY",password))
if registered == True: self.ircsock.send("PRIVMSG {} :{} {} {}".format("NickServ","IDENTIFY", self.botnick, password))
print("PRIVMSG {} {} {}".format("NickServ","IDENTIFY",password))
self.ircsock.send("PRIVMSG {} :{} {} {}".format("NickServ","IDENTIFY", self.botnick, password))
def add_project(self, project): def add_project(self, project):
project.set_ircsock ( self.ircsock ) project.set_ircsock ( self.ircsock )