Verified Commit 990eee82 authored by recette lemonweed's avatar recette lemonweed 🇮🇸

changed way aliases are assigned

parent 53982d3f
module.exports = {
name: "Alias",
triggers: ["alias"],
description: "Adds and removes user and server aliases. Flags can be escaped with \\",
category: "misc",
arguments: {
positional: ["trigger", "command"],
flags: {
server: [false],
remove: [false]
}
},
func: func
};
function viewAlias(aliases, trigger){
let command = aliases[trigger];
if(!command)
return;
return "\n"+trigger+" "+command.join(" ");
}
function listAliases(aliases){
let out = "";
for(let trigger in aliases){
out += viewAlias(aliases, trigger);
}
return out;
}
function func(message, args){
let strings = message.content.split(" ").slice(1);
let command = strings.slice(
Math.abs(strings.findIndex(a => !a.startsWith("-")))
).map(a => a.replace("\\-", "-"));
let trigger = command.shift();
let id = args.server && message.guild ? message.guild.id : message.author.id;
let aliasesConfig = Configs.get(id).get("aliases");
// check permissions for servers
if(!message.member.permissions.has("MANAGE_GUILD") && args.server)
return message.reply("You don't have manage guild perms.");
// remove if remove flag and alias exists
if(args.remove){
if(!trigger){
return message.reply(
"Need a trigger to remove\n```\n"+Config.trigger+"alias --remove hello```"
);
}
if(aliasesConfig.exists(trigger)){
aliasesConfig.delete(trigger);
return message.reply("Removed.");
} else {
return message.reply("Doesn't exist.");
}
}
// nothing, so print all aliases
if(!trigger)
return message.reply(listAliases(aliasesConfig) || "None set.");
// check whether trigger makes sense
if(trigger.match(/[^\w]/))
return message.reply("Can't use non-word characters in trigger.");
// if no command, print specific alias
if(!command.length)
return message.reply(viewAlias(aliasesConfig, trigger) || "Not set.");
command[0] = command[0].toLowerCase();
// check command actually exists in ika
if(!Commands[command[0]])
return message.reply(command[0]+" doesn't exist as a command.");
if(trigger === module.exports.triggers[0])
return message.reply("Not letting you brick this command.");
aliasesConfig.set(trigger, command);
message.reply("Set.");
}
......@@ -48,28 +48,6 @@ function assignDisabledCommands(id, message, args, str){
message.reply("Disabled "+commands.join(", ")+".");
}
function assignAliases(id, message, args){
let inaliases = message.content.split("\n").slice(1).map(a=>a.trim());
let aliases = {};
if(!inaliases.length)
return message.reply("Need some aliases.");
for(let alias of inaliases){
let [trigger, command] = alias.split("=");
if(!(trigger && command))
return message.reply(`Syntax is:\n\`\`\`${Config.trigger}config --aliases\nsaynice=say nice\nddg=g --ddg\`\`\``);
if(trigger.match(/[^\w]/))
return message.reply("Triggers need to be regular characters.");
trigger = trigger.toLowerCase();
command = command.replace(/\\(?=-)/, "").split(" ");
if(trigger === module.exports.name.toLowerCase())
return message.reply("You're not allowed to brick this command.");
aliases[trigger] = command;
}
Configs.get(id).set("aliases", aliases);
Configs.get(id).get("raw").set(args.setting, "\n"+inaliases.join("\n"));
message.reply("Set "+(Object.keys(aliases).length)+" aliases.");
}
let settings = {
muterole: {
assign: assignMuteRole,
......@@ -82,12 +60,6 @@ let settings = {
server: true,
user: false,
flag: [false, "dc"]
},
aliases: {
assign: assignAliases,
server: true,
user: true,
flag: [false, "alias", "al"]
}
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment