snipe

bot for a simple IRC game to make people say words
git clone https://a3nm.net/git/snipe/
Log | Files | Refs

commit e1e84b1d651502d743a3fa44e885a9fb89d4cacb
parent 75f64586a071c6598fb83b196838724bed472189
Author: Antoine Amarilli <ant.amarilli@free.fr>
Date:   Sat, 21 May 2011 00:11:16 -0400

hack for latin1 handling

Diffstat:
snipe.py | 11+++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/snipe.py b/snipe.py @@ -9,6 +9,8 @@ import pickle def fmt_score(score): return str(score) + " point" + ("s" if abs(score) != 1 else "") +sys.stdin = sys.stdin.detach() + num_missions = 3 ranking_size = 5 abort_penalty = 2 @@ -128,6 +130,10 @@ class Player: self.spawn_missions() return found +def to_unicode(data, errors='replace'): + detection = chardet.detect(data) + encoding = detection.get('encoding') or 'utf-16' + return unicode(data, encoding, errors=errors) missions = read_missions(mission_file) @@ -146,10 +152,11 @@ if ok: try: while True: + l = sys.stdin.readline() try: - line = sys.stdin.readline() + line = l.decode('utf8') except UnicodeDecodeError: - continue + line = l.decode('latin1') if (not line): break chan, speaker, message, to_us = parse(line)