Permalink
Browse files

Attempt to fix UTF8 handling across the board

  • Loading branch information...
aquarion committed Sep 30, 2012
1 parent 62622ff commit 58d4845142c7afc35d96441621b12b8c3f354029
View
@@ -398,7 +398,8 @@ def action(self, user, channel, msg):
self.logger.log("* %s %s" % (user, msg))
def message(self, user, message, length=200):
- return self.msg(user,message.encode("utf-8"),length)
+ message = message.decode("utf-8").encode("utf-8")
+ return self.msg(user,message,length)
# irc callbacks
@@ -24,12 +24,12 @@ def __init__(self, connection):
def channelAction(self, connection, user, channel, message, index):
if self.overUsed():
- connection.msg(user, "Overuse Triggered" )
+ connection.message(user, "Overuse Triggered" )
return True
#def everyLine(self, connection, user, channel, message)
#def leaveAction(self, connection, user, reason, parameters)
#def nickChangeAction(self, connection, old_nick, new_nick)
#def privateAction(self, connection, user, channel, message, index)
- #def scheduleAction(self, connection)
+ #def scheduleAction(self, connection)
@@ -12,8 +12,8 @@ class Reaction(lampstand.reactions.base.Reaction):
def __init__(self, connection):
self.privateMatch = (
- re.compile('say \#(\w*) (.*)', re.IGNORECASE),
- re.compile('do \#(\w*) (.*)', re.IGNORECASE),
+ re.compile('say (\#\w*) (.*)', re.IGNORECASE),
+ re.compile('do (\#\w*) (.*)', re.IGNORECASE),
re.compile('quit (.*)', re.IGNORECASE),
re.compile('status', re.IGNORECASE),
re.compile('reload (.*)', re.IGNORECASE),
@@ -35,12 +35,12 @@ def privateAction(self, connection, user, channel, message, matchindex = 0):
matches = self.privateMatch[matchindex].findall(message)
if matchindex == 0:
- print "[Say] %s %s" % (matches[0][0], matches[0][1].encode('utf8'))
- connection.msg(matches[0][0], matches[0][1].encode('utf8'))
+ print "[Say] %s %s" % (matches[0][0], matches[0][1])
+ connection.message(matches[0][0], matches[0][1])
elif matchindex == 1:
#print "[Do] %s %s" % (sys.argv[1], matches[0])
- connection.me("#%s" % matches[0][0], matches[0][1])
- connection.message(user, "%s" % matches)
+ connection.me(matches[0][0], matches[0][1])
+ #connection.message(user, "%s" % matches)
#connection.me("#%s" % sys.argv[1], matches[0])
elif matchindex == 2:
print "[Quit] %s" % (matches[0])
@@ -22,7 +22,7 @@ def channelAction(self, connection, user, channel, message):
if self.overUsed():
- connection.msg(user, "Enough with the religion for now. (Overuse triggered)")
+ connection.message(user, "Enough with the religion for now. (Overuse triggered)")
return
print "[Bible] %s" % matches
@@ -44,10 +44,10 @@ def channelAction(self, connection, user, channel, message):
stringOne = result[0:whereToSplit]
stringTwo = result[whereToSplit:]
- connection.msg(channel, "%s... " % stringOne)
- connection.msg(channel, "... %s [ESV]" % stringTwo)
+ connection.message(channel, "%s... " % stringOne)
+ connection.message(channel, "... %s [ESV]" % stringTwo)
else:
- connection.msg(channel, "%s [ESV]" % result)
+ connection.message(channel, "%s [ESV]" % result)
return True
@@ -72,9 +72,9 @@ def privateAction(self, connection, user, channel, message):
stringOne = result[0:whereToSplit]
stringTwo = result[whereToSplit:]
- connection.msg(user, "%s... " % stringOne)
- connection.msg(user, "... %s [ESV]" % stringTwo)
+ connection.message(user, "%s... " % stringOne)
+ connection.message(user, "... %s [ESV]" % stringTwo)
else:
- connection.msg(user, "%s [ESV]" % result)
+ connection.message(user, "%s [ESV]" % result)
return True
@@ -21,7 +21,7 @@ def channelAction(self, connection, user, channel, message):
if self.overUsed():
- connection.msg(channel, "I'm out of boxes, new delivery shortly.")
+ connection.message(channel, "I'm out of boxes, new delivery shortly.")
return
print "[Box] called "
@@ -24,7 +24,7 @@ def channelAction(self, connection, user, channel, message):
if self.overUsed(self.uses, self.cooldown_number, self.cooldown_time):
- connection.msg(channel, "I'm not running your life for you, go away." )
+ connection.message(channel, "I'm not running your life for you, go away." )
return True
self.updateOveruse()
@@ -34,12 +34,12 @@ def channelAction(self, connection, user, channel, message):
if random.randint(0,100) == 69:
print "Yes";
- connection.msg(channel, "%s: Yes" % user)
+ connection.message(channel, "%s: Yes" % user)
return True
if random.randint(0,100) == 67:
print "Edge";
- connection.msg(channel, "%s: edge" % user)
+ connection.message(channel, "%s: edge" % user)
return True
print match
@@ -49,7 +49,7 @@ def channelAction(self, connection, user, channel, message):
elif reaction.lower() == "boom" and user.lower():
connection.kick(channel,user, "BOOM")
else:
- connection.msg(channel, "%s: %s" % (user, reaction))
+ connection.message(channel, "%s: %s" % (user, reaction))
return True
@@ -59,7 +59,7 @@ def privateAction(self, connection, user, channel, message):
if self.overUsed(self.uses, self.cooldown_number, self.cooldown_time):
- connection.msg(user, "I'm not running your life for you, go away." )
+ connection.message(user, "I'm not running your life for you, go away." )
return
self.updateOveruse()
@@ -68,7 +68,7 @@ def privateAction(self, connection, user, channel, message):
print "Match: %s" % match
reaction = self.choose(match[0][1])
- connection.msg(user, "%s: %s" % (user, reaction))
+ connection.message(user, "%s: %s" % (user, reaction))
def choose(self, message):
if message[-1:] == "?":
@@ -32,6 +32,6 @@ def everyLine(self, connection, user, channel, message):
cutout = message[index:]
if len(cutout) > 0:
- connection.msg(channel, "%s: I think that cut out at \"%s\"" % (user, cutout));
+ connection.message(channel, "%s: I think that cut out at \"%s\"" % (user, cutout));
return True
@@ -23,13 +23,13 @@ def channelAction(self, connection, user, channel, message):
item = self.channelMatch.findall(message);
result = self.rollDice(item)
- connection.msg(channel, "%s: %s" % (user, result))
+ connection.message(channel, "%s: %s" % (user, result))
return True
def privateAction(self, connection, user, channel, message, matchindex = 0):
item = self.privateMatch.findall(message);
result = self.rollDice(item)
- connection.msg(user, result)
+ connection.message(user, result)
def rollDice(self, item):
@@ -191,8 +191,9 @@ def roll(self, dice, modifiers):
print "Changed"
changed = True
- if not changed:
- print "No change!"
- original = []
+ #if not changed:
+ # print "No change!"
+ # original = []
+
return [results, str(howmany)+'d'+str(type), original]
@@ -49,7 +49,7 @@ def getDefinition(self, query):
src = "Dictionary"
except socket.error:
print "[Define] Argh. Dictionary server's offline"
- connection.msg(channel, "Sorry, but my dictionary server's not working.")
+ connection.message(channel, "Sorry, but my dictionary server's not working.")
dfn = None
if not dfn:
@@ -78,14 +78,14 @@ def channelAction(self, connection, user, channel, message):
if self.overUsed():
- connection.msg(user, "The dictionary is on fire. Leave it alone. (Overuse triggered)")
+ connection.message(user, "The dictionary is on fire. Leave it alone. (Overuse triggered)")
return
self.updateOveruse()
try:
result, src = self.getDefinition(matches[0])
except:
- connection.msg(channel, "%s: There is no such word as '%s' in my dictionary. In fact, everything between 'herring' and 'marmalade' appears to be completely missing." % (user, matches[0]))
+ connection.message(channel, "%s: There is no such word as '%s' in my dictionary. In fact, everything between 'herring' and 'marmalade' appears to be completely missing." % (user, matches[0]))
return True
print "[Define] %s" % result
@@ -100,10 +100,10 @@ def channelAction(self, connection, user, channel, message):
stringOne = result[0:whereToSplit]
stringTwo = result[whereToSplit:]
- connection.msg(channel, "%s... " % stringOne)
- connection.msg(channel, "... %s" % stringTwo)
+ connection.message(channel, "%s... " % stringOne)
+ connection.message(channel, "... %s" % stringTwo)
else:
- connection.msg(channel, "%s" % result)
+ connection.message(channel, "%s" % result)
return True
@@ -115,7 +115,7 @@ def privateAction(self, connection, user, channel, message):
result, src = self.getDefinition(matches[0])
except:
- connection.msg(user, "%s: There is no such word as '%s' in my dictionary. In fact, everything between 'herring' and 'marmalade' appears to be completely missing." % (user, matches[0]))
+ connection.message(user, "%s: There is no such word as '%s' in my dictionary. In fact, everything between 'herring' and 'marmalade' appears to be completely missing." % (user, matches[0]))
return True
print "[Define] %s" % result
@@ -130,9 +130,9 @@ def privateAction(self, connection, user, channel, message):
stringOne = result[0:whereToSplit]
stringTwo = result[whereToSplit:]
- connection.msg(user, "%s... " % stringOne)
- connection.msg(user, "... %s" % stringTwo)
+ connection.message(user, "%s... " % stringOne)
+ connection.message(user, "... %s" % stringTwo)
else:
- connection.msg(user, "%s" % result)
+ connection.message(user, "%s" % result)
return True
@@ -31,12 +31,12 @@ def channelAction(self, connection, user, channel, message, matchIndex):
if self.overUsed():
- connection.msg(user, "The 8-ball says: 'Find a new prophet, I quit.', I'd give it a while to cool down." )
+ connection.message(user, "The 8-ball says: 'Find a new prophet, I quit.', I'd give it a while to cool down." )
return True
self.updateOveruse()
- connection.msg(channel, "%s: %s" % (user, eightball.question()) )
+ connection.message(channel, "%s: %s" % (user, eightball.question()) )
return True
@@ -69,7 +69,7 @@ def privateAction(self, connection, user, channel, message, matchIndex):
def channelAction(self, connection, user, channel, message, matchIndex):
if self.overUsed():
- connection.msg(user, "Overuse Triggered" )
+ connection.message(user, "Overuse Triggered" )
return True
matches = self.channelMatch[matchIndex].findall(message)[0]
@@ -72,7 +72,7 @@ def channelAction(self, connection, user, channel, message, matchindex):
if self.overUsed(self.uses):
if self.reactions[matchindex][1] != '':
- connection.msg(channel, self.reactions[matchindex][1])
+ connection.message(channel, self.reactions[matchindex][1])
return True
@@ -92,23 +92,23 @@ def channelAction(self, connection, user, channel, message, matchindex):
elif reaction[0] == "%":
roll = random.randint(0,50)
if roll == 45:
- connection.msg(channel, reaction[1:])
+ connection.message(channel, reaction[1:])
else:
print "Rolled %d" % roll;
else:
- connection.msg(channel, reaction)
+ connection.message(channel, reaction)
return True
def privateAction(self, connection, user, channel, message, matchindex):
#match = self.privateMatch.findall(message);
- #connection.msg(user, self.howLong(match).encode('ascii'))
+ #connection.message(user, self.howLong(match).encode('ascii'))
print "[Generic Reaction] called"
if self.overUsed(self.uses, self.cooldown_number, self.cooldown_time):
if self.reactions[matchindex][1] != '':
- connection.msg(user, self.reactions[matchindex][1])
+ connection.message(user, self.reactions[matchindex][1])
return
@@ -130,6 +130,6 @@ def privateAction(self, connection, user, channel, message, matchindex):
print "ACtion %s : %s" % (user, reaction)
connection.me(user, reaction)
else:
- connection.msg(user, reaction)
+ connection.message(user, reaction)
return
@@ -58,12 +58,12 @@ def countSyllables(self, connection, user, channel, message):
if syllables == 1:
ordinal = ""
elif syllables == -1:
- connection.msg(channel, "%s: I don't know, so I ignore it." % user)
+ connection.message(channel, "%s: I don't know, so I ignore it." % user)
return True
else:
ordinal = "s"
- connection.msg(channel, "%s: \"%s\" has %s syllable%s" % (user, matches[0], syllables, ordinal))
+ connection.message(channel, "%s: \"%s\" has %s syllable%s" % (user, matches[0], syllables, ordinal))
return True
def save(self):
@@ -98,7 +98,7 @@ def cheatSheet(self, connection, user, channel, message):
self.save()
- connection.msg(channel, "%s: If you say so" % user)
+ connection.message(channel, "%s: If you say so" % user)
return True
@@ -125,7 +125,7 @@ def findHaiku(self, connection, user, channel, message):
else:
channelout = channel;
- connection.msg(channelout, "That looked like a haiku on %s: %s " % (channel, " // ".join(haikus[0])))
+ connection.message(channelout, "That looked like a haiku on %s: %s " % (channel, " // ".join(haikus[0])))
self.channels[channel] = []
self.lasthaiku[channel] = " // ".join(haikus[0])
return True
View
@@ -26,28 +26,28 @@ def channelAction(self, connection, user, channel, message):
if self.overUsed():
print "[HUG REACTION] OVERUSED %s" % user;
- connection.msg(channel, "%s: I am not a vending machine :(" % user)
+ connection.message(channel, "%s: I am not a vending machine :(" % user)
return
if (self.banned.has_key(user.lower())):
print "[HUG REACTION] BANNED %s" % user;
insult = shakeinsult.shakeinsult(1);
- connection.msg(channel, "%s the %s, %s" % (user, self.banned[user.lower()], insult ) )
+ connection.message(channel, "%s the %s, %s" % (user, self.banned[user.lower()], insult ) )
return
self.updateOveruse()
print "[HUG REACTION] GET %s" % user;
- connection.me(channel, self.hug(user))
+ connection.describe(channel, self.hug(user).decode("utf-8").encode("utf-8"))
return True
def privateAction(self, connection, user, channel, message):
item = self.privateMatch.findall(message);
print "[HUG REACTION] SET %s %s" % (user, item[0]);
- connection.msg(user, self.set(user, item[0]))
+ connection.message(user, self.set(user, item[0]))
def set(self, username, item):
@@ -67,7 +67,7 @@ def hug(self, username):
if result != None:
print "I have a replacement for %s: %s" % (username, result[1]);
- return "gives %s %s " % (username, result[1].encode('utf8'))
+ return "gives %s %s " % (username, result[1])
else:
print "I have no replacement for %s" % username;
Oops, something went wrong.

0 comments on commit 58d4845

Please sign in to comment.