From 90923ac4047b84cd61d882410ecdb78adbe0c1da Mon Sep 17 00:00:00 2001 From: epswing Date: Sun, 14 Mar 2010 03:21:42 -0400 Subject: [PATCH 1/4] first installment of the big ass message creator --- plugins/bigassmessage.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 plugins/bigassmessage.py diff --git a/plugins/bigassmessage.py b/plugins/bigassmessage.py new file mode 100644 index 0000000..8e324b7 --- /dev/null +++ b/plugins/bigassmessage.py @@ -0,0 +1,25 @@ +from util import hook +from lxml import etree +import urllib2 + +host = 'http://bigassmessage.com' + +@hook.command +def bam(inp): + + if not inp: + return 'you forgot something' + + inp = inp.strip().replace(' ', '+') + path = '/dsx_BAM/boe.php?action=saveMsg&theStyle=magic&theMessage=' + inp + url = host + path + + try: + response = etree.parse(urllib2.urlopen(url)) + status = response.xpath('//status/text()')[0] + if (status == 'ok'): + return host + '/' + response.xpath('//msgid/text()')[0] + else: + return response.xpath('//message/text()')[0] + except: + pass From 441994fa342bcdeb9746781ddb353c14451a02c3 Mon Sep 17 00:00:00 2001 From: epswing Date: Sun, 14 Mar 2010 04:01:34 -0400 Subject: [PATCH 2/4] tabs to spaces, using urllib.quote, inp no longer needlessly stripped, if statements no longer using parens, spacing modified to pass pep8 --- plugins/bigassmessage.py | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/plugins/bigassmessage.py b/plugins/bigassmessage.py index 8e324b7..6e5645e 100644 --- a/plugins/bigassmessage.py +++ b/plugins/bigassmessage.py @@ -1,25 +1,26 @@ from util import hook from lxml import etree -import urllib2 +import urllib host = 'http://bigassmessage.com' + @hook.command def bam(inp): - - if not inp: - return 'you forgot something' - - inp = inp.strip().replace(' ', '+') - path = '/dsx_BAM/boe.php?action=saveMsg&theStyle=magic&theMessage=' + inp - url = host + path - - try: - response = etree.parse(urllib2.urlopen(url)) - status = response.xpath('//status/text()')[0] - if (status == 'ok'): - return host + '/' + response.xpath('//msgid/text()')[0] - else: - return response.xpath('//message/text()')[0] - except: - pass + + if not inp: + return 'you forgot something' + + inp = urllib.quote_plus(inp) + path = '/dsx_BAM/boe.php?action=saveMsg&theStyle=magic&theMessage=' + inp + url = host + path + + try: + response = etree.parse(url) + status = response.xpath('//status/text()')[0] + if status == 'ok': + return host + '/' + response.xpath('//msgid/text()')[0] + else: + return response.xpath('//message/text()')[0] + except: + pass From 1a9a6b4ad1f667d7b54c7b470b06b4daf568dabb Mon Sep 17 00:00:00 2001 From: epswing Date: Sun, 14 Mar 2010 04:55:48 -0400 Subject: [PATCH 3/4] added docstring, returning it if no input given, using style if specified by first word in input --- plugins/bigassmessage.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/plugins/bigassmessage.py b/plugins/bigassmessage.py index 6e5645e..5d15ff3 100644 --- a/plugins/bigassmessage.py +++ b/plugins/bigassmessage.py @@ -2,18 +2,26 @@ from util import hook from lxml import etree import urllib -host = 'http://bigassmessage.com' - @hook.command def bam(inp): + """[basic|magic|pepsi|jprdy] bigassify this""" if not inp: - return 'you forgot something' + return bam.__doc__ - inp = urllib.quote_plus(inp) - path = '/dsx_BAM/boe.php?action=saveMsg&theStyle=magic&theMessage=' + inp - url = host + path + host = 'http://bigassmessage.com' + path = '/dsx_BAM/boe.php' + params = {'action': 'saveMsg', 'theStyle': 'basic', 'theMessage': inp} + + styles = ['basic', 'magic', 'pepsi', 'jprdy'] + + for style in styles: + if inp.startswith(style + ' '): + params['theStyle'] = style + params['theMessage'] = inp[len(style) + 1:] + + url = host + path + '?' + urllib.urlencode(params) try: response = etree.parse(url) From 8cb88165f87682ff25ca969e0f51691ffe3322a9 Mon Sep 17 00:00:00 2001 From: epswing Date: Sun, 14 Mar 2010 05:05:16 -0400 Subject: [PATCH 4/4] better docstring --- plugins/bigassmessage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/bigassmessage.py b/plugins/bigassmessage.py index 5d15ff3..eec582a 100644 --- a/plugins/bigassmessage.py +++ b/plugins/bigassmessage.py @@ -5,7 +5,7 @@ import urllib @hook.command def bam(inp): - """[basic|magic|pepsi|jprdy] bigassify this""" + ".bam [basic|magic|pepsi|jprdy] -- creates a big ass message" if not inp: return bam.__doc__