Skip to content

Commit

Permalink
Needs more failsaves
Browse files Browse the repository at this point in the history
  • Loading branch information
Remco authored and Remco committed Mar 16, 2016
1 parent 7182f3d commit 1bcf2d8
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
18 changes: 18 additions & 0 deletions runtime/customization.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ exports.replyCheck = function(what, server, callback) {
if (result.length === 0) {
return callback('notFound', -1);
} else {
if (result[0] === undefined) {
initializeServer(server);
}
if (what === 'no_permission_response') {
return callback(null, result[0].responses.no_permission_response);
} else if (what === 'nsfw_disallowed_response') {
Expand Down Expand Up @@ -160,3 +163,18 @@ exports.initializeServer = function(server) {
};
db.insert(doc);
};

function initializeServer(server) {
var doc = {
_id: server.id,
responses: {
welcome_message: 'default',
no_permission_response: 'default',
nsfw_disallowed_response: 'default'
},
settings: {
welcoming: false
}
};
db.insert(doc);
}
34 changes: 34 additions & 0 deletions runtime/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ exports.GetNSFW = function(server, channel, callback) {
if (result.length === 0) {
return callback('notFound', -1);
} else {
if (result[0] === undefined) {
initializeServer(server);
return;
}
if (result[0].nsfw_permissions.allowed.indexOf(channel) > -1) {
return callback(null, 'on');
} else {
Expand Down Expand Up @@ -221,6 +225,10 @@ exports.SetNSFW = function(server, channel, allow, callback) {
if (result.length === 0) {
return callback('notFound', -1);
} else {
if (result[0] === undefined) {
initializeServer(server);
return;
}
if (allow === 'off') {
db.update({
_id: server.id
Expand Down Expand Up @@ -259,6 +267,32 @@ exports.onlySuperBlacklist = function(server, callback) { // Used to make DB doc
}
});
};

function initializeServer(server) {
// The NaN values are acting as placeholders
var doc = {
_id: server.id,
server_is_blacklisted: false,
superUser: server.owner.id,
permissions: {
level1: ["NaN"],
level2: ["NaN"],
level3: ["NaN"]
},
nsfw_permissions: {
allowed: ["NaN"]
}
};
db.insert(doc, function(err, result) {
if (err) {
Logger.error('Error while initializing server! ' + err);
} else if (result) {
Logger.debug('Successfully made a server doc.');
}
});
}


exports.initializeServer = function(server) {
// The NaN values are acting as placeholders
var doc = {
Expand Down
16 changes: 12 additions & 4 deletions runtime/user_nsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function trackNewUser(user) { // Most of the time, this function does not need t
Logger.debug('Sucess making an UserDB doc');
}
});
};
}

exports.handleNamechange = function(user) {
db.find({
Expand All @@ -50,9 +50,13 @@ exports.handleNamechange = function(user) {
if (err) {
Logger.error('Error handing namechange! ' + err);
}
if (!result) {
if (result.length === 0) {
trackNewUser(user);
} else {
if (result[0] === undefined) {
trackNewUser(user);
return;
}
if (result[0].known_names.length > 20) {
db.update({
_id: user.id
Expand Down Expand Up @@ -80,10 +84,14 @@ exports.returnNamechanges = function(user, callback) {
if (err) {
Logger.error('Error checking user knowledge! ' + err);
}
if (!result) {
if (result.length === 0) {
trackNewUser(user);
return callback('notfound', -1);
} else {
if (result[0] === undefined) {
trackNewUser(user);
return;
}
return callback(null, result[0].known_names);
}
});
Expand All @@ -96,7 +104,7 @@ exports.checkIfKnown = function(user) {
if (err) {
Logger.error('Error checking user knowledge! ' + err);
}
if (!result) {
if (result.length === 0) {
trackNewUser(user);
} else {
return; // User is known, so exit the function
Expand Down

0 comments on commit 1bcf2d8

Please sign in to comment.