[gnome-continuous/wip/new-bot] Reimplement IRC bot based on twisted Reimplement IRC bot based on twisted



commit d4980a3483bee315db7416dfc9d0318fa659bd24
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Sun Sep 29 13:45:20 2013 -0400

    Reimplement IRC bot based on twisted Reimplement IRC bot based on twisted

 .../GNOMEOSTree/plugin.py => ircbot/bot.py}        |   58 ++++++++++++++------
 extras/supybot/GNOMEOSTree/__init__.py             |   11 ----
 extras/supybot/GNOMEOSTree/config.py               |    7 ---
 3 files changed, 42 insertions(+), 34 deletions(-)
---
diff --git a/extras/supybot/GNOMEOSTree/plugin.py b/extras/ircbot/bot.py
similarity index 80%
rename from extras/supybot/GNOMEOSTree/plugin.py
rename to extras/ircbot/bot.py
index bb2e9fb..294a3e1 100644
--- a/extras/supybot/GNOMEOSTree/plugin.py
+++ b/extras/ircbot/bot.py
@@ -28,20 +28,29 @@
 # POSSIBILITY OF SUCH DAMAGE.
 ###
 
+HOST = "irc.gnome.org"
+PORT = 6667
+
 import itertools
 import os
 import json
 
-import supybot.ircmsgs as ircmsgs
-import supybot.ircutils as ircutils
-import supybot.schedule as schedule
-import supybot.callbacks as callbacks
+from twisted.internet import protocol, task
+from twisted.words.protocols import irc
+from twisted.application import internet, service
+
+def mirc_color(code, S):
+    return "\x03%d%s\x03" % (code, S)
+
+GREEN = 3
+RED = 4
+
+class BuildGnomeOrg(irc.IRCClient):
+    nickname = 'buildgnomeorg'
+    username = nickname
+    realname = nickname
 
-class GNOMEOSTree(callbacks.Plugin):
-    def __init__(self, irc):
-        super(GNOMEOSTree, self).__init__(irc)
-        schedule.addPeriodicEvent(self._query_new_tasks, 1, now=False)
-        self._irc = irc
+    def __init__(self):
         self._flood_channels = ['#testable']
         self._status_channels = ['#gnome-hackers']
         self._last_task_state = {}
@@ -53,10 +62,19 @@ class GNOMEOSTree(callbacks.Plugin):
         self._announce_periodic_tasks = ['smoketest', 'integrationtest']
         self._workdir = os.path.expanduser('/srv/ostree/ostbuild/%s/' % (tracked_build, ))
         self._workurl = "http://build.gnome.org/continuous/%s"; % (tracked_build, )
+        self._loop = task.LoopingCall(self._query_new_tasks)
+
+    def signedOn(self):
+        for chan in self._flood_channels:
+            self.join(chan)
+        for chan in self._status_channels:
+            self.join(chan)
+
+        self._loop.start(1)
 
     def _sendTo(self, channels, msg):
         for channel in channels:
-            self._irc.queueMsg(ircmsgs.privmsg(channel, msg))
+            self.msg(channel, msg)
 
     def _query_new_tasks(self):
         self._periodic_announce_ticks += 1
@@ -117,9 +135,9 @@ class GNOMEOSTree(callbacks.Plugin):
         msg += "%s/%s/output.txt" % (self._workurl, metadata['path'])
 
         if not success:
-            msg = ircutils.mircColor(msg, fg='red')
+            msg = mirc_color(RED, msg)
         else:
-            msg = ircutils.mircColor(msg, fg='green')
+            msg = mirc_color(GREEN, msg)
 
         return msg
 
@@ -147,8 +165,16 @@ class GNOMEOSTree(callbacks.Plugin):
         else:
             return self._status_line_for_task(taskname)
 
-    def buildstatus(self, irc, msg, args):
-        for taskname in itertools.chain(self._always_announce_tasks, self._announce_failed_tasks, 
self._announce_periodic_tasks):
-            irc.reply(self._buildstatus_for_task(taskname))
+    def privmsg(self, user, channel, message):
+        message = message.strip()
+        if message == '@buildstatus':
+            for taskname in itertools.chain(self._always_announce_tasks, self._announce_failed_tasks, 
self._announce_periodic_tasks):
+                status = self._buildstatus_for_task(taskname)
+                self.msg(channel, status)
+
+class BuildGnomeOrgFactory(protocol.ReconnectingClientFactory):
+    protocol = BuildGnomeOrg
 
-Class = GNOMEOSTree
+application = service.Application('continuous')
+ircService = internet.TCPClient(HOST, PORT, BuildGnomeOrgFactory())
+ircService.setServiceParent(application)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]