Update !roles
Now `!roles` while in a game will have the same effect as `!roles n` where n is the number of players that joined. Also got rid of string concatenation.
This commit is contained in:
parent
eef01df1f7
commit
397d7362db
@ -7709,9 +7709,9 @@ def listroles(cli, nick, chan, rest):
|
|||||||
"""Displays which roles are enabled at a certain number of players."""
|
"""Displays which roles are enabled at a certain number of players."""
|
||||||
|
|
||||||
old = {}
|
old = {}
|
||||||
txt = ""
|
msg = []
|
||||||
index = 0
|
index = 0
|
||||||
pl = len(var.list_players()) + len(var.DEAD)
|
lpl = len(var.list_players()) + len(var.DEAD)
|
||||||
roleindex = var.ROLE_INDEX
|
roleindex = var.ROLE_INDEX
|
||||||
roleguide = var.ROLE_GUIDE
|
roleguide = var.ROLE_GUIDE
|
||||||
|
|
||||||
@ -7720,18 +7720,19 @@ def listroles(cli, nick, chan, rest):
|
|||||||
rest = re.split(" +", rest.strip(), 1)
|
rest = re.split(" +", rest.strip(), 1)
|
||||||
|
|
||||||
#message if this game mode has been disabled
|
#message if this game mode has been disabled
|
||||||
if (not len(rest[0]) or rest[0].isdigit()) and var.GAME_MODES[var.CURRENT_GAMEMODE.name][4]:
|
if (not rest[0] or rest[0].isdigit()) and var.GAME_MODES[var.CURRENT_GAMEMODE.name][4]:
|
||||||
txt += " {0}: {1}roles is disabled for the {2} game mode.".format(nick, botconfig.CMD_CHAR, var.CURRENT_GAMEMODE.name)
|
msg.append("{0}: {1}roles is disabled for the {2} game mode.".format(nick, botconfig.CMD_CHAR, var.CURRENT_GAMEMODE.name))
|
||||||
rest = []
|
rest = []
|
||||||
roleindex = {}
|
roleindex = {}
|
||||||
#prepend player count if called without any arguments
|
#prepend player count if called without any arguments
|
||||||
elif not len(rest[0]) and pl > 0:
|
elif not rest[0] and lpl > 0:
|
||||||
txt += " {0}: There {1} \u0002{2}\u0002 playing.".format(nick, "is" if pl == 1 else "are", pl)
|
msg.append("{0}: There {1} \u0002{2}\u0002 playing.".format(nick, "is" if lpl == 1 else "are", lpl))
|
||||||
if var.PHASE in ["night", "day"]:
|
if var.PHASE in ["night", "day"]:
|
||||||
txt += " Using the {0} game mode.".format(var.CURRENT_GAMEMODE.name)
|
msg.append("Using the {0} game mode.".format(var.CURRENT_GAMEMODE.name))
|
||||||
|
rest = [str(lpl)]
|
||||||
|
|
||||||
#read game mode to get roles for
|
#read game mode to get roles for
|
||||||
elif len(rest[0]) and not rest[0].isdigit():
|
elif rest[0] and not rest[0].isdigit():
|
||||||
gamemode = rest[0]
|
gamemode = rest[0]
|
||||||
if gamemode not in var.GAME_MODES.keys():
|
if gamemode not in var.GAME_MODES.keys():
|
||||||
gamemode, _ = complete_match(rest[0], var.GAME_MODES.keys() - ["roles"])
|
gamemode, _ = complete_match(rest[0], var.GAME_MODES.keys() - ["roles"])
|
||||||
@ -7746,14 +7747,14 @@ def listroles(cli, nick, chan, rest):
|
|||||||
rest.pop(0)
|
rest.pop(0)
|
||||||
else:
|
else:
|
||||||
if gamemode in var.GAME_MODES and var.GAME_MODES[gamemode][4]:
|
if gamemode in var.GAME_MODES and var.GAME_MODES[gamemode][4]:
|
||||||
txt += " {0}: {1}roles is disabled for the {2} game mode.".format(nick, botconfig.CMD_CHAR, gamemode)
|
msg.append("{0}: {1}roles is disabled for the {2} game mode.".format(nick, botconfig.CMD_CHAR, gamemode))
|
||||||
else:
|
else:
|
||||||
txt += " {0}: {1} is not a valid game mode.".format(nick, rest[0])
|
msg.append("{0}: {1} is not a valid game mode.".format(nick, rest[0]))
|
||||||
rest = []
|
rest = []
|
||||||
roleindex = {}
|
roleindex = {}
|
||||||
|
|
||||||
#number of players to print the game mode for
|
#number of players to print the game mode for
|
||||||
if len(rest) and rest[0].isdigit():
|
if rest and rest[0].isdigit():
|
||||||
index = int(rest[0])
|
index = int(rest[0])
|
||||||
for i in range(len(roleindex)-1, -1, -1):
|
for i in range(len(roleindex)-1, -1, -1):
|
||||||
if roleindex[i] <= index:
|
if roleindex[i] <= index:
|
||||||
@ -7762,14 +7763,11 @@ def listroles(cli, nick, chan, rest):
|
|||||||
|
|
||||||
#special ordering
|
#special ordering
|
||||||
roleguide = [(role, roleguide[role]) for role in var.role_order()]
|
roleguide = [(role, roleguide[role]) for role in var.role_order()]
|
||||||
for i in range(0, len(roleindex)):
|
for i, num in enumerate(roleindex):
|
||||||
#getting the roles at a specific player count
|
#getting the roles at a specific player count
|
||||||
if index:
|
if index and num > index:
|
||||||
if roleindex[i] < index:
|
|
||||||
continue
|
|
||||||
elif roleindex[i] > index:
|
|
||||||
break
|
break
|
||||||
txt += " {0}[{1}]{0} ".format("\u0002" if roleindex[i] <= pl else "", str(roleindex[i]))
|
msg.append("{0}[{1}]{0}".format("\u0002" if num <= lpl else "", str(num)))
|
||||||
roles = []
|
roles = []
|
||||||
for role, amount in roleguide:
|
for role, amount in roleguide:
|
||||||
direction = 1 if amount[i] > old[role] else -1
|
direction = 1 if amount[i] > old[role] else -1
|
||||||
@ -7781,17 +7779,19 @@ def listroles(cli, nick, chan, rest):
|
|||||||
temp += "({0})".format(j)
|
temp += "({0})".format(j)
|
||||||
roles.append(temp)
|
roles.append(temp)
|
||||||
old[role] = amount[i]
|
old[role] = amount[i]
|
||||||
txt += ", ".join(roles)
|
msg.append(", ".join(roles))
|
||||||
txt = txt[1:]
|
|
||||||
if not len(txt):
|
if not msg:
|
||||||
txt = "No roles are defined for {0}p games.".format(index)
|
msg = ["No roles are defined for {0}p games.".format(index)]
|
||||||
|
|
||||||
|
msg = " ".join(msg)
|
||||||
|
|
||||||
if chan == nick:
|
if chan == nick:
|
||||||
pm(cli, nick, txt)
|
pm(cli, nick, msg)
|
||||||
elif nick not in var.list_players() and var.PHASE not in ("none", "join"):
|
elif nick not in var.list_players() and var.PHASE not in ("none", "join"):
|
||||||
cli.notice(nick, txt)
|
cli.notice(nick, msg)
|
||||||
else:
|
else:
|
||||||
cli.msg(chan, txt)
|
cli.msg(chan, msg)
|
||||||
|
|
||||||
@cmd("myrole", pm=True, phases=("day", "night"))
|
@cmd("myrole", pm=True, phases=("day", "night"))
|
||||||
def myrole(cli, nick, chan, rest):
|
def myrole(cli, nick, chan, rest):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user