b3DeployListen.py
· 1.7 KiB · Python
Raw
from twisted.words.protocols import irc
from twisted.internet import protocol, task, reactor
from twisted.application import internet, service
import subprocess
nick = "Nexus"
user = "Nexus"
passw = "bouncer password"
jenkins_nick = "HawkJenkins"
jenkins_job = "Nexus"
script_path = "/home/nexus/redeploy.sh"
channel = "#DSH105" # channel script will try to join
server = "bouncer.bounce" # irc server or bouncer
port = 5555 # if changed, else 6667
class Bot(irc.IRCClient):
nickname = nick
username = user
password = passw
def signedOn(self):
print "Signed on as %s." % self.nickname
def privmsg(self, user, channel, msg):
nick, _, host = user.partition("!")
trigger_phrase = "Project %s build" % jenkins_job
if nick == jenkins_nick and trigger_phrase in msg and "SUCCESS" in msg:
out = subprocess.check_output([script_path])
self.msg(channel, "Starting redeploy (triggered by %s)... " % jenkins_nick + out)
class BotFactory(protocol.ClientFactory):
protocol = Bot
def __init__(self, channel):
self.channel = channel
def clientConnectionLost(self, connector, reason):
print "Lost connection (%s), reconnecting." % (reason,)
connector.connect()
def clientConnectionFailed(self, connector, reason):
print "Could not connect: %s" % (reason,)
if __name__ == "__main__":
channel = channel
reactor.connectTCP(server, port, BotFactory(channel))
reactor.run()
elif __name__ == '__builtin__':
application = service.Application('H365IRCBot')
channel = channel
ircService = internet.TCPClient(server, port, BotFactory(channel))
ircService.setServiceParent(application)
| 1 | from twisted.words.protocols import irc |
| 2 | from twisted.internet import protocol, task, reactor |
| 3 | from twisted.application import internet, service |
| 4 | import subprocess |
| 5 | |
| 6 | nick = "Nexus" |
| 7 | user = "Nexus" |
| 8 | passw = "bouncer password" |
| 9 | jenkins_nick = "HawkJenkins" |
| 10 | jenkins_job = "Nexus" |
| 11 | script_path = "/home/nexus/redeploy.sh" |
| 12 | |
| 13 | channel = "#DSH105" # channel script will try to join |
| 14 | server = "bouncer.bounce" # irc server or bouncer |
| 15 | port = 5555 # if changed, else 6667 |
| 16 | |
| 17 | class Bot(irc.IRCClient): |
| 18 | nickname = nick |
| 19 | username = user |
| 20 | password = passw |
| 21 | |
| 22 | def signedOn(self): |
| 23 | print "Signed on as %s." % self.nickname |
| 24 | |
| 25 | def privmsg(self, user, channel, msg): |
| 26 | nick, _, host = user.partition("!") |
| 27 | trigger_phrase = "Project %s build" % jenkins_job |
| 28 | if nick == jenkins_nick and trigger_phrase in msg and "SUCCESS" in msg: |
| 29 | out = subprocess.check_output([script_path]) |
| 30 | self.msg(channel, "Starting redeploy (triggered by %s)... " % jenkins_nick + out) |
| 31 | |
| 32 | class BotFactory(protocol.ClientFactory): |
| 33 | protocol = Bot |
| 34 | |
| 35 | def __init__(self, channel): |
| 36 | self.channel = channel |
| 37 | |
| 38 | def clientConnectionLost(self, connector, reason): |
| 39 | print "Lost connection (%s), reconnecting." % (reason,) |
| 40 | connector.connect() |
| 41 | |
| 42 | def clientConnectionFailed(self, connector, reason): |
| 43 | print "Could not connect: %s" % (reason,) |
| 44 | |
| 45 | if __name__ == "__main__": |
| 46 | channel = channel |
| 47 | reactor.connectTCP(server, port, BotFactory(channel)) |
| 48 | reactor.run() |
| 49 | elif __name__ == '__builtin__': |
| 50 | application = service.Application('H365IRCBot') |
| 51 | channel = channel |
| 52 | ircService = internet.TCPClient(server, port, BotFactory(channel)) |
| 53 | ircService.setServiceParent(application) |
| 54 |