diff --git a/irc.py b/irc.py index e5bfdc3..281f5db 100755 --- a/irc.py +++ b/irc.py @@ -52,10 +52,14 @@ class Bot(asynchat.async_chat): def write(self, args, text=None): # This is a safe version of __write + def safe(input): + input = input.replace('\n', '') + input = input.replace('\r', '') + return input.encode('utf-8') try: - args = [arg.encode('utf-8') for arg in args] + args = [safe(arg) for arg in args] if text is not None: - text = text.encode('utf-8') + text = safe(text) self.__write(args, text) except Exception, e: pass diff --git a/modules/clock.py b/modules/clock.py index 2ef6b21..59c9eb1 100755 --- a/modules/clock.py +++ b/modules/clock.py @@ -96,8 +96,8 @@ TZ1 = { } TZ2 = { - 'ACDT': -10.5, - 'ACST': -9.5, + 'ACDT': 10.5, + 'ACST': 9.5, 'ADT': 3, 'AEDT': 11, # hmm 'AEST': 10, # hmm @@ -251,7 +251,7 @@ def yi(phenny, input): raels = quadraels * 4 extraraels, remainder = divide(remainder, 432000) if extraraels == 4: - return phenny.say('Yes!') + return phenny.say('Yes! PARTAI!') else: phenny.say('Not yet...') yi.commands = ['yi'] yi.priority = 'low' diff --git a/modules/codepoints.py b/modules/codepoints.py index e2fc39a..eb9c8bf 100755 --- a/modules/codepoints.py +++ b/modules/codepoints.py @@ -71,7 +71,8 @@ def u(phenny, input): if not arg: return phenny.reply('You gave me zero length input.') elif not arg.strip(' '): - return phenny.reply('%s SPACES' % len(arg)) + if len(arg) > 1: return phenny.reply('%s SPACEs (U+0020)' % len(arg)) + return phenny.reply('1 SPACE (U+0020)') # @@ space if set(arg.upper()) - set( diff --git a/modules/head.py b/modules/head.py index 8158958..274e1b0 100755 --- a/modules/head.py +++ b/modules/head.py @@ -7,7 +7,7 @@ Licensed under the Eiffel Forum License 2. http://inamidst.com/phenny/ """ -import re, urllib, httplib, urlparse, time +import re, urllib, urllib2, httplib, urlparse, time from htmlentitydefs import name2codepoint import web from tools import deprecated @@ -84,7 +84,11 @@ def f_title(self, origin, match, args): try: redirects = 0 while True: - info = web.head(uri) + req = urllib2.Request(uri, headers={'Accept':'text/html'}) + u = urllib2.urlopen(req) + info = u.info() + u.close() + # info = web.head(uri) if not isinstance(info, list): status = '200' @@ -108,7 +112,7 @@ def f_title(self, origin, match, args): self.msg(origin.sender, origin.nick + ": Document isn't HTML") return - u = urllib.urlopen(uri) + u = urllib2.urlopen(req) bytes = u.read(32768) u.close() @@ -142,11 +146,15 @@ def f_title(self, origin, match, args): title = r_entity.sub(e, title) if title: - try: title.decode('iso-8859-1') - except: pass - else: title = title.decode('iso-8859-1').encode('utf-8') + try: title.decode('utf-8') + except: + try: title = title.decode('iso-8859-1').encode('utf-8') + except: title = title.decode('cp1252').encode('utf-8') + else: pass else: title = '[The title is empty.]' + title = title.replace('\n', '') + title = title.replace('\r', '') self.msg(origin.sender, origin.nick + ': ' + title) else: self.msg(origin.sender, origin.nick + ': No title found') f_title.commands = ['title'] diff --git a/modules/oblique.py b/modules/oblique.py index 55a27fc..a4aba17 100755 --- a/modules/oblique.py +++ b/modules/oblique.py @@ -7,18 +7,22 @@ Licensed under the Eiffel Forum License 2. http://inamidst.com/phenny/ """ -import urllib +import re, urllib import web +definitions = 'http://code.google.com/p/phenny-ws/wiki/ServiceDefinitions' + +r_item = re.compile(r'(?i)