From fa593d0db16df2c8cf2255f1d423e2ef2611b15f Mon Sep 17 00:00:00 2001 From: jcao219 Date: Sat, 30 Jul 2011 02:38:33 -0500 Subject: [PATCH] somewhat modified the anti-flood, and fixed some howl differences --- oyoyo/client.py | 11 ++++------- var.py | 2 +- wolfgame.py | 8 +++++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/oyoyo/client.py b/oyoyo/client.py index 7dc53c5..23f366f 100644 --- a/oyoyo/client.py +++ b/oyoyo/client.py @@ -104,7 +104,7 @@ class IRCClient(object): self.blocking = True self.lock = threading.RLock() - self.tokenbucket = TokenBucket(3, 1.73) + self.tokenbucket = TokenBucket(28, 1.73) self.last_messaged = "" self.__dict__.update(kwargs) @@ -145,6 +145,9 @@ class IRCClient(object): msg = bytes(" ", "utf_8").join(bargs) logging.info('---> send "{0}"'.format(msg)) + while not self.tokenbucket.consume(1): + pass + self.socket.send(msg + bytes("\r\n", "utf_8")) def connect(self): @@ -226,12 +229,6 @@ class IRCClient(object): raise SystemExit # lets exit def msg(self, user, msg): for line in msg.split('\n'): - if user == self.last_messaged: - while not self.tokenbucket.consume(1): - pass - else: # ? - while not self.tokenbucket.consume(0.37): - pass self.send("PRIVMSG", user, ":{0}".format(line)) self.last_messaged = user privmsg = msg # Same thing diff --git a/var.py b/var.py index b0350c7..4449dac 100644 --- a/var.py +++ b/var.py @@ -2,7 +2,7 @@ PING_WAIT = 300 # Seconds MINIMUM_WAIT = 60 EXTRA_WAIT = 20 MAXIMUM_WAITED = 2 # limit for amount of !wait's -MAX_SHOTS = 2 +SHOTS_MULTIPLIER = .12 # ceil(shots_multiplier * len_players) = bullets given MAX_PLAYERS = 30 DRUNK_SHOTS_MULTIPLIER = 3 NIGHT_TIME_LIMIT = 90 diff --git a/wolfgame.py b/wolfgame.py index 3791a5f..1db8e27 100644 --- a/wolfgame.py +++ b/wolfgame.py @@ -22,6 +22,7 @@ import logging import sys import os import imp +import math COMMANDS = {} PM_COMMANDS = {} @@ -1761,9 +1762,10 @@ def start(cli, nick, chan, rest): for gnr in random.sample(possible, len(var.ROLES["gunner"])): if var.ROLES["village drunk"] == gnr: - var.GUNNERS[gnr] = var.DRUNK_SHOTS_MULTIPLIER * var.MAX_SHOTS + var.GUNNERS[gnr] = (var.DRUNK_SHOTS_MULTIPLIER * + math.ceil(var.SHOTS_MULTIPLIER * len(var.list_players()))) else: - var.GUNNERS[gnr] = var.MAX_SHOTS + var.GUNNERS[gnr] = math.ceil(var.SHOTS_MULTIPLIER * len(var.list_players())) del var.ROLES["gunner"] var.ROLES["villager"] = villagers @@ -2160,7 +2162,7 @@ if botconfig.DEBUG_MODE: if len(rolargs) == 2 and len(rolargs[1]) < 7 and rolargs[1].isdigit(): var.GUNNERS[who] = int(rolargs[1]) else: - var.GUNNERS[who] = var.MAX_SHOTS + var.GUNNERS[who] = math.ceil(var.SHOTS_MULTIPLIER * len(var.list_players())) if who not in pl: var.ROLES["villager"].append(who) elif rol == "cursed":