Skip to content

Commit

Permalink
add roleadd command
Browse files Browse the repository at this point in the history
  • Loading branch information
samilawson committed Feb 23, 2019
1 parent 7348ab7 commit 4e37a56
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 1 deletion.
52 changes: 52 additions & 0 deletions commands/roleme/roleadd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const { Command } = require("discord.js-commando");
const fs = require("fs");
const path = require("path");
const jsonPath = path.join(__dirname, "../../data/servers.json");
module.exports = class RoleAddCommand extends Command {
constructor(client) {
super(client, {
name: "roleadd",
group: "roleme",
memberName: "roleadd",
description: "Adds a role to the roleme list",
examples: ["roleadd updates"],
guildOnly: true,
args: [
{
key: "role",
prompt: "Which role should be added?",
type: "role"
}
]
});
}
async run(msg, { role }) {
const data = JSON.parse(fs.readFileSync(jsonPath), "utf8");
if (
!msg.member.permissions.has("ADMINISTRATOR") &&
msg.author.id !== msg.guild.ownerID
)
return msg.reply(
":no_entry_sign: [**Invalid Permissions**]: You don't have the **Administrator** permission!"
);
if (!data[msg.guild.id].roles) {
data[msg.guild.id].roles.push({ role: role });
fs.writeFileSync(jsonPath, JSON.stringify(data, null, 2));
} else {
let duplicate = false;
let toCheck = data[msg.guild.id].roles;
for (let i = 0; i < toCheck.length; i++) {
if (toCheck.role[i] == role) {
duplicate = true;
break;
}
if (duplicate == true) {
msg.channel.send("Role is already added!");
} else {
data[msg.guild.id].roles.push({ role: role });
fs.writeFileSync(jsonPath, JSON.stringify(data, null, 2));
}
}
}
}
};
Empty file added commands/roleme/rolelist.js
Empty file.
Empty file added commands/roleme/roleme.js
Empty file.
Empty file added commands/roleme/roleremove.js
Empty file.
Empty file added commands/roleme/unroleme.js
Empty file.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ client.registry
['ns', 'NationStates'],
['fun', 'Fun'],
['util', 'Utilities'],
['moderation', 'Moderation']
['moderation', 'Moderation'],
['roleme', "RoleMe"]
])
.registerDefaultGroups()
.registerDefaultCommands()
Expand Down

0 comments on commit 4e37a56

Please sign in to comment.