Browse Source

tweaked the anti-flood

master
jcao219 14 years ago
parent
commit
4370d51d33
  1. 16
      oyoyo/client.py
  2. 2
      wolfbot.py
  3. 18
      wolfgame.py

16
oyoyo/client.py

@ -40,14 +40,12 @@ class TokenBucket(object): @@ -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 False
@property
def tokens(self):
@ -106,7 +104,7 @@ class IRCClient(object): @@ -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): @@ -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):

2
wolfbot.py

@ -76,7 +76,7 @@ def main(): @@ -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__},

18
wolfgame.py

@ -658,6 +658,7 @@ def del_player(cli, nick, forced_death = False): @@ -658,6 +658,7 @@ def del_player(cli, nick, forced_death = False):
if not is_fake_nick(nick):
cmode.append(("+q", nick))
mass_mode(cli, cmode)
if nick not in var.DEAD:
var.DEAD.append(nick)
ret = not chk_win(cli)
if var.PHASE in ("night", "day") and ret:
@ -772,6 +773,7 @@ def goat(cli, nick, chan, rest): @@ -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): @@ -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): @@ -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): @@ -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))

Loading…
Cancel
Save