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):
self.timestamp = time.time() self.timestamp = time.time()
def consume(self, tokens): def consume(self, tokens):
"""Consume tokens from the bucket. Returns 0 if there were """Consume tokens from the bucket. Returns True if there were
sufficient tokens otherwise time until it is filled.""" sufficient tokens otherwise False."""
if tokens <= self.tokens: if tokens <= self.tokens:
self._tokens -= tokens self._tokens -= tokens
return 0
else:
return self.fill_rate
return True return True
return False
@property @property
def tokens(self): def tokens(self):
@ -106,7 +104,7 @@ class IRCClient(object):
self.connect_cb = None self.connect_cb = None
self.blocking = True self.blocking = True
self.lock = threading.RLock() self.lock = threading.RLock()
self.tokenbucket = TokenBucket(3, 1.13) self.tokenbucket = TokenBucket(3, 1.73)
self.__dict__.update(kwargs) self.__dict__.update(kwargs)
self.command_handler = cmd_handler self.command_handler = cmd_handler
@ -226,10 +224,8 @@ class IRCClient(object):
raise SystemExit # lets exit raise SystemExit # lets exit
def msg(self, user, msg): def msg(self, user, msg):
for line in msg.split('\n'): for line in msg.split('\n'):
tme = self.tokenbucket.consume(1) while not self.tokenbucket.consume(1):
while tme: pass
time.sleep(tme)
tme = self.tokenbucket.consume(1)
self.send("PRIVMSG", user, ":{0}".format(line)) self.send("PRIVMSG", user, ":{0}".format(line))
privmsg = msg # Same thing privmsg = msg # Same thing
def notice(self, user, msg): def notice(self, user, msg):

2
wolfbot.py

@ -76,7 +76,7 @@ def main():
if not botconfig.DEBUG_MODE: if not botconfig.DEBUG_MODE:
logging.basicConfig(level=logging.WARNING) logging.basicConfig(level=logging.WARNING)
else: else:
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.DEBUG)
cli = IRCClient( cli = IRCClient(
{"privmsg":on_privmsg, {"privmsg":on_privmsg,
"":__unhandled__}, "":__unhandled__},

18
wolfgame.py

@ -658,6 +658,7 @@ def del_player(cli, nick, forced_death = False):
if not is_fake_nick(nick): if not is_fake_nick(nick):
cmode.append(("+q", nick)) cmode.append(("+q", nick))
mass_mode(cli, cmode) mass_mode(cli, cmode)
if nick not in var.DEAD:
var.DEAD.append(nick) var.DEAD.append(nick)
ret = not chk_win(cli) ret = not chk_win(cli)
if var.PHASE in ("night", "day") and ret: if var.PHASE in ("night", "day") and ret:
@ -772,6 +773,7 @@ def goat(cli, nick, chan, rest):
cli.msg(chan, ("\u0002{0}\u0002's goat walks by "+ cli.msg(chan, ("\u0002{0}\u0002's goat walks by "+
"and kicks \u0002{1}\u0002.").format(nick, "and kicks \u0002{1}\u0002.").format(nick,
rest.strip())) rest.strip()))
var.GOATED = True
@ -1875,7 +1877,7 @@ def show_rules(cli, nick, chan, rest):
@pmcmd("help", raw_nick = True) @pmcmd("help", raw_nick = True)
def help(cli, rnick, rest): def get_help(cli, rnick, rest):
"""Gets help.""" """Gets help."""
nick, mode, user, cloak = parse_nick(rnick) nick, mode, user, cloak = parse_nick(rnick)
fns = [] fns = []
@ -1919,9 +1921,9 @@ def help(cli, rnick, rest):
def help2(cli, nick, chan, rest): def help2(cli, nick, chan, rest):
"""Gets help""" """Gets help"""
if rest.strip(): # command was given if rest.strip(): # command was given
help(cli, chan, rest) get_help(cli, chan, rest)
else: else:
help(cli, nick, rest) get_help(cli, nick, rest)
@hook("invite", raw_nick = False, admin_only = True) @hook("invite", raw_nick = False, admin_only = True)
@ -1964,6 +1966,16 @@ def coin(cli, nick, chan, rest):
if botconfig.DEBUG_MODE: 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) @cmd("revealroles", admin_only=True)
def revroles(cli, nick, chan, rest): def revroles(cli, nick, chan, rest):
cli.msg(chan, str(var.ROLES)) cli.msg(chan, str(var.ROLES))

Loading…
Cancel
Save