snipe

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

commit 4b05a340fba5498493ce6d1a95d437bea169368b
parent a2921fa3ccbe9e19b86060ed3818ec4abcae2750
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Sun, 22 May 2011 13:08:35 -0400

fix highlighting prevention

Diffstat:
snipe.py | 37+++++++++++++++++++++----------------
1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/snipe.py b/snipe.py @@ -66,7 +66,7 @@ def ranking(game): for player in players: if pos > ranking_size: break - result.append("%s. *%s* avec %s" % (str(pos), player.name, + result.append("%s. *%s* avec %s" % (str(pos), player.sayname, fmt_score(player.score))) pos += 1 return result @@ -82,6 +82,10 @@ def say(chan, messages): print("[%s] %s" % (chan, message)) class Player: + @property + def sayname(self): + return self.name[0] + '_' + self.name[1:] + def __init__(self, name): self.name = name self.score = 0 @@ -166,23 +170,24 @@ try: continue if speaker not in list(game.keys()): game[speaker] = Player(speaker) - game[speaker].spawn_missions() + speaker = game[speaker] + speaker.spawn_missions() if to_us: if message == "help": - say_to(chan, speaker, help) - game[speaker].report() + say_to(chan, speaker.name, help) + speaker.report() elif message == "rank": - say_to(chan, speaker, ranking(game)) + say_to(chan, speaker.name, ranking(game)) elif message == "info": - game[speaker].report() + speaker.report() else: - if game[speaker].abort(message): - say_to(chan, speaker, + if speaker.abort(message): + say_to(chan, speaker.name, ["Tu as abandonné \""+message+"\" et perdu " + fmt_score(abort_penalty)]) - game[speaker].report() + speaker.report() else: - say_to(chan, speaker, + say_to(chan, speaker.name, ["Ce mot n'est pas dans ta liste. Pour de l'aide, fais " + "\"help\"."]) else: @@ -191,24 +196,24 @@ try: for word in words: word = word.lower() for player in game.values(): - if player.name != speaker: + if player.name != speaker.name: score = player.succeed(word) if score > 0: lose = int(score / 2) msg = ["*** %s ! %s gagne %s et %s perd %s." % ( - word, player.name, fmt_score(score), speaker, + word, player.sayname, fmt_score(score), speaker.sayname, fmt_score(lose))] - say_to(chan, speaker, msg) + say_to(chan, speaker.name, msg) todo.append((player.name, - "%s a dit \"%s\" et t'a fait gagner %s." % (speaker, + "%s a dit \"%s\" et t'a fait gagner %s." % (speaker.name, word, fmt_score(score)))) todo.append((player.name, "Un nouveau mot te sera proposé prochainement.")) - todo.append((speaker, + todo.append((speaker.name, "Tu as dit \"%s\", tu as fait gagner %s à %s et tu as " "perdu %s." % (word, fmt_score(score), player.name, fmt_score(lose)))) - game[speaker].score -= lose + speaker.score -= lose for (player, msg) in todo: game[player].private_message([msg]) for player in set([t[0] for t in todo]):