mirror of https://github.com/str4d/RelayBot.git
Whitespace.
This commit is contained in:
parent
a0cbff26af
commit
3e516c9d70
48
relaybot.py
48
relaybot.py
|
@ -21,21 +21,21 @@ def main():
|
||||||
config = SafeConfigParser()
|
config = SafeConfigParser()
|
||||||
config.read("relaybot.config")
|
config.read("relaybot.config")
|
||||||
defaults = config.defaults()
|
defaults = config.defaults()
|
||||||
|
|
||||||
for section in config.sections():
|
for section in config.sections():
|
||||||
|
|
||||||
def get(option):
|
def get(option):
|
||||||
if option in defaults or config.has_option(section, option):
|
if option in defaults or config.has_option(section, option):
|
||||||
return config.get(section, option) or defaults[option]
|
return config.get(section, option) or defaults[option]
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
options = {}
|
options = {}
|
||||||
for option in [ "timeout", "host", "port", "nick", "channel", "info", "heartbeat", "password" ]:
|
for option in [ "timeout", "host", "port", "nick", "channel", "info", "heartbeat", "password" ]:
|
||||||
options[option] = get(option)
|
options[option] = get(option)
|
||||||
|
|
||||||
mode = get("mode")
|
mode = get("mode")
|
||||||
|
|
||||||
#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.)
|
||||||
factory = None
|
factory = None
|
||||||
|
@ -46,10 +46,10 @@ def main():
|
||||||
elif mode == "NickServ":
|
elif mode == "NickServ":
|
||||||
factory = NickServFactory
|
factory = NickServFactory
|
||||||
options["nickServPassword"] = get("nickServPassword")
|
options["nickServPassword"] = get("nickServPassword")
|
||||||
|
|
||||||
factory = factory(options)
|
factory = factory(options)
|
||||||
reactor.connectTCP(options['host'], int(options['port']), factory, int(options['timeout']))
|
reactor.connectTCP(options['host'], int(options['port']), factory, int(options['timeout']))
|
||||||
|
|
||||||
reactor.callWhenRunning(signal, SIGINT, handler)
|
reactor.callWhenRunning(signal, SIGINT, handler)
|
||||||
|
|
||||||
class Communicator:
|
class Communicator:
|
||||||
|
@ -81,7 +81,7 @@ communicator = Communicator()
|
||||||
class IRCRelayer(irc.IRCClient):
|
class IRCRelayer(irc.IRCClient):
|
||||||
realname = "Relay P. Botternson"
|
realname = "Relay P. Botternson"
|
||||||
username = "RelayBot"
|
username = "RelayBot"
|
||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.network = config['host']
|
self.network = config['host']
|
||||||
self.password = config['password']
|
self.password = config['password']
|
||||||
|
@ -102,18 +102,18 @@ class IRCRelayer(irc.IRCClient):
|
||||||
log.msg("[%s] Connected to network."%self.network)
|
log.msg("[%s] Connected to network."%self.network)
|
||||||
self.startHeartbeat()
|
self.startHeartbeat()
|
||||||
self.join(self.channel, "")
|
self.join(self.channel, "")
|
||||||
|
|
||||||
def connectionLost(self, reason):
|
def connectionLost(self, reason):
|
||||||
log.msg("[%s] Connection lost, unregistering."%self.network)
|
log.msg("[%s] Connection lost, unregistering."%self.network)
|
||||||
communicator.unregister(self)
|
communicator.unregister(self)
|
||||||
|
|
||||||
def twoWaySay(self, message, args=None):
|
def twoWaySay(self, message, args=None):
|
||||||
self.say(self.channel, message)
|
self.say(self.channel, message)
|
||||||
|
|
||||||
def joined(self, channel):
|
def joined(self, channel):
|
||||||
log.msg("Joined channel %s, registering."%channel)
|
log.msg("Joined channel %s, registering."%channel)
|
||||||
communicator.register(self)
|
communicator.register(self)
|
||||||
|
|
||||||
def privmsg(self, user, channel, message):
|
def privmsg(self, user, channel, message):
|
||||||
#If someone addresses the bot directly, respond in the same way.
|
#If someone addresses the bot directly, respond in the same way.
|
||||||
if channel == self.nickname:
|
if channel == self.nickname:
|
||||||
|
@ -125,36 +125,36 @@ class IRCRelayer(irc.IRCClient):
|
||||||
self.say(self.channel, self.privMsgResponse)
|
self.say(self.channel, self.privMsgResponse)
|
||||||
#For consistancy, if anyone responds to the bot's response:
|
#For consistancy, if anyone responds to the bot's response:
|
||||||
self.relay("[%s] %s"%(self.formatUsername(self.nickname), self.privMsgResponse))
|
self.relay("[%s] %s"%(self.formatUsername(self.nickname), self.privMsgResponse))
|
||||||
|
|
||||||
def kickedFrom(self, channel, kicker, message):
|
def kickedFrom(self, channel, kicker, message):
|
||||||
log.msg("Kicked by %s. Message \"%s\""%(kicker, message))
|
log.msg("Kicked by %s. Message \"%s\""%(kicker, message))
|
||||||
communicator.unregister(self)
|
communicator.unregister(self)
|
||||||
|
|
||||||
def userJoined(self, user, channel):
|
def userJoined(self, user, channel):
|
||||||
self.relay("%s joined."%self.formatUsername(user))
|
self.relay("%s joined."%self.formatUsername(user))
|
||||||
|
|
||||||
def userLeft(self, user, channel):
|
def userLeft(self, user, channel):
|
||||||
self.relay("%s left."%self.formatUsername(user))
|
self.relay("%s left."%self.formatUsername(user))
|
||||||
|
|
||||||
def userQuit(self, user, quitMessage):
|
def userQuit(self, user, quitMessage):
|
||||||
self.relay("%s quit. (%s)"%(self.formatUsername(user), quitMessage))
|
self.relay("%s quit. (%s)"%(self.formatUsername(user), quitMessage))
|
||||||
|
|
||||||
def action(self, user, channel, data):
|
def action(self, user, channel, data):
|
||||||
self.relay("* %s %s"%(self.formatUsername(user), data))
|
self.relay("* %s %s"%(self.formatUsername(user), data))
|
||||||
|
|
||||||
def userRenamed(self, oldname, newname):
|
def userRenamed(self, oldname, newname):
|
||||||
self.relay("%s is now known as %s."%(self.formatUsername(oldname), self.formatUsername(newname)))
|
self.relay("%s is now known as %s."%(self.formatUsername(oldname), self.formatUsername(newname)))
|
||||||
|
|
||||||
|
|
||||||
class RelayFactory(ReconnectingClientFactory):
|
class RelayFactory(ReconnectingClientFactory):
|
||||||
protocol = IRCRelayer
|
protocol = IRCRelayer
|
||||||
#Log information which includes reconnection status.
|
#Log information which includes reconnection status.
|
||||||
noisy = True
|
noisy = True
|
||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
config["identifier"] = "{0}{1}{2}".format(config["host"], config["port"], config["channel"])
|
config["identifier"] = "{0}{1}{2}".format(config["host"], config["port"], config["channel"])
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
def buildProtocol(self, addr):
|
def buildProtocol(self, addr):
|
||||||
#Connected - reset reconnect attempt delay.
|
#Connected - reset reconnect attempt delay.
|
||||||
self.resetDelay()
|
self.resetDelay()
|
||||||
|
@ -213,7 +213,7 @@ class NickServRelayer(SilentJoinPart):
|
||||||
self.join(self.channel, "")
|
self.join(self.channel, "")
|
||||||
else:
|
else:
|
||||||
log.msg("[%s] Recieved notice \"%s\" from %s."%(self.network, message, user))
|
log.msg("[%s] Recieved notice \"%s\" from %s."%(self.network, message, user))
|
||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
IRCRelayer.__init__(self, config)
|
IRCRelayer.__init__(self, config)
|
||||||
#super(NickServRelayer, self).__init__(config)
|
#super(NickServRelayer, self).__init__(config)
|
||||||
|
@ -225,7 +225,7 @@ class NickServFactory(RelayFactory):
|
||||||
protocol = NickServRelayer
|
protocol = NickServRelayer
|
||||||
|
|
||||||
def handler(signum, frame):
|
def handler(signum, frame):
|
||||||
reactor.stop()
|
reactor.stop()
|
||||||
|
|
||||||
#Main if run as script, builtin for twistd.
|
#Main if run as script, builtin for twistd.
|
||||||
if __name__ in ["__main__", "__builtin__"]:
|
if __name__ in ["__main__", "__builtin__"]:
|
||||||
|
|
Loading…
Reference in New Issue