Skip to content

Commit

Permalink
Updated to Clapp 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MeLlamoPablo committed Dec 5, 2016
1 parent 1b66e4b commit 6eb82fc
Show file tree
Hide file tree
Showing 15 changed files with 237 additions and 274 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,11 @@ trim_trailing_whitespace = true
end_of_line = lf
insert_final_newline = false

[package.json]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
indent_style = tab
indent_size = 4
53 changes: 25 additions & 28 deletions lib/commands/admin/add-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,32 @@ const db = require('../../modules/dbhandler/index').config;
module.exports = new Clapp.Command({
name: "add-admin",
desc: "Adds an user to the admins list. Careful when using this.",
fn: (argv, context, cb) => {
var id = argv.args.user.match(/<@([0-9]+)>/)[1];
context.summaryHandler.bot.fetchUser(id).then(user => {
if (user !== null) {
db.admins.add(user).then(added => {
if (added) {
context.botAdmins.push(user.id);
cb("The user was added as an admin.", context);
} else {
cb("Error: the user is already in the admin list");
}
}).catch(err => {
console.error(err);
cb("Sorry, an internal error occurred. Please talk to my author.");
});
} else {
cb("Error: the specified user doesn't exist.");
}
}).catch(err => {
if (err.status === 404) {
cb("Error: the specified user doesn't exist.");
} else {
console.error(err);
cb("Sorry, an internal error occurred. Please talk to my author.");
}
fn: (argv, context) => {
return new Promise((fulfill, reject) => {
let id = argv.args.user.match(/<@([0-9]+)>/)[1];
context.summaryHandler.bot.fetchUser(id).then(user => {
if (user !== null) {
db.admins.add(user).then(added => {
if (added) {
context.botAdmins.push(user.id);
fulfill("The user was added as an admin.", context);
} else {
fulfill("Error: the user is already in the admin list");
}
}).catch(reject);
} else {
fulfill("Error: the specified user doesn't exist.");
}
}).catch(err => {
if (err.status === 404) {
fulfill("Error: the specified user doesn't exist.");
} else {
reject(err);
}
});
});
},
args: [
require("./shared/arg_user.js")
],
async: true
require("./shared/user.js")
]
});
53 changes: 25 additions & 28 deletions lib/commands/admin/blacklist-add.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,32 @@ const db = require('../../modules/dbhandler/index').config;
module.exports = new Clapp.Command({
name: "blacklist-add",
desc: "Adds an user to the blacklist. That user will not be able to execute bot commands.",
fn: (argv, context, cb) => {
var id = argv.args.user.match(/<@([0-9]+)>/)[1];
context.summaryHandler.bot.fetchUser(id).then(user => {
if (user !== null) {
db.blacklist.add(user).then(added => {
if (added) {
context.blacklist.push(user.id);
cb("The user was added as to the blacklist.", context);
} else {
cb("Error: the user is already blacklisted");
}
}).catch(err => {
console.error(err);
cb("Sorry, an internal error occurred. Please talk to my author.");
});
} else {
cb("Error: the specified user doesn't exist.");
}
}).catch(err => {
if (err.status === 404) {
cb("Error: the specified user doesn't exist.");
} else {
console.error(err);
cb("Sorry, an internal error occurred. Please talk to my author.");
}
fn: (argv, context) => {
return new Promise((fulfill, reject) => {
let id = argv.args.user.match(/<@([0-9]+)>/)[1];
context.summaryHandler.bot.fetchUser(id).then(user => {
if (user !== null) {
db.blacklist.add(user).then(added => {
if (added) {
context.blacklist.push(user.id);
fulfill("The user was added as to the blacklist.", context);
} else {
fulfill("Error: the user is already blacklisted");
}
}).catch(reject);
} else {
fulfill("Error: the specified user doesn't exist.");
}
}).catch(err => {
if (err.status === 404) {
fulfill("Error: the specified user doesn't exist.");
} else {
reject(err);
}
});
});
},
args: [
require("./shared/arg_user.js")
],
async: true
require("./shared/user.js")
]
});
43 changes: 20 additions & 23 deletions lib/commands/admin/blacklist-remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,30 @@ const db = require('../../modules/dbhandler/index').config;
module.exports = new Clapp.Command({
name: "blacklist-remove",
desc: "Removes an user from the blacklist, thus being able to use the bot again.",
fn: (argv, context, cb) => {
var id = argv.args.user.match(/<@([0-9]+)>/)[1];
context.summaryHandler.bot.fetchUser(id).then(user => {
db.blacklist.remove(user).then(removed => {
if (removed) {
context.blacklist.splice(
context.blacklist.indexOf(user.id), 1
);
cb("The user was removed from the blacklist successfully", context);
fn: (argv, context) => {
return new Promise((fulfill, reject) => {
let id = argv.args.user.match(/<@([0-9]+)>/)[1];
context.summaryHandler.bot.fetchUser(id).then(user => {
db.blacklist.remove(user).then(removed => {
if (removed) {
context.blacklist.splice(
context.blacklist.indexOf(user.id), 1
);
fulfill("The user was removed from the blacklist successfully", context);
} else {
fulfill("The user is not blacklisted")
}
}).catch(reject);
}).catch(err => {
if (err.status === 404) {
fulfill("Error: the specified user doesn't exist.");
} else {
cb("The user is not blacklisted")
reject(err);
}
}).catch(err => {
console.error(err);
cb("Sorry, an internal error occurred. Please talk to my author.");
});
}).catch(err => {
if (err.status === 404) {
cb("Error: the specified user doesn't exist.");
} else {
console.error(err);
cb("Sorry, an internal error occurred. Please talk to my author.");
}
});
},
args: [
require("./shared/arg_user.js")
],
async: true
require("./shared/user.js")
]
});
51 changes: 23 additions & 28 deletions lib/commands/admin/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,29 @@ module.exports = new Clapp.Command({
name: "link",
desc: "Links an event with a role. ScheduleBot will notify all members of the role so they" +
" can confirm or reject.",
fn: (argv, context, cb) => {
var roleId = argv.args.role.match(/<@&([0-9]+)>/)[1];
var role = context.summaryHandler.masterChannel.guild.roles.get(roleId);
if (role) {
var waiting = role.members.keyArray();
fn: (argv, context) => {
return new Promise((fulfill, reject) => {
let roleId = argv.args.role.match(/<@&([0-9]+)>/)[1];
let role = context.summaryHandler.masterChannel.guild.roles.get(roleId);
if (role) {
let waiting = role.members.keyArray();

db.events.get(argv.args.id).then(event => {
if (event !== null) {
db.events.updateWaiting(event, waiting).then(() => {
cb("The event #`" + argv.args.id + "` has been linked " +
"to <@&" + roleId + ">");
}).catch(err => {
console.error(err);
cb("Sorry, an internal error occurred. Please talk to my author.");
});
db.events.get(argv.args.id).then(event => {
if (event !== null) {
db.events.updateWaiting(event, waiting).then(() => {
fulfill("The event #`" + argv.args.id + "` has been linked " +
"to <@&" + roleId + ">");
}).catch(reject);

context.summaryHandler.updateSummary(event).catch(console.error);
} else {
cb("Event #`" + argv.args.id + "` does not exist");
}
}).catch(err => {
console.error(err);
cb("Sorry, an internal error occurred. Please talk to my author.");
});
} else {
cb("Sorry, the role you specified doesn't exist");
}
context.summaryHandler.updateSummary(event).catch(console.error);
} else {
fulfill("Event #`" + argv.args.id + "` does not exist");
}
}).catch(reject);
} else {
fulfill("Sorry, the role you specified doesn't exist");
}
});
},
args: [
{
Expand All @@ -52,11 +48,10 @@ module.exports = new Clapp.Command({
{
errorMessage: "You need to mention the role for the command to work",
validate: val => {
return val.match(/<@&[0-9]+>/) ? true : false;
return !!val.match(/<@&[0-9]+>/);
}
}
]
}
],
async: true
]
});
55 changes: 27 additions & 28 deletions lib/commands/admin/remove-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,36 @@ const db = require('../../modules/dbhandler/index').config;
module.exports = new Clapp.Command({
name: "remove-admin",
desc: "Removes an user from the admin list.",
fn: (argv, context, cb) => {
if (context.botAdmins.length > 1) {
var id = argv.args.user.match(/<@([0-9]+)>/)[1];
context.summaryHandler.bot.fetchUser(id).then(user => {
db.admins.remove(user).then(removed => {
if (removed) {
context.botAdmins.splice(
context.botAdmins.indexOf(user.id), 1
);
cb("The user was removed from the admins list successfully", context);
fn: (argv, context) => {
return new Promise((fulfill, reject) => {
if (context.botAdmins.length > 1) {
let id = argv.args.user.match(/<@([0-9]+)>/)[1];
context.summaryHandler.bot.fetchUser(id).then(user => {
db.admins.remove(user).then(removed => {
if (removed) {
context.botAdmins.splice(
context.botAdmins.indexOf(user.id), 1
);
fulfill("The user was removed from the admins list successfully",
context);
} else {
fulfill("The user is not an admin")
}
}).catch(reject);
}).catch(err => {
if (err.status === 404) {
fulfill("Error: the specified user doesn't exist.");
} else {
cb("The user is not an admin")
reject(err);
}
}).catch(err => {
console.error(err);
cb("Sorry, an internal error occurred. Please talk to my author.");
});
}).catch(err => {
if (err.status === 404) {
cb("Error: the specified user doesn't exist.");
} else {
console.error(err);
cb("Sorry, an internal error occurred. Please talk to my author.");
}
});
} else {
cb("Sorry, you can't remove the only admin that there is. Add another admin first.");
}
} else {
fulfill("Sorry, you can't remove the only admin that there is." +
"Add another admin first.");
}
});
},
args: [
require("./shared/arg_user.js")
],
async: true
require("./shared/user.js")
]
});
40 changes: 19 additions & 21 deletions lib/commands/admin/remove-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@ const db = require('../../modules/dbhandler/index').events;
module.exports = new Clapp.Command({
name: "remove-event",
desc: "Removes the specified event. This action can't be undone.",
fn: (argv, context, cb) => {
db.get(argv.args.id).then(event => {
if (event !== null) {
var eventName = event.name;
var deleteSummaryPromise = context.summaryHandler.deleteSummary(event);
var deleteEventPromise = event.deleteEvent();
fn: (argv, context) => {
return new Promise((fulfill, reject) => {
db.get(argv.args.id).then(event => {
if (event !== null) {
let eventName = event.name;
let deleteSummaryPromise = context.summaryHandler.deleteSummary(event);
let deleteEventPromise = event.deleteEvent();

Promise.all([deleteSummaryPromise, deleteEventPromise]).then(() => {
cb("The event `" + eventName+ "` was successfully deleted.");
}).catch(err => {
console.error(err);
cb("Sorry, an internal error occurred. Please talk to my author.");
});
} else {
cb("Error: the specified event `" + argv.args.id + "` doesn't exist.");
}
}, err => {
console.error(err);
cb("Sorry, an internal error occurred. Please talk to my author.");
})
Promise.all([deleteSummaryPromise, deleteEventPromise]).then(() => {
fulfill("The event `" + eventName+ "` was successfully deleted.");
}).catch(err => {
console.error(err);
fulfill("Sorry, an internal error occurred. Please talk to my author.");
});
} else {
fulfill("Error: the specified event `" + argv.args.id + "` doesn't exist.");
}
}).catch(reject);
});
},
args: [
{
Expand All @@ -35,6 +34,5 @@ module.exports = new Clapp.Command({
type: "number",
required: true
}
],
async: true
]
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
{
errorMessage: "You need to mention the user for the command to work",
validate: val => {
return val.match(/<@[0-9]+>/) ? true : false;
return !!val.match(/<@[0-9]+>/);
}
}
]
Expand Down
Loading

0 comments on commit 6eb82fc

Please sign in to comment.