Remove some trailing whitespace

This commit is contained in:
nyuszika7h 2015-03-27 20:09:45 +01:00
parent ad8f3a720a
commit 440f4beca5
7 changed files with 77 additions and 77 deletions

View File

@ -46,7 +46,7 @@ def on_privmsg(cli, rawnick, chan, msg, notice = False):
else:
if botconfig.IGNORE_HIDDEN_COMMANDS and chan[0] in prefixes:
return
if (notice and ((chan != botconfig.NICK and not botconfig.ALLOW_NOTICE_COMMANDS) or
(chan == botconfig.NICK and not botconfig.ALLOW_PRIVATE_NOTICE_COMMANDS))):
return # not allowed in settings
@ -84,7 +84,7 @@ def on_privmsg(cli, rawnick, chan, msg, notice = False):
else:
notify_error(cli, chan, log)
def __unhandled__(cli, prefix, cmd, *args):
currmod = ld.MODULES[ld.CURRENT_MODULE]
@ -101,7 +101,7 @@ def __unhandled__(cli, prefix, cmd, *args):
else:
notify_error(cli, botconfig.CHANNEL, log)
COMMANDS = {}
HOOKS = {}
@ -110,29 +110,29 @@ hook = decorators.generate(HOOKS, raw_nick=True, permissions=False)
def connect_callback(cli):
def prepare_stuff(*args):
def prepare_stuff(*args):
cli.join(botconfig.CHANNEL)
cli.join(botconfig.ALT_CHANNELS)
cli.join(",".join(chan.lstrip("".join(var.STATUSMSG_PREFIXES)) for chan in botconfig.DEV_CHANNEL.split(",")))
cli.msg("ChanServ", "op "+botconfig.CHANNEL)
cli.cap("REQ", "extended-join")
cli.cap("REQ", "account-notify")
try:
ld.MODULES[ld.CURRENT_MODULE].connect_callback(cli)
except AttributeError:
pass # no connect_callback for this one
cli.nick(botconfig.NICK) # very important (for regain/release)
prepare_stuff = hook("endofmotd", hookid=294)(prepare_stuff)
def mustregain(cli, *blah):
if not botconfig.PASS:
return
cli.ns_regain()
cli.ns_regain()
def mustrelease(cli, *rest):
if not botconfig.PASS:
return # prevents the bot from trying to release without a password
@ -144,13 +144,13 @@ def connect_callback(cli):
def must_use_temp_nick(cli, *etc):
cli.nick(botconfig.NICK+"_")
cli.user(botconfig.NICK, "")
decorators.unhook(HOOKS, 239)
hook("unavailresource")(mustrelease)
hook("nicknameinuse")(mustregain)
if botconfig.SASL_AUTHENTICATION:
@hook("authenticate")
def auth_plus(cli, something, plus):
if plus == "+":
@ -158,16 +158,16 @@ def connect_callback(cli):
pass_b = bytes(botconfig.PASS, "utf-8")
secrt_msg = b'\0'.join((nick_b, nick_b, pass_b))
cli.send("AUTHENTICATE " + b64encode(secrt_msg).decode("utf-8"))
@hook("cap")
def on_cap(cli, svr, mynick, ack, cap):
if ack.upper() == "ACK" and "sasl" in cap:
cli.send("AUTHENTICATE PLAIN")
@hook("903")
def on_successful_auth(cli, blah, blahh, blahhh):
cli.cap("END")
@hook("904")
@hook("905")
@hook("906")
@ -176,9 +176,9 @@ def connect_callback(cli):
cli.quit()
alog("Authentication failed. Did you fill the account name "+
"in botconfig.USERNAME if it's different from the bot nick?")
@hook("ping")
def on_ping(cli, prefix, server):
cli.send('PONG', server)

View File

