Prevent chained aliases in chatalias #43
68
chatalias.py
68
chatalias.py
@ -55,12 +55,6 @@ permission_FINFO = "utils.alias.finfo"
|
|||||||
# CODE #
|
# CODE #
|
||||||
########
|
########
|
||||||
|
|
||||||
# OnEnable
|
|
||||||
enabled = helpers_version in helpers_versions
|
|
||||||
if not enabled:
|
|
||||||
error = colorify("&6Incompatible versions detected (&chelpers.py&6)")
|
|
||||||
|
|
||||||
|
|
||||||
def safe_open_json(uuid):
|
def safe_open_json(uuid):
|
||||||
if not os.path.exists("plugins/redstoner-utils.py.dir/files/aliases"):
|
if not os.path.exists("plugins/redstoner-utils.py.dir/files/aliases"):
|
||||||
os.makedirs("plugins/redstoner-utils.py.dir/files/aliases")
|
os.makedirs("plugins/redstoner-utils.py.dir/files/aliases")
|
||||||
@ -179,8 +173,9 @@ def add(sender, args):
|
|||||||
msg(sender, "&cCould not create alias: Max_limit reached!")
|
msg(sender, "&cCould not create alias: Max_limit reached!")
|
||||||
return True
|
return True
|
||||||
args = [args[0]] + [" ".join(args[1:])]
|
args = [args[0]] + [" ".join(args[1:])]
|
||||||
data[str(uid(sender))][str(args[0])] = args[1]
|
if not add_alias_data(uid(sender), str(args[0]), args[1]):
|
||||||
save_data(uid(sender))
|
msg(sender, colorify("&c") + "Could not add this alias because it would cause some sequences to be replaced multiple times", usecolor = False)
|
||||||
|
return True
|
||||||
msg(sender, colorify("&7Alias: ") + args[0] + colorify("&7 -> " + args[1] + colorify("&7 was succesfully created!")), usecolor=sender.hasPermission("essentials.chat.color"))
|
msg(sender, colorify("&7Alias: ") + args[0] + colorify("&7 -> " + args[1] + colorify("&7 was succesfully created!")), usecolor=sender.hasPermission("essentials.chat.color"))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -196,6 +191,8 @@ def radd(sender, args):
|
|||||||
if args[3].lower() == "false":
|
if args[3].lower() == "false":
|
||||||
plugin_header(target, "Alias")
|
plugin_header(target, "Alias")
|
||||||
msg(target, "&cPlayer " + sender_name + " &cis creating an alias for you!")
|
msg(target, "&cPlayer " + sender_name + " &cis creating an alias for you!")
|
||||||
|
elif args[3].lower() != "true":
|
||||||
|
args[2] += " " + args[3]
|
||||||
if not sender.hasPermission(permission_ALL) and len(data[uid(sender)]) >= int(get_permission_content(target, permission_AMOUNT)):
|
if not sender.hasPermission(permission_ALL) and len(data[uid(sender)]) >= int(get_permission_content(target, permission_AMOUNT)):
|
||||||
msg(sender, "&cCould not create alias: Max_limit reached!")
|
msg(sender, "&cCould not create alias: Max_limit reached!")
|
||||||
if args[3].lower() == "false":
|
if args[3].lower() == "false":
|
||||||
@ -203,14 +200,37 @@ def radd(sender, args):
|
|||||||
return True
|
return True
|
||||||
if len(args) == 3:
|
if len(args) == 3:
|
||||||
args += ["true"]
|
args += ["true"]
|
||||||
data[str(uid(target))][str(args[1])] = str(args[2])
|
if not add_alias_data(uid(target), str(args[1]), str(args[2])):
|
||||||
save_data(uid(target))
|
message = colorify("&c") + "Could not add this alias because it would cause some sequences to be replaced multiple times"
|
||||||
|
msg(sender, message)
|
||||||
|
if args[3].lower() == "false":
|
||||||
|
msg(target, message)
|
||||||
|
return True
|
||||||
msg(sender, colorify("&7Alias: ") + args[1] + colorify("&7 -> " + args[2] + colorify("&7 was succesfully created!")), usecolor=target.hasPermission("essentials.chat.color"))
|
msg(sender, colorify("&7Alias: ") + args[1] + colorify("&7 -> " + args[2] + colorify("&7 was succesfully created!")), usecolor=target.hasPermission("essentials.chat.color"))
|
||||||
if args[3].lower() == "false":
|
if args[3].lower() == "false":
|
||||||
msg(target, colorify("&7Alias: ") + args[1] + colorify("&7 -> " + args[2] + colorify("&7 was succesfully created!")), usecolor=target.hasPermission("essentials.chat.color"))
|
msg(target, colorify("&7Alias: ") + args[1] + colorify("&7 -> " + args[2] + colorify("&7 was succesfully created!")), usecolor=target.hasPermission("essentials.chat.color"))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def add_alias_data(puuid, aliased, new_alias):
|
||||||
|
prior = data[puuid]
|
||||||
|
|
||||||
|
# prevent 2 -> 3 if there is 1 -> 2
|
||||||
|
if aliased not in prior:
|
||||||
|
for alias in prior.values():
|
||||||
|
if aliased in alias:
|
||||||
|
return False
|
||||||
|
|
||||||
|
# prevent 1 -> 2 if there is 2 -> 3
|
||||||
|
for sequence in prior:
|
||||||
|
if sequence in new_alias:
|
||||||
|
return False
|
||||||
|
|
||||||
|
prior[aliased] = new_alias
|
||||||
|
save_data(puuid)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def remove(sender, args):
|
def remove(sender, args):
|
||||||
plugin_header(sender, "Alias")
|
plugin_header(sender, "Alias")
|
||||||
try:
|
try:
|
||||||
@ -256,7 +276,7 @@ def rlist_alias(sender, args):
|
|||||||
plugin_header(sender, "Alias")
|
plugin_header(sender, "Alias")
|
||||||
target = get_player(args[0])
|
target = get_player(args[0])
|
||||||
if is_player(sender):
|
if is_player(sender):
|
||||||
sender_name = colorify(sender.getDisplayName)
|
sender_name = colorify(sender.getDisplayName())
|
||||||
else:
|
else:
|
||||||
sender_name = colorify("&6Console")
|
sender_name = colorify("&6Console")
|
||||||
if len(args) == 1:
|
if len(args) == 1:
|
||||||
@ -264,11 +284,9 @@ def rlist_alias(sender, args):
|
|||||||
msg(sender, "Player " + args[0] + " has following aliases (" + str(len(data[uid(target)])) + " in total):")
|
msg(sender, "Player " + args[0] + " has following aliases (" + str(len(data[uid(target)])) + " in total):")
|
||||||
if args[1].lower() == "false":
|
if args[1].lower() == "false":
|
||||||
plugin_header(target, "Alias")
|
plugin_header(target, "Alias")
|
||||||
msg(target, "&cPlayer " + sender_name + " &cis listing your aliases (" + str(len(data[uid(target)])) + " in total):")
|
msg(target, "&cPlayer " + sender_name + " &cis listing your aliases")
|
||||||
for word, alias in data[str(uid(target))].items():
|
for word, alias in data[str(uid(target))].items():
|
||||||
msg(sender, colorify("&7") + word + colorify("&7 -> ") + alias, usecolor=target.hasPermission("essentials.chat.color"))
|
msg(sender, colorify("&7") + word + colorify("&7 -> ") + alias, usecolor=target.hasPermission("essentials.chat.color"))
|
||||||
if args[1].lower() == "false":
|
|
||||||
msg(target, colorify("&7") + word + colorify("&7 -> ") + alias, usecolor=target.hasPermission("essentials.chat.color"))
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@ -323,16 +341,34 @@ def save_data_thread(uuid):
|
|||||||
# Subcommands:
|
# Subcommands:
|
||||||
subcommands = {
|
subcommands = {
|
||||||
"help": help,
|
"help": help,
|
||||||
|
"?": help,
|
||||||
"add": add,
|
"add": add,
|
||||||
"remove": remove,
|
"remove": remove,
|
||||||
|
"del": remove,
|
||||||
|
"delete": remove,
|
||||||
"player": remote,
|
"player": remote,
|
||||||
|
"remote": remote,
|
||||||
"list": list_alias
|
"list": list_alias
|
||||||
}
|
}
|
||||||
|
|
||||||
remotes = {
|
remotes = {
|
||||||
"add": radd,
|
"add": radd,
|
||||||
"remove": rremove,
|
"remove": rremove,
|
||||||
|
"del": rremove,
|
||||||
|
"delete": rremove,
|
||||||
"list": rlist_alias,
|
"list": rlist_alias,
|
||||||
}
|
}
|
||||||
Status API Training Shop Blog About
|
|
||||||
© 2016 GitHub, Inc. Terms Privacy Security Contact Help
|
# OnModuleLoad
|
||||||
|
|
||||||
|
enabled = helpers_version in helpers_versions
|
||||||
|
if not enabled:
|
||||||
|
error = colorify("&6Incompatible versions detected (&chelpers.py&6)")
|
||||||
|
for player in server.getOnlinePlayers():
|
||||||
|
if enabled:
|
||||||
|
t = threading.Thread(target=load_data, args=(uid(player), ))
|
||||||
|
t.daemon = True
|
||||||
|
t.start()
|
||||||
|
else:
|
||||||
|
if player.hasPermission(permission_FINFO):
|
||||||
|
disabled_fallback(player)
|
||||||
|
Reference in New Issue
Block a user