From 4370d51d33fdd13bc16525f1a7be3157045316ee Mon Sep 17 00:00:00 2001 From: jcao219 Date: Wed, 27 Jul 2011 18:07:36 -0500 Subject: [PATCH] tweaked the anti-flood --- oyoyo/client.py | 18 +++++++----------- wolfbot.py | 2 +- wolfgame.py | 20 ++++++++++++++++---- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/oyoyo/client.py b/oyoyo/client.py index c0d6c97..661dc4f 100644 --- a/oyoyo/client.py +++ b/oyoyo/client.py @@ -40,14 +40,12 @@ class TokenBucket(object): self.timestamp = time.time() def consume(self, tokens): - """Consume tokens from the bucket. Returns 0 if there were - sufficient tokens otherwise time until it is filled.""" + """Consume tokens from the bucket. Returns True if there were + sufficient tokens otherwise False.""" if tokens <= self.tokens: self._tokens -= tokens - return 0 - else: - return self.fill_rate - return True + return True + return False @property def tokens(self): @@ -106,7 +104,7 @@ class IRCClient(object): self.connect_cb = None self.blocking = True self.lock = threading.RLock() - self.tokenbucket = TokenBucket(3, 1.13) + self.tokenbucket = TokenBucket(3, 1.73) self.__dict__.update(kwargs) self.command_handler = cmd_handler @@ -226,10 +224,8 @@ class IRCClient(object): raise SystemExit # lets exit def msg(self, user, msg): for line in msg.split('\n'): - tme = self.tokenbucket.consume(1) - while tme: - time.sleep(tme) - tme = self.tokenbucket.consume(1) + while not self.tokenbucket.consume(1): + pass self.send("PRIVMSG", user, ":{0}".format(line)) privmsg = msg # Same thing def notice(self, user, msg): diff --git a/wolfbot.py b/wolfbot.py index bdfc11c..a2cdf2a 100644 --- a/wolfbot.py +++ b/wolfbot.py @@ -76,7 +76,7 @@ def main(): if not botconfig.DEBUG_MODE: logging.basicConfig(level=logging.WARNING) else: - logging.basicConfig(level=logging.INFO) + logging.basicConfig(level=logging.DEBUG) cli = IRCClient( {"privmsg":on_privmsg, "":__unhandled__}, diff --git a/wolfgame.py b/wolfgame.py index e6aac9d..69382de 100644 --- a/wolfgame.py +++ b/wolfgame.py @@ -658,7 +658,8 @@ def del_player(cli, nick, forced_death = False): if not is_fake_nick(nick): cmode.append(("+q", nick)) mass_mode(cli, cmode) - var.DEAD.append(nick) + if nick not in var.DEAD: + var.DEAD.append(nick) ret = not chk_win(cli) if var.PHASE in ("night", "day") and ret: # remove him from variables if he is in there @@ -772,6 +773,7 @@ def goat(cli, nick, chan, rest): cli.msg(chan, ("\u0002{0}\u0002's goat walks by "+ "and kicks \u0002{1}\u0002.").format(nick, rest.strip())) + var.GOATED = True @@ -1875,7 +1877,7 @@ def show_rules(cli, nick, chan, rest): @pmcmd("help", raw_nick = True) -def help(cli, rnick, rest): +def get_help(cli, rnick, rest): """Gets help.""" nick, mode, user, cloak = parse_nick(rnick) fns = [] @@ -1919,9 +1921,9 @@ def help(cli, rnick, rest): def help2(cli, nick, chan, rest): """Gets help""" if rest.strip(): # command was given - help(cli, chan, rest) + get_help(cli, chan, rest) else: - help(cli, nick, rest) + get_help(cli, nick, rest) @hook("invite", raw_nick = False, admin_only = True) @@ -1964,6 +1966,16 @@ def coin(cli, nick, chan, rest): if botconfig.DEBUG_MODE: + + @cmd("set", admin_only=True) + def set(cli, nick, chan, rest): + rest = re(" +",rest, 1) + if len(rest) != 2 or not rest[0] or not rest[1]: + cli.msg(chan, "Invalid syntax.") + return + cli.msg(chan, "Not implemented yet.") + + @cmd("revealroles", admin_only=True) def revroles(cli, nick, chan, rest): cli.msg(chan, str(var.ROLES))