improve frole template handling, don't require underscores
This commit is contained in:
parent
022da467ec
commit
c5036bceac
@ -621,7 +621,7 @@
|
|||||||
"invalid_target": "This can only be done on players in the channel or fake nicks.",
|
"invalid_target": "This can only be done on players in the channel or fake nicks.",
|
||||||
"admin_only_force": "Only full admins can force an admin-only command.",
|
"admin_only_force": "Only full admins can force an admin-only command.",
|
||||||
"operation_successful": "Operation successful.",
|
"operation_successful": "Operation successful.",
|
||||||
"frole_incorrect": "Invalid arguments for {0}frole: {1}",
|
"frole_incorrect": "Invalid arguments for {0}frole, couldn't parse \"{1}\"",
|
||||||
"not_owner": "You are not the owner.",
|
"not_owner": "You are not the owner.",
|
||||||
"invalid_permissions": "You do not have permission to use that command.",
|
"invalid_permissions": "You do not have permission to use that command.",
|
||||||
"player_joined_deadchat": "\u0002{0}\u0002 has joined the deadchat.",
|
"player_joined_deadchat": "\u0002{0}\u0002 has joined the deadchat.",
|
||||||
|
@ -5391,7 +5391,8 @@ def start(cli, nick, chan, forced = False, restart = ""):
|
|||||||
var.SPECTATING_DEADCHAT.clear()
|
var.SPECTATING_DEADCHAT.clear()
|
||||||
|
|
||||||
for role, ps in var.FORCE_ROLES.items():
|
for role, ps in var.FORCE_ROLES.items():
|
||||||
vils.difference_update(ps)
|
if role not in var.TEMPLATE_RESTRICTIONS.keys():
|
||||||
|
vils.difference_update(ps)
|
||||||
|
|
||||||
for role, count in addroles.items():
|
for role, count in addroles.items():
|
||||||
if role in var.TEMPLATE_RESTRICTIONS.keys():
|
if role in var.TEMPLATE_RESTRICTIONS.keys():
|
||||||
@ -5401,11 +5402,16 @@ def start(cli, nick, chan, forced = False, restart = ""):
|
|||||||
to_add = set()
|
to_add = set()
|
||||||
|
|
||||||
if role in var.FORCE_ROLES:
|
if role in var.FORCE_ROLES:
|
||||||
|
# Templates are handled later
|
||||||
|
if role in var.TEMPLATE_RESTRICTIONS:
|
||||||
|
continue
|
||||||
if len(var.FORCE_ROLES[role]) > count:
|
if len(var.FORCE_ROLES[role]) > count:
|
||||||
channels.Main.send(messages["error_frole_too_many"].format(role))
|
channels.Main.send(messages["error_frole_too_many"].format(role))
|
||||||
return
|
return
|
||||||
for user in var.FORCE_ROLES[role]:
|
for user in var.FORCE_ROLES[role]:
|
||||||
var.MAIN_ROLES[user] = role
|
# If multiple main roles were forced, only first one is put in MAIN_ROLES
|
||||||
|
if not user in var.MAIN_ROLES:
|
||||||
|
var.MAIN_ROLES[user] = role
|
||||||
var.ORIGINAL_MAIN_ROLES[user] = role
|
var.ORIGINAL_MAIN_ROLES[user] = role
|
||||||
to_add.add(user)
|
to_add.add(user)
|
||||||
count -= 1
|
count -= 1
|
||||||
@ -5438,13 +5444,21 @@ def start(cli, nick, chan, forced = False, restart = ""):
|
|||||||
|
|
||||||
# Now for the templates
|
# Now for the templates
|
||||||
for template, restrictions in var.TEMPLATE_RESTRICTIONS.items():
|
for template, restrictions in var.TEMPLATE_RESTRICTIONS.items():
|
||||||
if template == "sharpshooter":
|
templ_count = len(var.ROLES[template])
|
||||||
continue # sharpshooter gets applied specially
|
var.ROLES[template] = UserSet()
|
||||||
|
if template in var.FORCE_ROLES:
|
||||||
|
ps = var.FORCE_ROLES[template]
|
||||||
|
var.ROLES[template].update(ps)
|
||||||
|
templ_count -= len(ps)
|
||||||
|
# sharpshooter gets applied specially
|
||||||
|
# Don't do anything further if this template was forced on enough players already
|
||||||
|
if template == "sharpshooter" or templ_count <= 0:
|
||||||
|
continue
|
||||||
possible = pl[:]
|
possible = pl[:]
|
||||||
for cannotbe in list_players(restrictions):
|
for cannotbe in list_players(restrictions):
|
||||||
if cannotbe in possible:
|
if cannotbe in possible:
|
||||||
possible.remove(cannotbe)
|
possible.remove(cannotbe)
|
||||||
if len(possible) < len(var.ROLES[template]):
|
if len(possible) < templ_count:
|
||||||
cli.msg(chan, messages["not_enough_targets"].format(template))
|
cli.msg(chan, messages["not_enough_targets"].format(template))
|
||||||
if var.ORIGINAL_SETTINGS:
|
if var.ORIGINAL_SETTINGS:
|
||||||
var.ROLES.clear()
|
var.ROLES.clear()
|
||||||
@ -5455,13 +5469,12 @@ def start(cli, nick, chan, forced = False, restart = ""):
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
cli.msg(chan, messages["role_skipped"])
|
cli.msg(chan, messages["role_skipped"])
|
||||||
var.ROLES[template] = UserSet()
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
var.ROLES[template] = UserSet(users._get(x) for x in random.sample(possible, len(var.ROLES[template]))) # FIXME
|
var.ROLES[template].update([users._get(x) for x in random.sample(possible, templ_count)]) # FIXME
|
||||||
|
|
||||||
# Handle gunner
|
# Handle gunner
|
||||||
cannot_be_sharpshooter = get_players(var.TEMPLATE_RESTRICTIONS["sharpshooter"])
|
cannot_be_sharpshooter = get_players(var.TEMPLATE_RESTRICTIONS["sharpshooter"]) + list(var.FORCE_ROLES["gunner"])
|
||||||
gunner_list = set(var.ROLES["gunner"]) # make a copy since we mutate var.ROLES["gunner"]
|
gunner_list = set(var.ROLES["gunner"]) # make a copy since we mutate var.ROLES["gunner"]
|
||||||
num_sharpshooters = 0
|
num_sharpshooters = 0
|
||||||
for gunner in gunner_list:
|
for gunner in gunner_list:
|
||||||
@ -5470,13 +5483,11 @@ def start(cli, nick, chan, forced = False, restart = ""):
|
|||||||
elif num_sharpshooters < addroles["sharpshooter"] and gunner not in cannot_be_sharpshooter and random.random() <= var.SHARPSHOOTER_CHANCE:
|
elif num_sharpshooters < addroles["sharpshooter"] and gunner not in cannot_be_sharpshooter and random.random() <= var.SHARPSHOOTER_CHANCE:
|
||||||
var.GUNNERS[gunner] = math.ceil(var.SHARPSHOOTER_MULTIPLIER * len(pl))
|
var.GUNNERS[gunner] = math.ceil(var.SHARPSHOOTER_MULTIPLIER * len(pl))
|
||||||
var.ROLES["gunner"].remove(gunner)
|
var.ROLES["gunner"].remove(gunner)
|
||||||
var.ROLES["sharpshooter"].append(gunner)
|
var.ROLES["sharpshooter"].add(gunner)
|
||||||
num_sharpshooters += 1
|
num_sharpshooters += 1
|
||||||
else:
|
else:
|
||||||
var.GUNNERS[gunner] = math.ceil(var.SHOTS_MULTIPLIER * len(pl))
|
var.GUNNERS[gunner] = math.ceil(var.SHOTS_MULTIPLIER * len(pl))
|
||||||
|
|
||||||
var.ROLES["sharpshooter"] = UserSet(p for p in var.ROLES["sharpshooter"] if p is not None)
|
|
||||||
|
|
||||||
with var.WARNING_LOCK: # cancel timers
|
with var.WARNING_LOCK: # cancel timers
|
||||||
for name in ("join", "join_pinger", "start_votes"):
|
for name in ("join", "join_pinger", "start_votes"):
|
||||||
if name in var.TIMERS:
|
if name in var.TIMERS:
|
||||||
@ -6798,30 +6809,20 @@ def frole(var, wrapper, message):
|
|||||||
if wrapper.source not in pl and not wrapper.source.is_admin():
|
if wrapper.source not in pl and not wrapper.source.is_admin():
|
||||||
return
|
return
|
||||||
|
|
||||||
to_force = {}
|
parts = message.strip().lower().replace("=", " ").split(",")
|
||||||
|
for part in parts:
|
||||||
parts = message.strip().lower().replace(":", " ").replace(",", " ").replace("=", " ").split()
|
try:
|
||||||
if len(parts) % 2: # odd number of arguments; invalid
|
(name, role) = part.strip().split(" ", 1)
|
||||||
wrapper.send(messages["frole_incorrect"].format(botconfig.CMD_CHAR, message))
|
except ValueError:
|
||||||
return
|
wrapper.send(messages["frole_incorrect"].format(botconfig.CMD_CHAR, part))
|
||||||
|
return
|
||||||
for name, role in zip(parts[::2], parts[1::2]):
|
|
||||||
user, _ = users.complete_match(name, pl)
|
user, _ = users.complete_match(name, pl)
|
||||||
role = role.replace("_", " ")
|
role = role.replace("_", " ")
|
||||||
if role in var.ROLE_ALIASES:
|
if role in var.ROLE_ALIASES:
|
||||||
role = var.ROLE_ALIASES[role]
|
role = var.ROLE_ALIASES[role]
|
||||||
if user is None or role not in var.ROLE_GUIDE or role == var.DEFAULT_ROLE:
|
if user is None or role not in var.ROLE_GUIDE or role == var.DEFAULT_ROLE:
|
||||||
wrapper.send(messages["frole_incorrect"].format(botconfig.CMD_CHAR, message))
|
wrapper.send(messages["frole_incorrect"].format(botconfig.CMD_CHAR, part))
|
||||||
return
|
return
|
||||||
to_force[user] = role
|
|
||||||
|
|
||||||
for user, role in to_force.items():
|
|
||||||
for key, ps in tuple(var.FORCE_ROLES.items()):
|
|
||||||
if user in ps:
|
|
||||||
ps.remove(user)
|
|
||||||
if not ps:
|
|
||||||
del var.FORCE_ROLES[key]
|
|
||||||
|
|
||||||
var.FORCE_ROLES[role].add(user)
|
var.FORCE_ROLES[role].add(user)
|
||||||
|
|
||||||
wrapper.send(messages["operation_successful"])
|
wrapper.send(messages["operation_successful"])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user