Initial config file implementation. Doesn't include nickname.

This commit is contained in:
Steve Dougherty 2012-03-03 01:41:51 -05:00
parent f272e61df6
commit 0918c915f5
3 changed files with 32 additions and 13 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
*.log *.log
*.pid *.pid
*.pyc *.pyc
*.config

17
relaybot.config_sample Normal file
View File

@ -0,0 +1,17 @@
#Can override these defaults per-section.
[DEFAULT]
#Twisted's default is 30 seconds.
timeout=120
port=6667
channel=#a-bridged-channel
#Can change to allow more specialized behavior.
mode=Default
#Response sent when addressed with <nickname>: or privmsg'd.
info=This is a relay bot.
[Freenode]
host=irc.freenode.net
[Umich]
host=irc.umich.edu

View File

@ -5,6 +5,7 @@ from twisted.python import log
from twisted.internet.endpoints import clientFromString from twisted.internet.endpoints import clientFromString
from twisted.application import service from twisted.application import service
from signal import signal, SIGINT from signal import signal, SIGINT
from ConfigParser import SafeConfigParser
import re, sys import re, sys
# #
@ -17,19 +18,19 @@ __version__ = "0.1"
application = service.Application("RelayBot") application = service.Application("RelayBot")
def main(): def main():
host = "localhost" config = SafeConfigParser()
timeout = 120 config.read("relaybot.config")
defaults = config.defaults()
preamble = "This is a bot which relays traffic between #i2p-bridge on FLIP and #flip-bridge on I2Prc. " for section in config.sections():
timeout = config.get(section, "timeout") or defaults["timeout"]
contactFreenet = "Freemail: operhiem1@oblda5d6jfleur3uomyws52uljrvo4l2jbuwcwsuk54tcn3qi5ehqwlsojvdaytcjnseslbnki3fozckj5ztaqkblb3gw3dwmreeg6dhk5te2ncyj55hgmkmkq4xoytworgdkrdpgvvsyqkrifbucqkf.freemail" host = config.get(section, "host") or defaults["host"]
port = config.get(section, "port") or defaults["port"]
contactI2P = "I2P-bote: operhiem1@QcTYSRYota-9WDSgfoUfaOkeSiPc7cyBuHqbgJ28YmilVk66-n1U1Zf1sCwTS2eDxlk4iwMZuufRmATsPJdkipw4EuRfaHLXKktwtkSTXNhciDsTMgJn7Ka14ayVuuPiF2tKzyaCTV4H2vc7sUkOKLsH9lyccVnFdYOnL~bkZiCGDI" channel = config.get(section, "channel") or defaults["channel"]
privReply = config.get(section, "info") or defaults["info"]
#Configure channels here: kind = config.get(section, "mode") or defaults["mode"]
#Tuple order is (hostname or IP, port, response when privmsg'd or referred to in chat, special behavior)
for host, port, channel, privReply, kind in [(host, 6667, "#i2p-bridge", preamble+contactFreenet, "FLIP"),\ print(section, timeout, host, port, channel, privReply, kind)
(host, 6669, "#test-lol", preamble+contactI2P, None)]:
#Not using endpoints pending http://twistedmatrix.com/trac/ticket/4735 #Not using endpoints pending http://twistedmatrix.com/trac/ticket/4735
#(ReconnectingClientFactory equivalent for endpoints.) #(ReconnectingClientFactory equivalent for endpoints.)
@ -39,7 +40,7 @@ def main():
else: else:
factory = RelayFactory(host, channel, privReply, port) factory = RelayFactory(host, channel, privReply, port)
reactor.connectTCP(host, port, factory, timeout) reactor.connectTCP(host, int(port), factory, int(timeout))
reactor.callWhenRunning(signal, SIGINT, handler) reactor.callWhenRunning(signal, SIGINT, handler)