Browse Source

a few bugfixes and added !coin (which should be removed), license change

master
jcao219 13 years ago
parent
commit
b85a4f47c0
  1. 24
      LICENSE
  2. 10
      decorators.py
  3. 383
      wolfgame.py

24
LICENSE

@ -1,16 +1,8 @@
Copyright (c) 2011 Jimmy Cao Copyright (c) 2011, Jimmy Cao
Permission is hereby granted, free of charge, to any person obtaining a copy All rights reserved.
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
furnished to do so, subject to the following conditions: Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
The above copyright notice and this permission notice shall be included in THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

10
decorators.py

@ -1,3 +1,13 @@
# Copyright (c) 2011, Jimmy Cao
# All rights reserved.
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
# Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
# Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from oyoyo.parse import parse_nick from oyoyo.parse import parse_nick
import botconfig import botconfig

383
wolfgame.py

@ -1,19 +1,11 @@
# Copyright (c) 2011 Jimmy Cao # Copyright (c) 2011, Jimmy Cao
# Permission is hereby granted, free of charge, to any person obtaining a copy # All rights reserved.
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights # Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is # Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
# furnished to do so, subject to the following conditions: # Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
# The above copyright notice and this permission notice shall be included in # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
from oyoyo.parse import parse_nick from oyoyo.parse import parse_nick
import var import var
@ -46,10 +38,10 @@ def connect_callback(cli):
def prepare_stuff(): def prepare_stuff():
cli.join(botconfig.CHANNEL) cli.join(botconfig.CHANNEL)
cli.msg("ChanServ", "op "+botconfig.CHANNEL) cli.msg("ChanServ", "op "+botconfig.CHANNEL)
var.USERS = [] var.USERS = []
var.CLOAKS = [] var.CLOAKS = []
@hook("whoreply") @hook("whoreply")
def on_whoreply(cli, server, dunno, chan, dunno1, def on_whoreply(cli, server, dunno, chan, dunno1,
cloak, dunno3, user, status, dunno4): cloak, dunno3, user, status, dunno4):
@ -57,7 +49,7 @@ def connect_callback(cli):
var.USERS.append(user) var.USERS.append(user)
var.CLOAKS.append(cloak) var.CLOAKS.append(cloak)
cli.who(botconfig.CHANNEL) cli.who(botconfig.CHANNEL)
@hook("nicknameinuse") @hook("nicknameinuse")
def mustghost(cli, *blah): def mustghost(cli, *blah):
cli.nick(botconfig.NICK+"_") cli.nick(botconfig.NICK+"_")
@ -65,7 +57,7 @@ def connect_callback(cli):
cli.ns_ghost() cli.ns_ghost()
cli.nick(botconfig.NICK) cli.nick(botconfig.NICK)
prepare_stuff() prepare_stuff()
@hook("unavailresource") @hook("unavailresource")
def mustrelease(cli, *blah): def mustrelease(cli, *blah):
cli.nick(botconfig.NICK+"_") cli.nick(botconfig.NICK+"_")
@ -80,14 +72,14 @@ def connect_callback(cli):
var.PHASE = "none" # "join", "day", or "night" var.PHASE = "none" # "join", "day", or "night"
var.TIMERS = [None, None] var.TIMERS = [None, None]
var.DEAD = [] var.DEAD = []
var.ORIGINAL_SETTINGS = {} var.ORIGINAL_SETTINGS = {}
var.DENIED_SETTINGS_CHANGE = [] var.DENIED_SETTINGS_CHANGE = []
var.SETTINGS_CHANGE_OPPOSITION = [] var.SETTINGS_CHANGE_OPPOSITION = []
var.SETTINGS_CHANGE_REQUESTER = None var.SETTINGS_CHANGE_REQUESTER = None
var.LAST_SAID_TIME = {} var.LAST_SAID_TIME = {}
var.GAME_START_TIME = datetime.now() # for idle checker only var.GAME_START_TIME = datetime.now() # for idle checker only
var.GRAVEYARD_LOCK = threading.RLock() var.GRAVEYARD_LOCK = threading.RLock()
var.GAME_ID = 0 var.GAME_ID = 0
@ -108,19 +100,19 @@ def mass_mode(cli, md):
# Now z equal something like [('+v', '-v'), ('asdf', 'wobosd')] # Now z equal something like [('+v', '-v'), ('asdf', 'wobosd')]
arg1 = "".join(z[0]) arg1 = "".join(z[0])
arg2 = " ".join(z[1]) + " " + " ".join([x+"!*@*" for x in z[1]]) arg2 = " ".join(z[1]) + " " + " ".join([x+"!*@*" for x in z[1]])
cli.mode(botconfig.CHANNEL, arg1, arg2) cli.mode(botconfig.CHANNEL, arg1, arg2)
def reset_settings(): def reset_settings():
for attr in list(var.ORIGINAL_SETTINGS.keys()): for attr in list(var.ORIGINAL_SETTINGS.keys()):
setattr(var, attr, var.ORIGINAL_SETTINGS[attr]) setattr(var, attr, var.ORIGINAL_SETTINGS[attr])
dict.clear(var.ORIGINAL_SETTINGS) dict.clear(var.ORIGINAL_SETTINGS)
var.SETTINGS_CHANGE_OPPOSITION = [] var.SETTINGS_CHANGE_OPPOSITION = []
var.SETTINGS_CHANGE_REQUESTER = None var.SETTINGS_CHANGE_REQUESTER = None
def reset(cli): def reset(cli):
chan = botconfig.CHANNEL chan = botconfig.CHANNEL
var.PHASE = "none" var.PHASE = "none"
@ -143,12 +135,12 @@ def reset(cli):
var.DEAD = [] var.DEAD = []
var.ROLES = {"person" : []} var.ROLES = {"person" : []}
reset_settings() reset_settings()
var.DENIED_SETTINGS_CHANGE = [] var.DENIED_SETTINGS_CHANGE = []
dict.clear(var.LAST_SAID_TIME) dict.clear(var.LAST_SAID_TIME)
@pmcmd("bye", admin_only=True) @pmcmd("bye", admin_only=True)
@cmd("bye", admin_only=True) @cmd("bye", admin_only=True)
@ -171,9 +163,9 @@ def py(cli, nick, chan, rest):
exec(rest) exec(rest)
except Exception as e: except Exception as e:
cli.msg(chan, str(type(e))+":"+str(e)) cli.msg(chan, str(type(e))+":"+str(e))
@cmd("eval", owner_only = True) @cmd("eval", owner_only = True)
def pyeval(cli, nick, chan, rest): def pyeval(cli, nick, chan, rest):
try: try:
@ -184,8 +176,8 @@ def pyeval(cli, nick, chan, rest):
cli.msg(chan, a[0:500]) cli.msg(chan, a[0:500])
except Exception as e: except Exception as e:
cli.msg(chan, str(type(e))+":"+str(e)) cli.msg(chan, str(type(e))+":"+str(e))
@cmd("restart", admin_only=True) @cmd("restart", admin_only=True)
def restart_program(cli, nick, chan, rest): def restart_program(cli, nick, chan, rest):
"""Restarts the bot.""" """Restarts the bot."""
@ -195,9 +187,9 @@ def restart_program(cli, nick, chan, rest):
print("RESTARTING") print("RESTARTING")
python = sys.executable python = sys.executable
os.execl(python, python, *sys.argv) os.execl(python, python, *sys.argv)
@cmd("op", admin_only=True) @cmd("op", admin_only=True)
def give_op(cli, nick, chan, rest): def give_op(cli, nick, chan, rest):
"""OP [(person)] Makes someone or yourself a channel operator""" """OP [(person)] Makes someone or yourself a channel operator"""
@ -207,17 +199,17 @@ def give_op(cli, nick, chan, rest):
@pmcmd("op", admin_only=True) @pmcmd("op", admin_only=True)
def give_op_pm(cli, nick, rest): def give_op_pm(cli, nick, rest):
give_op(cli, nick, botconfig.CHANNEL, rest) give_op(cli, nick, botconfig.CHANNEL, rest)
@cmd("deop", admin_only=True) @cmd("deop", admin_only=True)
def take_op(cli, nick, chan, rest): def take_op(cli, nick, chan, rest):
"""Takes operator rights from someone or yourself.""" """Takes operator rights from someone or yourself."""
if not rest.strip(): if not rest.strip():
rest = nick rest = nick
cli.msg("ChanServ", " ".join(("deop",chan,rest.strip()))) cli.msg("ChanServ", " ".join(("deop",chan,rest.strip())))
@cmd("ping") @cmd("ping")
def pinger(cli, nick, chan, rest): def pinger(cli, nick, chan, rest):
@ -240,7 +232,7 @@ def pinger(cli, nick, chan, rest):
if not var.PINGING: return if not var.PINGING: return
if user in (botconfig.NICK, nick): return # Don't ping self. if user in (botconfig.NICK, nick): return # Don't ping self.
if (var.PINGING and 'G' not in status and if (var.PINGING and 'G' not in status and
'+' not in status and cloak not in var.AWAY): '+' not in status and cloak not in var.AWAY):
TO_PING.append(user) TO_PING.append(user)
@ -257,7 +249,7 @@ def pinger(cli, nick, chan, rest):
HOOKS.pop("endofwho") HOOKS.pop("endofwho")
cli.who(chan) cli.who(chan)
@cmd("away", raw_nick=True) @cmd("away", raw_nick=True)
@pmcmd("away", raw_nick=True) @pmcmd("away", raw_nick=True)
@ -273,9 +265,9 @@ def away(cli, nick, *rest):
return return
var.AWAY.append(cloak) var.AWAY.append(cloak)
cli.notice(nick, "You are now marked as away.") cli.notice(nick, "You are now marked as away.")
@cmd("fping", admin_only=True) @cmd("fping", admin_only=True)
def fpinger(cli, nick, chan, rest): def fpinger(cli, nick, chan, rest):
var.LAST_PING = None var.LAST_PING = None
@ -314,17 +306,18 @@ def fjoin(cli, nick, chan, rest):
noticed = False noticed = False
if not rest.strip(): if not rest.strip():
join(cli, nick, chan, "") join(cli, nick, chan, "")
for a in re.split("\s+",rest): for a in re.split(" +",rest):
a = a.strip() a = a.strip()
if not a: if not a:
continue continue
ull = [u.lower() for u in var.USERS] ull = [u.lower() for u in var.USERS]
if a.lower() not in ull: if a.lower() not in ull:
if not is_fake_nick(a) and not noticed: if not is_fake_nick(a):
cli.msg(chan, nick+(": You may only fjoin fake people "+ if not noticed: # important
"or people in this channel for now.")) cli.msg(chan, nick+(": You may only fjoin fake people "+
noticed = True "or people in this channel for now."))
noticed = True
continue continue
if not is_fake_nick(a): if not is_fake_nick(a):
a = var.USERS[ull.index(a.lower())] a = var.USERS[ull.index(a.lower())]
@ -332,10 +325,10 @@ def fjoin(cli, nick, chan, rest):
join(cli, a.strip(), chan, "") join(cli, a.strip(), chan, "")
else: else:
cli.notice(nick, "No, that won't be allowed.") cli.notice(nick, "No, that won't be allowed.")
@cmd("fleave","fquit","fdel", admin_only=True) @cmd("fleave","fquit","fdel", admin_only=True)
def fleave(cli, nick, chan, rest): def fleave(cli, nick, chan, rest):
for a in re.split("\s+",rest): for a in re.split(" +",rest):
a = a.strip() a = a.strip()
if not a: if not a:
continue continue
@ -347,19 +340,19 @@ def fleave(cli, nick, chan, rest):
elif a.lower() not in pll: elif a.lower() not in pll:
cli.msg(chan, nick+": That could not be done.") cli.msg(chan, nick+": That could not be done.")
@cmd("fstart", admin_only=True) @cmd("fstart", admin_only=True)
def fstart(cli, nick, chan, rest): def fstart(cli, nick, chan, rest):
var.CAN_START_TIME = datetime.now() var.CAN_START_TIME = datetime.now()
cli.msg(chan, "\u0002{0}\u0002 has forced the game to start.".format(nick)) cli.msg(chan, "\u0002{0}\u0002 has forced the game to start.".format(nick))
start(cli, nick, chan, rest) start(cli, nick, chan, rest)
@cmd("chankick", admin_only=True) @cmd("chankick", admin_only=True)
def chankick(cli, nick, chan, rest): def chankick(cli, nick, chan, rest):
rest = rest.split(" ", 1) rest = re.split(" +", rest, 1)
if not rest[0]: if not rest[0]:
cli.notice(nick, "Invalid syntax for this command.") cli.notice(nick, "Invalid syntax for this command.")
return return
@ -367,17 +360,17 @@ def chankick(cli, nick, chan, rest):
cli.kick(chan, *rest) cli.kick(chan, *rest)
else: else:
cli.kick(chan, nick, "No.") cli.kick(chan, nick, "No.")
@hook("kick") @hook("kick")
def on_kicked(cli, nick, chan, victim, reason): def on_kicked(cli, nick, chan, victim, reason):
if victim == botconfig.NICK: if victim == botconfig.NICK:
cli.join(botconfig.CHANNEL) cli.join(botconfig.CHANNEL)
cli.msg("ChanServ", "op "+botconfig.CHANNEL) cli.msg("ChanServ", "op "+botconfig.CHANNEL)
# cli.kick(chan, nick, "No.") # cli.kick(chan, nick, "No.")
@cmd("stats") @cmd("stats")
def stats(cli, nick, chan, rest): def stats(cli, nick, chan, rest):
@ -427,7 +420,7 @@ def hurry_up(cli, gameid=0):
if gameid != var.DAY_ID: if gameid != var.DAY_ID:
return return
var.DAY_ID = 0 var.DAY_ID = 0
chan = botconfig.CHANNEL chan = botconfig.CHANNEL
pl = var.list_players() pl = var.list_players()
avail = len(pl) - len(var.WOUNDED) avail = len(pl) - len(var.WOUNDED)
@ -450,25 +443,25 @@ def hurry_up(cli, gameid=0):
for plr in pl: for plr in pl:
var.VOTES[plr] = [None] * (votesneeded - 1) var.VOTES[plr] = [None] * (votesneeded - 1)
@cmd("fnight", admin_only=True) @cmd("fnight", admin_only=True)
def fnight(cli, nick, chan, rest): def fnight(cli, nick, chan, rest):
if var.PHASE != "day": if var.PHASE != "day":
cli.notice(nick, "It is not daytime.") cli.notice(nick, "It is not daytime.")
else: else:
hurry_up(cli) hurry_up(cli)
@cmd("fday", admin_only=True) @cmd("fday", admin_only=True)
def fday(cli, nick, chan, rest): def fday(cli, nick, chan, rest):
if var.PHASE != "night": if var.PHASE != "night":
cli.notice(nick, "It is not nighttime.") cli.notice(nick, "It is not nighttime.")
else: else:
transition_day(cli) transition_day(cli)
def chk_decision(cli): def chk_decision(cli):
chan = botconfig.CHANNEL chan = botconfig.CHANNEL
pl = var.list_players() pl = var.list_players()
@ -526,7 +519,7 @@ def chk_traitor(cli):
cli.msg(tt, ('HOOOOOOOOOWL. You have become... a wolf!\n'+ cli.msg(tt, ('HOOOOOOOOOWL. You have become... a wolf!\n'+
'It is up to you to avenge your fallen leaders!')) 'It is up to you to avenge your fallen leaders!'))
def chk_win(cli): def chk_win(cli):
""" Returns True if someone won """ """ Returns True if someone won """
@ -550,7 +543,7 @@ def chk_win(cli):
cli.msg(chan, ("Game over! There are more wolves than "+ cli.msg(chan, ("Game over! There are more wolves than "+
"villagers. The wolves eat everyone, and win.")) "villagers. The wolves eat everyone, and win."))
elif (not var.ROLES["wolf"] and elif (not var.ROLES["wolf"] and
not var.ROLES["traitor"] and not var.ROLES["traitor"] and
not var.ROLES["werecrow"]): not var.ROLES["werecrow"]):
cli.msg(chan, ("Game over! All the wolves are dead! The villagers "+ cli.msg(chan, ("Game over! All the wolves are dead! The villagers "+
"chop them up, BBQ them, and have a hearty meal.")) "chop them up, BBQ them, and have a hearty meal."))
@ -657,21 +650,21 @@ def del_player(cli, nick, forced_death = False):
var.VOTES[k].remove(nick) var.VOTES[k].remove(nick)
chk_decision(cli) chk_decision(cli)
return ret return ret
@hook("ping") @hook("ping")
def on_ping(cli, prefix, server): def on_ping(cli, prefix, server):
cli.send('PONG', server) cli.send('PONG', server)
def reaper(cli, gameid): def reaper(cli, gameid):
# check to see if idlers need to be killed. # check to see if idlers need to be killed.
var.IDLE_WARNED = [] var.IDLE_WARNED = []
if not var.WARN_IDLE_TIME or not var.KILL_IDLE_TIME: if not var.WARN_IDLE_TIME or not var.KILL_IDLE_TIME:
return return
while gameid == var.GAME_ID: while gameid == var.GAME_ID:
with var.GRAVEYARD_LOCK: with var.GRAVEYARD_LOCK:
to_warn = [] to_warn = []
@ -679,11 +672,11 @@ def reaper(cli, gameid):
for nick in var.list_players(): for nick in var.list_players():
lst = var.LAST_SAID_TIME.get(nick, var.GAME_START_TIME) lst = var.LAST_SAID_TIME.get(nick, var.GAME_START_TIME)
tdiff = datetime.now() - lst tdiff = datetime.now() - lst
if (tdiff > timedelta(seconds=var.WARN_IDLE_TIME) and if (tdiff > timedelta(seconds=var.WARN_IDLE_TIME) and
nick not in var.IDLE_WARNED): nick not in var.IDLE_WARNED):
to_warn.append(nick) to_warn.append(nick)
var.IDLE_WARNED.append(nick) var.IDLE_WARNED.append(nick)
var.LAST_SAID_TIME[nick] = (datetime.now() - var.LAST_SAID_TIME[nick] = (datetime.now() -
timedelta(seconds=var.WARN_IDLE_TIME)) # Give him a chance timedelta(seconds=var.WARN_IDLE_TIME)) # Give him a chance
elif (tdiff > timedelta(seconds=var.KILL_IDLE_TIME) and elif (tdiff > timedelta(seconds=var.KILL_IDLE_TIME) and
nick in var.IDLE_WARNED): nick in var.IDLE_WARNED):
@ -707,17 +700,17 @@ def reaper(cli, gameid):
cli.msg(chan, ("{0}: \u0002You have been idling for a while. "+ cli.msg(chan, ("{0}: \u0002You have been idling for a while. "+
"Please remember to say something soon or you "+ "Please remember to say something soon or you "+
"might be declared dead.\u0002").format(", ".join(x))) "might be declared dead.\u0002").format(", ".join(x)))
sleep(10) sleep(10)
@cmd("") # update last said @cmd("") # update last said
def update_last_said(cli, nick, *rest): def update_last_said(cli, nick, *rest):
if var.PHASE not in ("join", "none"): if var.PHASE not in ("join", "none"):
var.LAST_SAID_TIME[nick] = datetime.now() var.LAST_SAID_TIME[nick] = datetime.now()
@hook("join") @hook("join")
def on_join(cli, raw_nick, chan): def on_join(cli, raw_nick, chan):
nick,m,u,cloak = parse_nick(raw_nick) nick,m,u,cloak = parse_nick(raw_nick)
@ -726,7 +719,7 @@ def on_join(cli, raw_nick, chan):
var.CLOAKS.append(cloak) var.CLOAKS.append(cloak)
#if nick in var.list_players(): #if nick in var.list_players():
# cli.mode(chan, "+v", nick, nick+"!*@*") needed? # cli.mode(chan, "+v", nick, nick+"!*@*") needed?
@cmd("goat") @cmd("goat")
def goat(cli, nick, chan, rest): def goat(cli, nick, chan, rest):
"""Use a goat to interact with anyone in the channel during the day""" """Use a goat to interact with anyone in the channel during the day"""
@ -744,37 +737,37 @@ def goat(cli, nick, chan, rest):
return return
if rest.strip() in var.USERS: if rest.strip() in var.USERS:
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()))
@hook("nick") @hook("nick")
def on_nick(cli, prefix, nick): def on_nick(cli, prefix, nick):
prefix,u,m,cloak = parse_nick(prefix) prefix,u,m,cloak = parse_nick(prefix)
if prefix in var.DENIED_SETTINGS_CHANGE: if prefix in var.DENIED_SETTINGS_CHANGE:
var.DENIED_SETTINGS_CHANGE.append(nick) var.DENIED_SETTINGS_CHANGE.append(nick)
var.DENIED_SETTINGS_CHANGE.remove(prefix) var.DENIED_SETTINGS_CHANGE.remove(prefix)
if prefix in var.USERS: if prefix in var.USERS:
var.USERS.remove(prefix) var.USERS.remove(prefix)
var.CLOAKS.remove(cloak) var.CLOAKS.remove(cloak)
var.USERS.append(nick) var.USERS.append(nick)
var.CLOAKS.append(cloak) var.CLOAKS.append(cloak)
opl = [] opl = []
for k,v in var.ORIGINAL_ROLES.items(): for k,v in var.ORIGINAL_ROLES.items():
if prefix in v: if prefix in v:
var.ORIGINAL_ROLES[k].remove(prefix) var.ORIGINAL_ROLES[k].remove(prefix)
var.ORIGINAL_ROLES[k].append(nick) var.ORIGINAL_ROLES[k].append(nick)
break break
if prefix in var.list_players(): if prefix in var.list_players():
r = var.ROLES[var.get_role(prefix)] r = var.ROLES[var.get_role(prefix)]
r.append(nick) r.append(nick)
r.remove(prefix) r.remove(prefix)
if var.PHASE in ("night", "day"): if var.PHASE in ("night", "day"):
if var.VICTIM == prefix: if var.VICTIM == prefix:
var.VICTIM = nick var.VICTIM = nick
@ -796,7 +789,7 @@ def on_nick(cli, prefix, nick):
del var.GUNNERS[nick] del var.GUNNERS[nick]
if nick in var.CURSED: if nick in var.CURSED:
var.CURSED.remove(nick) var.CURSED.remove(nick)
if var.PHASE == "day": if var.PHASE == "day":
if prefix in var.WOUNDED: if prefix in var.WOUNDED:
var.WOUNDED.remove(prefix) var.WOUNDED.remove(prefix)
@ -812,8 +805,8 @@ def on_nick(cli, prefix, nick):
v.append(nick) v.append(nick)
else: else:
return return
def leave(cli, what, nick, why=""): def leave(cli, what, nick, why=""):
"""Exit the game.""" """Exit the game."""
if why and why == botconfig.CHANGING_HOST_QUIT_MESSAGE: if why and why == botconfig.CHANGING_HOST_QUIT_MESSAGE:
@ -856,7 +849,7 @@ hook("kick")(lambda cli, nick, *rest: leave(cli, "kick", parse_nick(rest[1])[0])
def begin_day(cli): def begin_day(cli):
chan = botconfig.CHANNEL chan = botconfig.CHANNEL
# Reset nighttime variables # Reset nighttime variables
var.VICTIM = "" # nickname of kill victim var.VICTIM = "" # nickname of kill victim
var.ACTED_WOLVES = set() var.ACTED_WOLVES = set()
@ -866,7 +859,7 @@ def begin_day(cli):
var.OBSERVED = {} # those whom werecrows have observed var.OBSERVED = {} # those whom werecrows have observed
var.HVISITED = {} var.HVISITED = {}
var.GUARDED = {} var.GUARDED = {}
cli.msg(chan, ("The villagers must now vote for whom to lynch. "+ cli.msg(chan, ("The villagers must now vote for whom to lynch. "+
'Use "{0}lynch <nick>" to cast your vote. 3 votes '+ 'Use "{0}lynch <nick>" to cast your vote. 3 votes '+
'are required to lynch.').format(botconfig.CMD_CHAR)) 'are required to lynch.').format(botconfig.CMD_CHAR))
@ -877,9 +870,9 @@ def begin_day(cli):
var.TIMERS[1] = t var.TIMERS[1] = t
var.TIMERS[1].daemon = True var.TIMERS[1].daemon = True
t.start() t.start()
def transition_day(cli, gameid=0): def transition_day(cli, gameid=0):
if gameid: if gameid:
if gameid != var.NIGHT_ID: if gameid != var.NIGHT_ID:
@ -888,22 +881,22 @@ def transition_day(cli, gameid=0):
var.PHASE = "day" var.PHASE = "day"
var.GOATED = False var.GOATED = False
chan = botconfig.CHANNEL chan = botconfig.CHANNEL
if not len(var.SEEN)+len(var.ACTED_WOLVES) and var.FIRST_NIGHT and var.ROLES["seer"]: if not len(var.SEEN)+len(var.ACTED_WOLVES) and var.FIRST_NIGHT and var.ROLES["seer"]:
cli.msg(botconfig.CHANNEL, ("The \u0002{0}\u0002, a \u0002wolf\u0002, and \u0002{1}\u0002, a \u0002seer\u0002 "+ cli.msg(botconfig.CHANNEL, ("The \u0002{0}\u0002, a \u0002wolf\u0002, and \u0002{1}\u0002, a \u0002seer\u0002 "+
"were both found dead in their beds.").format(var.ROLES["wolf"][0], "were both found dead in their beds.").format(var.ROLES["wolf"][0],
var.ROLES["seer"][0])) var.ROLES["seer"][0]))
for x in (var.ROLES["wolf"][0],var.ROLES["seer"][0]): for x in (var.ROLES["wolf"][0],var.ROLES["seer"][0]):
del_player(cli, x) # kill them. del_player(cli, x) # kill them.
chk_win(cli) # force to end chk_win(cli) # force to end
return return
# Reset daytime variables # Reset daytime variables
var.VOTES = {} var.VOTES = {}
var.INVESTIGATED = [] var.INVESTIGATED = []
var.WOUNDED = [] var.WOUNDED = []
var.DAY_START_TIME = datetime.now() var.DAY_START_TIME = datetime.now()
td = var.DAY_START_TIME - var.NIGHT_START_TIME td = var.DAY_START_TIME - var.NIGHT_START_TIME
var.NIGHT_START_TIME = None var.NIGHT_START_TIME = None
var.NIGHT_TIMEDELTA += td var.NIGHT_TIMEDELTA += td
@ -924,7 +917,7 @@ def transition_day(cli, gameid=0):
if var.VICTIM in var.GUARDED.values(): if var.VICTIM in var.GUARDED.values():
var.VICTIM = "" # Whew... protected by guardian angel. var.VICTIM = "" # Whew... protected by guardian angel.
if not var.VICTIM: if not var.VICTIM:
message.append(random.choice(var.NO_VICTIMS_MESSAGES) + message.append(random.choice(var.NO_VICTIMS_MESSAGES) +
" All villagers, however, have survived.") " All villagers, however, have survived.")
elif var.VICTIM in var.ROLES["harlot"]: # Attacked harlot, yay no deaths elif var.VICTIM in var.ROLES["harlot"]: # Attacked harlot, yay no deaths
if var.HVISITED.get(var.VICTIM): if var.HVISITED.get(var.VICTIM):
@ -971,8 +964,8 @@ def transition_day(cli, gameid=0):
"and is now dead.").format(gangel)) "and is now dead.").format(gangel))
dead.append(gangel) dead.append(gangel)
for crow, target in iter(var.OBSERVED.items()): for crow, target in iter(var.OBSERVED.items()):
if (target in var.ROLES["harlot"] and if (target in var.ROLES["harlot"] and
target in var.HVISITED.keys() and target in var.HVISITED.keys() and
target not in dead): target not in dead):
# Was visited by a crow # Was visited by a crow
cli.msg(target, ("You suddenly remember that you were startled by the loud "+ cli.msg(target, ("You suddenly remember that you were startled by the loud "+
@ -988,7 +981,7 @@ def transition_day(cli, gameid=0):
if not del_player(cli, deadperson): if not del_player(cli, deadperson):
return return
begin_day(cli) begin_day(cli)
def chk_nightdone(cli): def chk_nightdone(cli):
if (len(var.SEEN) == len(var.ROLES["seer"]) and # Seers have seen. if (len(var.SEEN) == len(var.ROLES["seer"]) and # Seers have seen.
@ -1018,7 +1011,7 @@ def vote(cli, nick, chan, rest):
return return
pl = var.list_players() pl = var.list_players()
pl_l = [x.strip().lower() for x in pl] pl_l = [x.strip().lower() for x in pl]
rest = re.split("\s+",rest)[0].strip().lower() rest = re.split(" +",rest)[0].strip().lower()
if rest in pl_l: if rest in pl_l:
if nick in var.WOUNDED: if nick in var.WOUNDED:
cli.msg(chan, ("{0}: You are wounded and resting, "+ cli.msg(chan, ("{0}: You are wounded and resting, "+
@ -1089,7 +1082,7 @@ def shoot(cli, nick, chan, rest):
elif not var.GUNNERS[nick]: elif not var.GUNNERS[nick]:
cli.msg(nick, "You don't have any more bullets.") cli.msg(nick, "You don't have any more bullets.")
return return
victim = re.split("\s+",rest)[0].strip().lower() victim = re.split(" +",rest)[0].strip().lower()
if not victim: if not victim:
cli.notice(nick, "Not enough parameters") cli.notice(nick, "Not enough parameters")
return return
@ -1134,7 +1127,7 @@ def shoot(cli, nick, chan, rest):
cli.msg(chan, "Appears that (s)he was a \u0002{0}\u0002.".format(var.get_role(nick))) cli.msg(chan, "Appears that (s)he was a \u0002{0}\u0002.".format(var.get_role(nick)))
if not del_player(cli, nick): if not del_player(cli, nick):
return # Someone won. return # Someone won.
@pmcmd("kill") @pmcmd("kill")
@ -1152,7 +1145,7 @@ def kill(cli, nick, rest):
if var.PHASE != "night": if var.PHASE != "night":
cli.msg(nick, "You may only kill people at night.") cli.msg(nick, "You may only kill people at night.")
return return
victim = re.split("\s+",rest)[0].strip().lower() victim = re.split(" +",rest)[0].strip().lower()
if not victim: if not victim:
cli.msg(nick, "Not enough parameters") cli.msg(nick, "Not enough parameters")
return return
@ -1177,8 +1170,8 @@ def kill(cli, nick, rest):
cli.msg(nick, "You have selected \u0002{0}\u0002 to be killed".format(var.VICTIM)) cli.msg(nick, "You have selected \u0002{0}\u0002 to be killed".format(var.VICTIM))
var.ACTED_WOLVES.add(nick) var.ACTED_WOLVES.add(nick)
chk_nightdone(cli) chk_nightdone(cli)
@pmcmd("guard") @pmcmd("guard")
def guard(cli, nick, rest): def guard(cli, nick, rest):
if var.PHASE in ("none", "join"): if var.PHASE in ("none", "join"):
@ -1194,7 +1187,7 @@ def guard(cli, nick, rest):
if var.PHASE != "night": if var.PHASE != "night":
cli.msg(nick, "You may only protect people at night.") cli.msg(nick, "You may only protect people at night.")
return return
victim = re.split("\s+",rest)[0].strip().lower() victim = re.split(" +",rest)[0].strip().lower()
if not victim: if not victim:
cli.msg(nick, "Not enough parameters") cli.msg(nick, "Not enough parameters")
return return
@ -1231,7 +1224,7 @@ def observe(cli, nick, rest):
if var.PHASE != "night": if var.PHASE != "night":
cli.msg(nick, "You may only transform into a crow at night.") cli.msg(nick, "You may only transform into a crow at night.")
return return
victim = re.split("\s+", rest)[0].strip().lower() victim = re.split(" +", rest)[0].strip().lower()
if not victim: if not victim:
cli.msg(nick, "Not enough parameters") cli.msg(nick, "Not enough parameters")
return return
@ -1252,9 +1245,9 @@ def observe(cli, nick, rest):
cli.msg(nick, ("You transform into a large crow and start your flight "+ cli.msg(nick, ("You transform into a large crow and start your flight "+
"to \u0002{0}'s\u0002 house. You will return after "+ "to \u0002{0}'s\u0002 house. You will return after "+
"collecting your observations when day begins.").format(victim)) "collecting your observations when day begins.").format(victim))
@pmcmd("id") @pmcmd("id")
def investigate(cli, nick, rest): def investigate(cli, nick, rest):
if var.PHASE in ("none", "join"): if var.PHASE in ("none", "join"):
@ -1272,7 +1265,7 @@ def investigate(cli, nick, rest):
if nick in var.INVESTIGATED: if nick in var.INVESTIGATED:
cli.msg(nick, "You may only investigate one person per round.") cli.msg(nick, "You may only investigate one person per round.")
return return
victim = re.split("\s+", rest)[0].strip().lower() victim = re.split(" +", rest)[0].strip().lower()
if not victim: if not victim:
cli.msg(nick, "Not enough parameters") cli.msg(nick, "Not enough parameters")
return return
@ -1282,7 +1275,7 @@ def investigate(cli, nick, rest):
cli.msg(nick, "\u0002{0}\u0002 is currently not playing.".format(victim)) cli.msg(nick, "\u0002{0}\u0002 is currently not playing.".format(victim))
return return
victim = pl[pll.index(victim)] victim = pl[pll.index(victim)]
var.INVESTIGATED.append(nick) var.INVESTIGATED.append(nick)
cli.msg(nick, ("The results of your investigation have returned. \u0002{0}\u0002"+ cli.msg(nick, ("The results of your investigation have returned. \u0002{0}\u0002"+
" is a... \u0002{1}\u0002!").format(victim, var.get_role(victim))) " is a... \u0002{1}\u0002!").format(victim, var.get_role(victim)))
@ -1291,9 +1284,9 @@ def investigate(cli, nick, rest):
for badguy in var.ROLES["wolf"] + var.ROLES["werecrow"] + var.ROLES["traitor"]: for badguy in var.ROLES["wolf"] + var.ROLES["werecrow"] + var.ROLES["traitor"]:
cli.msg(badguy, ("\u0002{0}\u0002 accidentally drops a paper. The paper reveals "+ cli.msg(badguy, ("\u0002{0}\u0002 accidentally drops a paper. The paper reveals "+
"that (s)he is the detective!").format(nick)) "that (s)he is the detective!").format(nick))
@pmcmd("visit") @pmcmd("visit")
def hvisit(cli, nick, rest): def hvisit(cli, nick, rest):
if var.PHASE in ("none", "join"): if var.PHASE in ("none", "join"):
@ -1312,7 +1305,7 @@ def hvisit(cli, nick, rest):
cli.msg(nick, ("You are already spending the night "+ cli.msg(nick, ("You are already spending the night "+
"with \u0002{0}\u0002.").format(var.HVISITED[nick])) "with \u0002{0}\u0002.").format(var.HVISITED[nick]))
return return
victim = re.split("\s+",rest)[0].strip().lower() victim = re.split(" +",rest)[0].strip().lower()
if not victim: if not victim:
cli.msg(nick, "Not enough parameters") cli.msg(nick, "Not enough parameters")
return return
@ -1331,17 +1324,17 @@ def hvisit(cli, nick, rest):
cli.msg(var.HVISITED[nick], ("You are spending the night with \u0002{0}"+ cli.msg(var.HVISITED[nick], ("You are spending the night with \u0002{0}"+
"\u0002. Have a good time!").format(nick)) "\u0002. Have a good time!").format(nick))
chk_nightdone(cli) chk_nightdone(cli)
def is_fake_nick(who): def is_fake_nick(who):
return not( ((who[0].isalpha() or (who[0] in (botconfig.CMD_CHAR, "\\", "_", "`"))) and return not( ((who[0].isalpha() or (who[0] in (botconfig.CMD_CHAR, "\\", "_", "`"))) and
not who.lower().endswith("serv"))) not who.lower().endswith("serv")))
@cmd("frole", admin_only=True) @cmd("frole", admin_only=True)
def frole(cli, nick, chan, rest): def frole(cli, nick, chan, rest):
rst = re.split("\s+",rest) rst = re.split(" +",rest)
if len(rst) < 2: if len(rst) < 2:
cli.msg(chan, "The syntax is incorrect.") cli.msg(chan, "The syntax is incorrect.")
who = rst.pop(0).strip() who = rst.pop(0).strip()
@ -1380,11 +1373,11 @@ def frole(cli, nick, chan, rest):
cli.msg(chan, "Operation successful.") cli.msg(chan, "Operation successful.")
if var.PHASE not in ('none','join'): if var.PHASE not in ('none','join'):
chk_win(cli) chk_win(cli)
@cmd("force", admin_only=True) @cmd("force", admin_only=True)
def forcepm(cli, nick, chan, rest): def forcepm(cli, nick, chan, rest):
rst = re.split("\s+",rest) rst = re.split(" +",rest)
if len(rst) < 2: if len(rst) < 2:
cli.msg(chan, "The syntax is incorrect.") cli.msg(chan, "The syntax is incorrect.")
return return
@ -1427,7 +1420,7 @@ def see(cli, nick, rest):
if nick in var.SEEN: if nick in var.SEEN:
cli.msg(nick, "You may only have one vision per round.") cli.msg(nick, "You may only have one vision per round.")
return return
victim = re.split("\s+",rest)[0].strip().lower() victim = re.split(" +",rest)[0].strip().lower()
pl = var.list_players() pl = var.list_players()
pll = [x.lower() for x in pl] pll = [x.lower() for x in pl]
if not victim: if not victim:
@ -1467,10 +1460,10 @@ def getfeatures(cli, nick, *rest):
else: else:
var.MAX_PRIVMSG_TARGETS = int(l) var.MAX_PRIVMSG_TARGETS = int(l)
break break
@pmcmd("") @pmcmd("")
def relay(cli, nick, rest): def relay(cli, nick, rest):
if var.PHASE != "night": if var.PHASE != "night":
@ -1496,7 +1489,7 @@ def transition_night(cli):
if var.TIMERS[1]: # cancel daytime-limit timer if var.TIMERS[1]: # cancel daytime-limit timer
var.TIMERS[1].cancel() var.TIMERS[1].cancel()
var.TIMERS[1] = None var.TIMERS[1] = None
var.FIRST_NIGHT = (var.ROLES == var.ORIGINAL_ROLES) var.FIRST_NIGHT = (var.ROLES == var.ORIGINAL_ROLES)
# Reset nighttime variables # Reset nighttime variables
@ -1573,7 +1566,7 @@ def transition_night(cli):
'If you visit a victim of a wolf, or visit a wolf, '+ 'If you visit a victim of a wolf, or visit a wolf, '+
'you will die. Use !visit to visit a player.')) 'you will die. Use !visit to visit a player.'))
cli.msg(harlot, "Players: "+", ".join(pl)) cli.msg(harlot, "Players: "+", ".join(pl))
for g_angel in var.ROLES["guardian angel"]: for g_angel in var.ROLES["guardian angel"]:
pl = ps[:] pl = ps[:]
pl.remove(g_angel) pl.remove(g_angel)
@ -1589,7 +1582,7 @@ def transition_night(cli):
"identity of all users, even traitors.")) "identity of all users, even traitors."))
for d in var.ROLES["village drunk"]: for d in var.ROLES["village drunk"]:
cli.msg(d, 'You have been drinking too much! You are the \u0002village drunk\u0002.') cli.msg(d, 'You have been drinking too much! You are the \u0002village drunk\u0002.')
for g in tuple(var.GUNNERS.keys()): for g in tuple(var.GUNNERS.keys()):
gun_msg = ("You hold a gun that shoots special silver bullets. You may only use it "+ gun_msg = ("You hold a gun that shoots special silver bullets. You may only use it "+
"during the day. If you shoot a wolf, (s)he will die instantly, but if you "+ "during the day. If you shoot a wolf, (s)he will die instantly, but if you "+
@ -1606,7 +1599,7 @@ def transition_night(cli):
"check for PMs from me for instructions. "+ "check for PMs from me for instructions. "+
"If you did not receive one, simply sit back, "+ "If you did not receive one, simply sit back, "+
"relax, and wait patiently for morning.")) "relax, and wait patiently for morning."))
# cli.msg(chan, "DEBUG: "+str(var.ROLES)) # cli.msg(chan, "DEBUG: "+str(var.ROLES))
if not var.ROLES["wolf"]: # Probably something interesting going on. if not var.ROLES["wolf"]: # Probably something interesting going on.
chk_nightdone(cli) chk_nightdone(cli)
@ -1626,7 +1619,7 @@ def cgamemode(cli, *args):
gm = var.GAME_MODES[md](modeargs[0]) gm = var.GAME_MODES[md](modeargs[0])
for attr in dir(gm): for attr in dir(gm):
val = getattr(gm, attr) val = getattr(gm, attr)
if (hasattr(var, attr) and not callable(val) if (hasattr(var, attr) and not callable(val)
and not attr.startswith("_")): and not attr.startswith("_")):
var.ORIGINAL_SETTINGS[attr] = getattr(var, attr) var.ORIGINAL_SETTINGS[attr] = getattr(var, attr)
setattr(var, attr, val) setattr(var, attr, val)
@ -1636,12 +1629,12 @@ def cgamemode(cli, *args):
return False return False
else: else:
cli.msg(chan, "Mode \u0002{0}\u0002 not found.".format(modeargs[0])) cli.msg(chan, "Mode \u0002{0}\u0002 not found.".format(modeargs[0]))
@cmd("start") @cmd("start")
def start(cli, nick, chan, rest): def start(cli, nick, chan, rest):
villagers = var.list_players() villagers = var.list_players()
if var.PHASE == "none": if var.PHASE == "none":
cli.notice(nick, "No game is currently running.") cli.notice(nick, "No game is currently running.")
return return
@ -1661,15 +1654,15 @@ def start(cli, nick, chan, rest):
if len(villagers) < 4: if len(villagers) < 4:
cli.msg(chan, "{0}: Four or more players are required to play.".format(nick)) cli.msg(chan, "{0}: Four or more players are required to play.".format(nick))
return return
for pcount in range(len(villagers), 3, -1): for pcount in range(len(villagers), 3, -1):
addroles = var.ROLES_GUIDE.get(pcount) addroles = var.ROLES_GUIDE.get(pcount)
if addroles: if addroles:
break break
if var.ORIGINAL_SETTINGS: # Custom settings if var.ORIGINAL_SETTINGS: # Custom settings
while True: while True:
wvs = (addroles[var.INDEX_OF_ROLE["wolf"]] + wvs = (addroles[var.INDEX_OF_ROLE["wolf"]] +
addroles[var.INDEX_OF_ROLE["traitor"]]) addroles[var.INDEX_OF_ROLE["traitor"]])
if len(villagers) < (sum(addroles) - addroles[var.INDEX_OF_ROLE["gunner"]] - if len(villagers) < (sum(addroles) - addroles[var.INDEX_OF_ROLE["gunner"]] -
addroles[var.INDEX_OF_ROLE["cursed"]]): addroles[var.INDEX_OF_ROLE["cursed"]]):
@ -1685,8 +1678,8 @@ def start(cli, nick, chan, rest):
cli.msg(chan, "The default settings have been restored. Please !start again.") cli.msg(chan, "The default settings have been restored. Please !start again.")
var.PHASE = "join" var.PHASE = "join"
return return
var.ROLES = {} var.ROLES = {}
var.CURSED = [] var.CURSED = []
var.GUNNERS = {} var.GUNNERS = {}
@ -1701,7 +1694,7 @@ def start(cli, nick, chan, rest):
var.ROLES[role] = selected var.ROLES[role] = selected
for x in selected: for x in selected:
villagers.remove(x) villagers.remove(x)
# Now for the villager roles # Now for the villager roles
# Select cursed (just a villager) # Select cursed (just a villager)
if var.ROLES["cursed"]: if var.ROLES["cursed"]:
@ -1737,19 +1730,19 @@ def start(cli, nick, chan, rest):
var.NIGHT_TIMEDELTA = timedelta(0) var.NIGHT_TIMEDELTA = timedelta(0)
var.DAY_START_TIME = None var.DAY_START_TIME = None
var.NIGHT_START_TIME = None var.NIGHT_START_TIME = None
if not var.START_WITH_DAY: if not var.START_WITH_DAY:
transition_night(cli) transition_night(cli)
else: else:
transition_day(cli) transition_day(cli)
# DEATH TO IDLERS! # DEATH TO IDLERS!
reapertimer = threading.Thread(None, reaper, args=(cli,var.GAME_ID)) reapertimer = threading.Thread(None, reaper, args=(cli,var.GAME_ID))
reapertimer.daemon = True reapertimer.daemon = True
reapertimer.start() reapertimer.start()
@cmd("game", admin_only=var.GAME_COMMAND_ADMIN_ONLY) @cmd("game", admin_only=var.GAME_COMMAND_ADMIN_ONLY)
def game(cli, nick, chan, rest): def game(cli, nick, chan, rest):
pl = var.list_players() pl = var.list_players()
@ -1772,7 +1765,7 @@ def game(cli, nick, chan, rest):
return return
rest = rest.strip().lower() rest = rest.strip().lower()
if rest: if rest:
if cgamemode(cli, *re.split("\s+",rest)): if cgamemode(cli, *re.split(" +",rest)):
var.SETTINGS_CHANGE_REQUESTER = nick var.SETTINGS_CHANGE_REQUESTER = nick
cli.msg(chan, ("\u0002{0}\u0002 has changed the "+ cli.msg(chan, ("\u0002{0}\u0002 has changed the "+
"game settings successfully. To "+ "game settings successfully. To "+
@ -1781,7 +1774,7 @@ def game(cli, nick, chan, rest):
var.CAN_START_TIME = datetime.now() + timedelta(seconds=var.EXTRA_WAIT) * 2 var.CAN_START_TIME = datetime.now() + timedelta(seconds=var.EXTRA_WAIT) * 2
cli.msg(chan, "The wait time has also been extended.") cli.msg(chan, "The wait time has also been extended.")
@cmd("no") @cmd("no")
def nay(cli, nick, chan, rest): def nay(cli, nick, chan, rest):
pl = var.list_players() pl = var.list_players()
@ -1810,8 +1803,8 @@ def nay(cli, nick, chan, rest):
needed - len(var.SETTINGS_CHANGE_OPPOSITION), needed - len(var.SETTINGS_CHANGE_OPPOSITION),
"s" if needed > len(var.SETTINGS_CHANGE_OPPOSITION) + 1 else "")) "s" if needed > len(var.SETTINGS_CHANGE_OPPOSITION) + 1 else ""))
@cmd("wait") @cmd("wait")
def wait(cli, nick, chan, rest): def wait(cli, nick, chan, rest):
pl = var.list_players() pl = var.list_players()
@ -1838,7 +1831,7 @@ def wait(cli, nick, chan, rest):
"{1} seconds.").format(nick, var.EXTRA_WAIT)) "{1} seconds.").format(nick, var.EXTRA_WAIT))
@cmd("fwait", admin_only=True) @cmd("fwait", admin_only=True)
def fwait(cli, nick, chan, rest): def fwait(cli, nick, chan, rest):
pl = var.list_players() pl = var.list_players()
@ -1857,7 +1850,7 @@ def fwait(cli, nick, chan, rest):
var.WAITED += 1 var.WAITED += 1
cli.msg(chan, ("\u0002{0}\u0002 increased the wait time by "+ cli.msg(chan, ("\u0002{0}\u0002 increased the wait time by "+
"{1} seconds.").format(nick, var.EXTRA_WAIT)) "{1} seconds.").format(nick, var.EXTRA_WAIT))
@cmd("fstop",admin_only=True) @cmd("fstop",admin_only=True)
def reset_game(cli, nick, chan, rest): def reset_game(cli, nick, chan, rest):
@ -1866,22 +1859,22 @@ def reset_game(cli, nick, chan, rest):
return return
cli.msg(chan, "\u0002{0}\u0002 has forced the game to stop.".format(nick)) cli.msg(chan, "\u0002{0}\u0002 has forced the game to stop.".format(nick))
reset(cli) reset(cli)
@pmcmd("rules") @pmcmd("rules")
def pm_rules(cli, nick, rest): def pm_rules(cli, nick, rest):
cli.msg(nick, var.RULES) cli.msg(nick, var.RULES)
@cmd("rules") @cmd("rules")
def show_rules(cli, nick, chan, rest): def show_rules(cli, nick, chan, rest):
cli.msg(chan, var.RULES) cli.msg(chan, var.RULES)
@pmcmd("help", raw_nick = True) @pmcmd("help", raw_nick = True)
def help(cli, rnick, rest): def help(cli, rnick, rest):
nick, mode, user, cloak = parse_nick(rnick) nick, mode, user, cloak = parse_nick(rnick)
fns = [] fns = []
cname = rest.strip().replace(botconfig.CMD_CHAR, "").lower() cname = rest.strip().replace(botconfig.CMD_CHAR, "").lower()
if cname: if cname:
for c in (COMMANDS,PM_COMMANDS): for c in (COMMANDS,PM_COMMANDS):
@ -1917,15 +1910,15 @@ def help2(cli, nick, chan, rest):
help(cli, chan, rest) help(cli, chan, rest)
else: else:
help(cli, nick, rest) help(cli, nick, rest)
@hook("invite", raw_nick = False, admin_only = True) @hook("invite", raw_nick = False, admin_only = True)
def on_invite(cli, nick, something, chan): def on_invite(cli, nick, something, chan):
if chan == botconfig.CHANNEL: if chan == botconfig.CHANNEL:
cli.join(chan) cli.join(chan)
@cmd("admins") @cmd("admins")
def show_admins(cli, nick, chan, rest): def show_admins(cli, nick, chan, rest):
"""Pings the admins that are available.""" """Pings the admins that are available."""
@ -1934,7 +1927,7 @@ def show_admins(cli, nick, chan, rest):
@hook("whoreply") @hook("whoreply")
def on_whoreply(cli, server, dunno, chan, dunno1, def on_whoreply(cli, server, dunno, chan, dunno1,
cloak, dunno3, user, status, dunno4): cloak, dunno3, user, status, dunno4):
if (cloak in botconfig.ADMINS and 'G' not in status and if (cloak in botconfig.ADMINS and 'G' not in status and
user != botconfig.NICK and cloak not in var.AWAY): user != botconfig.NICK and cloak not in var.AWAY):
admins.append(user) admins.append(user)
@ -1948,12 +1941,12 @@ def show_admins(cli, nick, chan, rest):
HOOKS.pop("endofwho") HOOKS.pop("endofwho")
cli.who(chan) cli.who(chan)
@cmd("admin", owner_only=True) @cmd("admin", owner_only=True)
def make_admin(cli, nick, chan, rest): def make_admin(cli, nick, chan, rest):
"""Temporarily""" """Temporarily"""
rst = re.split("\s+",rest) rst = re.split(" +",rest)
if len(rst) < 1: if len(rst) < 1:
cli.msg(chan, "The syntax is incorrect.") cli.msg(chan, "The syntax is incorrect.")
return return
@ -1965,12 +1958,18 @@ def make_admin(cli, nick, chan, rest):
who = var.CLOAKS[ull.index(who.lower())] who = var.CLOAKS[ull.index(who.lower())]
botconfig.ADMINS = botconfig.ADMINS + (who,) botconfig.ADMINS = botconfig.ADMINS + (who,)
cli.msg(chan, "Operation successful.") cli.msg(chan, "Operation successful.")
@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))
#TODO: make this and other functions debug-mode only #TODO: make this and other functions debug-mode only
@cmd("coin")
def coin(cli, nick, chan, rest):
"""Ugh"""
cli.msg(chan, "\2{0}\2 tosses a coin into the air...".format(nick))
cli.msg(chan, "The coin lands on \2{0}\2.".format("heads" if random.random() < 0.5 else "tails"))

Loading…
Cancel
Save