@ -1924,7 +1924,7 @@ def stop_game(cli, winner = "", abort = False):
if p.startswith("(dced)"):
p = p[6:]
if p in origroles and role not in var.TEMPLATE_RESTRICTIONS.keys():
playersformatted.append("\u0002{0}\u0002 ({1}{2})".format(p,
playersformatted.append("\u0002{0}\u0002 ({1}{2})".format(p,
"" if prev else "was ", origroles[p]))
prev = True
else:
@ -2143,7 +2143,7 @@ def chk_win(cli, end_game = True):
with var.GRAVEYARD_LOCK:
if var.PHASE not in ("day", "night"):
return False #some other thread already ended game probably
lwolves = len(var.list_players(var.WOLFCHAT_ROLES))
cubs = len(var.ROLES["wolf cub"]) if "wolf cub" in var.ROLES else 0
lrealwolves = len(var.list_players(var.WOLF_ROLES)) - cubs
@ -3598,7 +3598,7 @@ def transition_day(cli, gameid=0):
"https://i.imgur.com/b8HAvjL.gifv",
"https://i.imgur.com/PIIfL15.gifv"]
))
if victim in var.HVISITED.values() and victim in bywolves: # victim was visited by some harlot and victim was attacked by wolves
for hlt in var.HVISITED.keys():
if var.HVISITED[hlt] == victim:
@ -3719,7 +3719,7 @@ def transition_day(cli, gameid=0):
if havetotem:
message.append("\u0002{0}\u0002 seem{1} to be in possession of a mysterious totem...".format(havetotem, "ed" if havetotem in dead else "s"))
cli.msg(chan, "\n".join(message))
if chk_win(cli): # if after the last person is killed, one side wins, then actually end the game here
return
@ -3812,7 +3812,7 @@ def no_lynch(cli, nick, chan, rest):
if nick not in var.NO_LYNCH:
var.NO_LYNCH.append(nick)
cli.msg(chan, "\u0002{0}\u0002 votes to not lynch anyone today.".format(nick))
chk_decision(cli)
return
@ -4085,7 +4085,7 @@ def check_exchange(cli, actor, nick):
if nick_role == "shaman":
pm(cli, actor, "You have a \u0002{0}\u0002 totem.".format(nick_totem))
var.TOTEMS[actor] = nick_totem
elif nick_role in var.WOLFCHAT_ROLES and actor_role not in var.WOLFCHAT_ROLES:
elif nick_role in var.WOLFCHAT_ROLES and actor_role not in var.WOLFCHAT_ROLES:
pl = var.list_players()
random.shuffle(pl)
pl.remove(actor) # remove self from list
@ -4121,7 +4121,7 @@ def check_exchange(cli, actor, nick):
if actor_role == "shaman":
pm(cli, nick, "You have a \u0002{0}\u0002 totem.".format(actor_totem))
var.TOTEMS[nick] = actor_totem
elif actor_role in var.WOLFCHAT_ROLES and nick_role not in var.WOLFCHAT_ROLES:
elif actor_role in var.WOLFCHAT_ROLES and nick_role not in var.WOLFCHAT_ROLES:
pl = var.list_players()
random.shuffle(pl)
pl.remove(nick) # remove self from list
@ -4471,7 +4471,7 @@ def guard(cli, nick, chan, rest):
var.LASTGUARDED[nick] = nick
pm(cli, nick, "You have decided to guard yourself tonight.")
else:
victim = choose_target(nick, victim)
victim = choose_target(nick, victim)
if check_exchange(cli, nick, victim):
return
var.GUARDED[nick] = victim
@ -5234,7 +5234,7 @@ def transition_night(cli):
# this makes playing the day transition message easier since we can keep
# var.BITTEN around for a day after they turn
chumprole = var.get_role(chump)
if chumprole in var.WOLF_ROLES:
del var.BITTEN[chump]
continue
@ -6417,7 +6417,7 @@ def allow_deny(cli, nick, chan, rest, mode):
var.remove_allow(cloak, command)
else:
var.remove_deny(cloak, command)
if cloak in variable and variable[cloak]:
msg = "\u0002{0}\u0002 (Host: {1}) is now {2} the following {3}commands: {4}{5}.".format(
data[0], cloak, "allowed" if mode == 'allow' else "denied", "special " if mode == 'allow' else "", botconfig.CMD_CHAR, ", {0}".format(botconfig.CMD_CHAR).join(variable[cloak]))
@ -7106,7 +7106,7 @@ def game(cli, nick, chan, rest):
if rest:
gamemode = rest.lower().split()[0]
else:
gamemodes = ", ".join(["\002{}\002".format(gamemode) if len(var.list_players()) in range(var.GAME_MODES[gamemode][1],
gamemodes = ", ".join(["\002{}\002".format(gamemode) if len(var.list_players()) in range(var.GAME_MODES[gamemode][1],
var.GAME_MODES[gamemode][2]+1) else gamemode for gamemode in var.GAME_MODES.keys() if gamemode != "roles"])
cli.notice(nick, "No game mode specified. Available game modes: " + gamemodes)
return
@ -7121,7 +7121,7 @@ def game(cli, nick, chan, rest):
cli.notice(nick, "\002{0}\002 is not a valid game mode.".format(gamemode))
return
gamemode = match
if gamemode != "roles":
var.GAMEMODE_VOTES[nick] = gamemode
cli.msg(chan, "\002{0}\002 votes for the \002{1}\002 game mode.".format(nick, gamemode))

View File

@ -21,12 +21,12 @@ import traceback
import sys
import ssl
from oyoyo.parse import parse_raw_irc_command
from oyoyo.parse import parse_raw_irc_command
# Adapted from http://code.activestate.com/recipes/511490-implementation-of-the-token-bucket-algorithm/
class TokenBucket(object):
"""An implementation of the token bucket algorithm.
>>> bucket = TokenBucket(80, 0.5)
>>> bucket.consume(1)
"""
@ -54,9 +54,9 @@ class TokenBucket(object):
self._tokens = min(self.capacity, self._tokens + delta)
self.timestamp = now
return self._tokens
def add_commands(d):
def dec(cls):
for c in d:
@ -78,25 +78,25 @@ class IRCClient(object):
"""
def __init__(self, cmd_handler, **kwargs):
""" the first argument should be an object with attributes/methods named
as the irc commands. You may subclass from one of the classes in
oyoyo.cmdhandler for convenience but it is not required. The
methods should have arguments (prefix, args). prefix is
""" the first argument should be an object with attributes/methods named
as the irc commands. You may subclass from one of the classes in
oyoyo.cmdhandler for convenience but it is not required. The
methods should have arguments (prefix, args). prefix is
normally the sender of the command. args is a list of arguments.
Its recommened you subclass oyoyo.cmdhandler.DefaultCommandHandler,
this class provides defaults for callbacks that are required for
Its recommened you subclass oyoyo.cmdhandler.DefaultCommandHandler,
this class provides defaults for callbacks that are required for
normal IRC operation.
all other arguments should be keyword arguments. The most commonly
used will be nick, host and port. You can also specify an "on connect"
callback. ( check the source for others )
Warning: By default this class will not block on socket operations, this
Warning: By default this class will not block on socket operations, this
means if you use a plain while loop your app will consume 100% cpu.
To enable blocking pass blocking=True.
To enable blocking pass blocking=True.
"""
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.nickname = ""
self.hostmask = ""
self.ident = ""
@ -111,12 +111,12 @@ class IRCClient(object):
self.use_ssl = False
self.lock = threading.RLock()
self.stream_handler = lambda output, level=None: print(output)
self.tokenbucket = TokenBucket(23, 1.73)
self.__dict__.update(kwargs)
self.command_handler = cmd_handler
if self.use_ssl:
self.socket = ssl.wrap_socket(self.socket)
@ -124,8 +124,8 @@ class IRCClient(object):
def send(self, *args, **kwargs):
""" send a message to the connected server. all arguments are joined
with a space for convenience, for example the following are identical
with a space for convenience, for example the following are identical
>>> cli.send("JOIN " + some_room)
>>> cli.send("JOIN", some_room)
@ -134,7 +134,7 @@ class IRCClient(object):
the 'encoding' keyword argument (default 'utf8').
In python 3, all args must be of type str or bytes, *BUT* if they are
str they will be converted to bytes with the encoding specified by the
'encoding' keyword argument (default 'utf8').
'encoding' keyword argument (default 'utf8').
"""
with self.lock:
# Convert all args to bytes if not already
@ -154,14 +154,14 @@ class IRCClient(object):
msg = bytes(" ", "utf_8").join(bargs)
self.stream_handler('---> send {0}'.format(str(msg)[1:]))
while not self.tokenbucket.consume(1):
time.sleep(0.3)
self.socket.send(msg + bytes("\r\n", "utf_8"))
def connect(self):
""" initiates the connection to the server set in self.host:self.port
and returns a generator object.
""" initiates the connection to the server set in self.host:self.port
and returns a generator object.
>>> cli = IRCClient(my_handler, host="irc.freenode.net", port=6667)
>>> g = cli.connect()
@ -183,32 +183,32 @@ class IRCClient(object):
break
if not self.blocking:
self.socket.setblocking(0)
if not self.sasl_auth:
self.send("PASS {0}:{1}".format(self.authname if self.authname else self.nickname,
self.send("PASS {0}:{1}".format(self.authname if self.authname else self.nickname,
self.password if self.password else "NOPASS"))
else:
self.cap("LS")
self.nick(self.nickname)
self.user(self.ident, self.real_name)
if self.sasl_auth:
self.cap("REQ", "multi-prefix")
self.cap("REQ", "sasl")
if self.connect_cb:
try:
self.connect_cb(self)
except Exception as e:
traceback.print_exc()
raise e
buffer = bytes()
while not self._end:
try:
buffer += self.socket.recv(1024)
except socket.error as e:
except socket.error as e:
if False and not self.blocking and e.errno == 11:
pass
else:
@ -219,14 +219,14 @@ class IRCClient(object):
for el in data:
prefix, command, args = parse_raw_irc_command(el)
try:
enc = "utf8"
fargs = [arg.decode(enc) for arg in args if isinstance(arg,bytes)]
except UnicodeDecodeError:
enc = "latin1"
fargs = [arg.decode(enc) for arg in args if isinstance(arg,bytes)]
self.stream_handler("processCommand ({2}){0}({1})".format(command,
fargs, prefix), level="debug")
try:
@ -244,7 +244,7 @@ class IRCClient(object):
raise e # ?
yield True
finally:
if self.socket:
if self.socket:
self.stream_handler('closing socket')
self.socket.close()
yield False
@ -291,4 +291,4 @@ class IRCClient(object):
if not next(conn):
self.stream_handler("Calling sys.exit()...", level="warning")
sys.exit()

View File

@ -59,7 +59,7 @@ def parse_raw_irc_command(element):
if args[0].startswith(bytes(':', 'utf_8')):
args = [bytes(" ", "utf_8").join(args)[1:]]
else:
for idx, arg in enumerate(args):
for idx, arg in enumerate(args):
if arg.startswith(bytes(':', 'utf_8')):
args = args[:idx] + [bytes(" ", 'utf_8').join(args[idx:])[1:]]
break
@ -87,4 +87,4 @@ def parse_nick(name):
return (nick, mode, rest, None)
return (nick, mode, user, host)

View File

@ -82,7 +82,7 @@ DISABLE_DEBUG_MODE_STASIS = True
# Minimum number of players needed for mad scientist to skip over dead people when determining who is next to them
# Set to 0 to always skip over dead players. Note this is number of players that !joined, NOT number of players currently alive
MAD_SCIENTIST_SKIPS_DEAD_PLAYERS = 16
MAD_SCIENTIST_SKIPS_DEAD_PLAYERS = 16
CARE_BOLD = False
CARE_COLOR = False
@ -308,7 +308,7 @@ def is_owner(nick, cloak=None, acc=None):
def plural(role):
bits = role.split()
bits[-1] = {"person": "people", "wolf": "wolves"}.get(bits[-1], bits[-1] + "s")
return " ".join(bits)
return " ".join(bits)
def list_players(roles = None):
if roles == None:
@ -373,7 +373,7 @@ def role_order():
vils = [role for role in ROLE_GUIDE.keys() if role not in WOLFTEAM_ROLES+templates]
vils.sort()
return WOLFTEAM_ROLES + vils + templates
def break_long_message(phrases, joinstr = " "):
message = ""

View File

@ -152,12 +152,12 @@ def generate(fdict, permissions=True, **kwargs):
innerf.aftergame = False
innerf.__doc__ = f.__doc__
return innerf
return dec
return lambda *args, **kwarargs: cmd(*args, **kwarargs) if kwarargs else cmd(*args, **kwargs)
def unhook(hdict, hookid):
for cmd in list(hdict.keys()):
for x in hdict[cmd]:

View File

@ -13,13 +13,13 @@ for modfile in os.listdir("modules"):
continue # not a module
if not os.path.isfile("modules/"+modfile):
continue # not a file
modfile = modfile[:-3]
logger(None)("Loading module "+modfile)
MODULES[modfile] = getattr(__import__("modules."+modfile), modfile)
if botconfig.DEFAULT_MODULE in MODULES.keys():
CURRENT_MODULE = botconfig.DEFAULT_MODULE.lower()
else: