aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkongr45gpen <electrovesta@gmail.com>2014-04-27 23:31:24 +0300
committerkongr45gpen <electrovesta@gmail.com>2014-04-27 23:31:24 +0300
commita4445d2c8064d8099c09a54f08ad57f755f15a5f (patch)
treea62c0c3c4ce6a68808780b58325dcc43844e2e18
parent44e5718b218b879d7cc5e83ad387e02b9668937e (diff)
downloadsupybot_github-a4445d2c8064d8099c09a54f08ad57f755f15a5f.tar.gz
supybot_github-a4445d2c8064d8099c09a54f08ad57f755f15a5f.tar.bz2
supybot_github-a4445d2c8064d8099c09a54f08ad57f755f15a5f.zip
Add testing command
-rw-r--r--__init__.py1
-rw-r--r--local/handler/GithubHandler.py2
-rw-r--r--local/utility.py9
-rw-r--r--plugin.py38
4 files changed, 48 insertions, 2 deletions
diff --git a/__init__.py b/__init__.py
index 9a47fe9..d7be23a 100644
--- a/__init__.py
+++ b/__init__.py
@@ -22,6 +22,7 @@ __contributors__ = {}
# This is a url where the most recent plugin package can be downloaded.
__url__ = 'https://github.com/kongr45gpen/supybot-github'
+
import config
import plugin
reload(plugin) # In case we're being reloaded.
diff --git a/local/handler/GithubHandler.py b/local/handler/GithubHandler.py
index 2b4096d..ed27a98 100644
--- a/local/handler/GithubHandler.py
+++ b/local/handler/GithubHandler.py
@@ -107,5 +107,7 @@ class GithubHandler(BaseHTTPServer.BaseHTTPRequestHandler):
for msg in msgs:
irc.queueMsg(ircmsgs.privmsg(channel, msg))
+ saveMessages(msgs)
+
def log_message(self, format, *args):
log.info(format % args)
diff --git a/local/utility.py b/local/utility.py
index 7c66d9e..abb0915 100644
--- a/local/utility.py
+++ b/local/utility.py
@@ -1,9 +1,12 @@
import urllib2
import supybot.conf as conf
+import supybot.world as world
import supybot.ircutils as ircutils
import supybot.registry as registry
+import globals
+
def registryValue(plugin, name, channel=None, value=True):
group = conf.supybot.plugins.get(plugin)
names = registry.split(name)
@@ -62,6 +65,12 @@ def getShortURL(longurl):
url = response.info().getheader('Location')
return ircutils.mircColor(url, "purple")
+def saveMessages(msgs):
+ """ Saves the last messages so that the plugin can be easily tested """
+ if world.testing:
+ return
+ globals.messageList = msgs
+
# Possible colours:
# white, black, (light/dark) blue, (light) green, red, brown, purple,
# orange, yellow, teal, pink, light/dark gray/grey
diff --git a/plugin.py b/plugin.py
index 75adadd..6985213 100644
--- a/plugin.py
+++ b/plugin.py
@@ -28,6 +28,7 @@
import re
import json
import time
+import Queue
import urllib
import urlparse
import threading
@@ -44,8 +45,12 @@ import supybot.ircutils as ircutils
import supybot.registry as registry
import supybot.callbacks as callbacks
-RequestHandler = utils.python.universalImport('handler.GithubHandler', 'local.handler.GithubHandler')
-Utility = utils.python.universalImport('local.utility')
+#RequestHandler = utils.python.universalImport('handler.GithubHandler', 'local.handler.GithubHandler')
+#Utility = utils.python.universalImport('local.utility')
+
+import local.globals as globals
+import local.handler.GithubHandler as RequestHandler
+import local.utility as Utility
class Github(callbacks.Plugin):
"""Add the help for \"@plugin help Github\" here
@@ -53,6 +58,7 @@ class Github(callbacks.Plugin):
threaded = True
port = Utility.configValue('port')
+ messages = []
pass
def ServerStart(self, httpd):
@@ -74,6 +80,7 @@ class Github(callbacks.Plugin):
def __call__(self, irc, msg):
self.__parent.__call__(irc, msg)
+
def die(self):
self.httpd.server_close()
self.httpd.shutdown()
@@ -81,6 +88,33 @@ class Github(callbacks.Plugin):
reload(RequestHandler)
reload(Utility)
+ def get(self, irc, msg, args, order, type, garbage):
+ """[<order>] [<type>] [<garbage>]
+ Returns the requested message generated by the request handler.
+ Examples: get first message, get 2nd last response
+ """
+ _digits = re.compile('\d')
+
+ orders = { 'first': 1,
+ 'second': 2,
+ 'third': 3,
+ 'fourth': 4
+ }
+
+ if _digits.search(order):
+ requestedNum = int(re.sub("[^0-9]", "", order))
+ else:
+ requestedNum = orders[order] if order in orders else 1
+
+ if order == 'last' or type == 'last':
+ requestedNum = len(globals.messageList) - requestedNum + 1
+
+ print globals.messageList
+ irc.reply(globals.messageList[requestedNum-1])
+
+ # Debug function
+ get = wrap(get, ['lowered', optional('lowered'), optional('text')]) if world.testing else False
+
Class = Github

© 2014-2024 Faster IT GmbH | imprint | privacy policy