summaryrefslogtreecommitdiff
path: root/deployerbot.py
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2015-01-24 20:27:53 -0800
committerJesse Morgan <jesse@jesterpm.net>2015-01-24 20:27:53 -0800
commitcca6829caed96fff5ecceb9c89b4eb2942c264f5 (patch)
treeb9e263d392c8425a7cce9d188b66677f1abe644f /deployerbot.py
parent92af71570ab35143c8edab7f45520408751bf3c6 (diff)
Adding the basic shell for the deployer bot.
Diffstat (limited to 'deployerbot.py')
-rw-r--r--deployerbot.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/deployerbot.py b/deployerbot.py
new file mode 100644
index 0000000..eced411
--- /dev/null
+++ b/deployerbot.py
@@ -0,0 +1,76 @@
+#!/usr/bin/python
+import re
+
+"""
+DeployerBot sends fires webhooks on command. Although you could really do
+anything with a webhook, the intent is to trigger deployments. Therefore the
+webhooks are designed mimic GitHub push events.
+
+DeployerBot responds to private messages or channel messages prefixed with the
+bot's nick. It will respond to the follow commands:
+
+ * deploy <application>
+ * list webhooks
+ * add webhook for <application> with url <url> and secret <secret>
+ * remove webhook for <application>
+"""
+class DeployerBot:
+ def __init__(self, expiry=1800):
+ self.__name__ = "DeployerBot"
+ self.__version__ = "0.0.1"
+ self.deploy_pattern = re.compile(r"deploy (?:(?:the )?application )?(\S+)", re.IGNORECASE)
+ self.list_pattern = re.compile(r"list (?:.* )?webhooks", re.IGNORECASE);
+ self.add_pattern = re.compile(r"add (?:.* )?webhook (?:(?:.* )?(?:application|for) )?(\S+) (?:(?:.* )?(?:url|address) )?(\S+) (?:(?:.* )secret )?(\S+)", re.IGNORECASE)
+
+ self.applications = dict()
+
+ def onPrivMsg(self, IRC, user, msg):
+ self.processMsg(IRC, user, user, msg)
+
+ def onChanMsg(self, IRC, user, channel, targetprefix, msg):
+ name_pattern = r"^" + re.escape(IRC.identity.nick) + r"[,:! ]"
+ if re.match(name_pattern, msg, re.IGNORECASE):
+ self.processMsg(IRC, user, channel, msg)
+
+ """
+ Process a message addressed to the bot.
+ * IRC is the main IRC object.
+ * sender is the User object representing the sender.
+ * dest is where to send the response. It may be any object with a msg method.
+ * msg is the message received.
+ """
+ def processMsg(self, IRC, sender, dest, msg):
+ matches = self.deploy_pattern.findall(msg)
+ if matches is not None:
+ for application in matches:
+ self.deploy(IRC, sender, dest, application)
+ return
+
+ if self.list_pattern.findall(msg):
+ self.listWebHooks(IRC, sender, dest)
+ return
+
+ matches = self.add_pattern.findall(msg)
+ if matches is not None:
+ for application, url, secret in matches:
+ self.addApplication(IRC, sender, dest, application, url, secret)
+ return
+
+ def deploy(self, IRC, sender, dest, application):
+ dest.msg("Ok, I will deploy %s" % application)
+
+
+ def listWebHooks(self, IRC, sender, dest):
+ if self.applications:
+ msg = "I know the following applications: " + ", ".join([app for (app, url, key) in self.applications.values()])
+ dest.msg(msg)
+ else:
+ dest.msg("I don't have any hooks :(")
+
+ def addApplication(self, IRC, sender, dest, application, url, secret):
+ key = application.lower()
+ if key in self.applications:
+ dest.msg("I already have an application called %s" % application)
+ else:
+ self.applications[key] = (application, url, secret)
+ dest.msg("I've added application %s" % application)