[FEATURE] Add nickserv support, add bot mode.

This commit is contained in:
Jan Philipp Timme 2015-06-01 18:25:01 +02:00
parent 8180ffb826
commit 6c7f4006b1
2 changed files with 8 additions and 2 deletions

View File

@ -26,6 +26,9 @@ class MonitorBot(irc.IRCClient):
# callbacks for events # callbacks for events
def signedOn(self): def signedOn(self):
"""Called when bot has succesfully signed on to server.""" """Called when bot has succesfully signed on to server."""
print("[signed in]")
self.msg('NickServ', 'IDENTIFY %s' % self.factory.nickserv_pw)
self.mode(self.nickname, True, 'B')
self.join(self.factory.channel) self.join(self.factory.channel)
def joined(self, channel): def joined(self, channel):
@ -42,9 +45,10 @@ class MonitorBotFactory(protocol.ClientFactory):
A new protocol instance will be created each time we connect to the server. A new protocol instance will be created each time we connect to the server.
""" """
def __init__(self, nickname, channel, fsmon): def __init__(self, nickname, channel, nickserv_pw, fsmon):
self.nickname = nickname self.nickname = nickname
self.channel = channel self.channel = channel
self.nickserv_pw = nickserv_pw
self.fsmon = fsmon self.fsmon = fsmon
def buildProtocol(self, addr): def buildProtocol(self, addr):
@ -138,13 +142,14 @@ if __name__ == '__main__':
port = int(config.get('irc', 'port')) port = int(config.get('irc', 'port'))
channel = config.get('irc', 'channel') channel = config.get('irc', 'channel')
nickname = config.get('irc', 'nickname') nickname = config.get('irc', 'nickname')
nickserv_pw = config.get('irc', 'nickserv_pw')
realname = config.get('irc', 'realname') realname = config.get('irc', 'realname')
path = config.get('fsmonitor', 'path') path = config.get('fsmonitor', 'path')
fsmon = FSMonitor(path, channel) fsmon = FSMonitor(path, channel)
# create factory protocol and application # create factory protocol and application
f = MonitorBotFactory(nickname, channel, fsmon) f = MonitorBotFactory(nickname, channel, nickserv_pw, fsmon)
# connect factory to this host and port # connect factory to this host and port
reactor.connectTCP(host, port, f) reactor.connectTCP(host, port, f)

View File

@ -4,6 +4,7 @@ port = 6667
nickName = FDS-kun nickName = FDS-kun
realName = bot: provides tracking of an ftp folder realName = bot: provides tracking of an ftp folder
channel = #JPT channel = #JPT
nickserv_pw = secret
[fsmonitor] [fsmonitor]
path=/tmp/foobar/ path=/tmp/foobar/