Skip to content
This repository has been archived by the owner on Aug 27, 2018. It is now read-only.

Commit

Permalink
Download.js Fix (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
UnseenFaith authored and CyberiumShadow committed Jan 23, 2017
1 parent d451a22 commit ccc4db0
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions commands/System/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ exports.run = (client, msg, [link, piece, folder = "Downloaded"]) => {
request.get(newURL, (error, res) => {
if (error) {
if (error.message === "Unexpected token <") return msg.channel.sendMessage(`<@!${msg.author.id}> | An error has occured: **${error.message}** | This typically happens when you try to download a file from a link that isn't raw github information. Try a raw link instead!`);
return msg.channel.sendMessage(`<@!${msg.author.id}> | An error has occured: **${error}** | We're not sure what happened here... Report this our Developers to get it checked out!`);
if (error.message === "Not Found") return msg.channel.sendMessage(`<@!${msg.author.id}> | An error has occured: **${error.message}** | This typically happens when you try to download a piece that doesn't exist. Try verifying it exists.`);
return msg.channel.sendMessage(`<@!${msg.author.id}> | An error has occured: **${error}** | We're not sure what happened here... Report this to our Developers to get it checked out!`);
}
const mod = {
exports: {},
Expand All @@ -38,29 +39,30 @@ exports.run = (client, msg, [link, piece, folder = "Downloaded"]) => {
}
return console.log(err.message);
}

const name = mod.exports.help.name;
const description = mod.exports.help.description || "No description provided.";
const type = link;
const modules = mod.exports.conf.requiredModules || "No required modules.. Yay!";

if (!name) return msg.channel.sendMessage(`<@!${msg.author.id}> | I have stopped the load of this piece because it does not have a name value, and I cannot determine the file name without it. Please ask the Developer of this piece to add it.`);
if (!type) return msg.channel.sendMessage(`<@!${msg.author.id}> | I have stopped the load of this piece because it does not have a type value, and I cannot determine the type without it. Please ask the Developer of the piece to add it.`);
if (!["command", "function", "inhibitor", "monitor", "provider"].includes(type)) return msg.channel.sendMessage(`<@!${msg.author.id}> | I have stopped the loading of this piece because its type value doesn't match those we accept. Please ask the Developer of the piece to fix it.`);
if (!["commands", "functions", "inhibitors", "monitors", "providers"].includes(type)) return msg.channel.sendMessage(`<@!${msg.author.id}> | I have stopped the loading of this piece because its type value doesn't match those we accept. Please ask the Developer of the piece to fix it.`);

switch (type) {
case "command":
case "commands":
if (client.commands.has(name)) return msg.channel.sendMessage(`<@!${msg.author.id}> | That command already exists in your bot. Aborting the load.`);
break;
case "function":
case "functions":
if (client.funcs[name]) return msg.channel.sendMessage(`<@!${msg.author.id}> | That function already exists in your bot. Aborting the load.`);
break;
case "inhibitor":
case "inhibitors":
if (client.commandInhibitors.has(name)) return msg.channel.sendMessage(`<@!${msg.author.id}> | That command inhibitor already exists in your bot. Aborting the load.`);
break;
case "monitor":
case "monitors":
if (client.messageMonitors.has(name)) return msg.channel.sendMessage(`<@!${msg.author.id}> | That message monitor already exists in your bot. Aborting the load.`);
break;
case "provider":
case "providers":
if (client.providers.has(name)) return msg.channel.sendMessage(`<@!${msg.author.id} | That provider already exists in your bot. Aborting the load.`);
break;
default:
Expand Down Expand Up @@ -102,7 +104,7 @@ ${modules}
const category = mod.exports.help.category ? mod.exports.help.category : client.funcs.toTitleCase(folder);
let message;
switch (type) {
case "command": {
case "commands": {
const dir = path.resolve(`${client.clientBaseDir}/commands/${category}/`);
m.edit(`:inbox_tray: \`Loading ${type} into ${dir}/${name}.js...\``);
await fs.ensureDirAsync(dir).catch(err => client.funcs.log(err, "error"));
Expand All @@ -115,7 +117,7 @@ ${modules}
if (message) m.edit(`:inbox_tray: ${message}`);
break;
}
case "function": {
case "functions": {
const dir = path.resolve(`${client.clientBaseDir}/functions/`);
m.edit(`:inbox_tray: \`Loading ${type} into ${dir}/${name}.js...\``);
await fs.writeFileAsync(`${dir}${path.sep}${name}.js`, res.text).catch(err => client.funcs.log(err, "error"));
Expand All @@ -124,10 +126,10 @@ ${modules}
m.edit(`:no_mobile_phones: Function load failed ${name}\n\`\`\`${response}\`\`\``);
return fs.unlinkSync(`${dir}/${name}.js`);
});
m.edit(`:inbox_tray: ${message}`);
if (message) m.edit(`:inbox_tray: ${message}`);
break;
}
case "inhibitor": {
case "inhibitors": {
const dir = path.resolve(`${client.clientBaseDir}/inhibitors/`);
m.edit(`:inbox_tray: \`Loading ${type} into ${dir}/${name}.js...\``);
await fs.writeFileAsync(`${dir}/${name}.js`, res.text).catch(err => client.funcs.log(err, "error"));
Expand All @@ -136,10 +138,10 @@ ${modules}
m.edit(`:no_mobile_phones: Inhibitor load failed ${name}\n\`\`\`${response}\`\`\``);
return fs.unlinkSync(`${dir}/${name}.js`);
});
m.edit(`:inbox_tray: ${message}`);
if (message) m.edit(`:inbox_tray: ${message}`);
break;
}
case "monitor": {
case "monitors": {
const dir = path.resolve(`${client.clientBaseDir}/monitors/`);
m.edit(`:inbox_tray: \`Loading ${type} into ${dir}/${name}.js...\``);
await fs.writeFileAsync(`${dir}/${name}.js`, res.text).catch(err => client.funcs.log(err, "error"));
Expand All @@ -148,10 +150,10 @@ ${modules}
m.edit(`:no_mobile_phones: Monitor load failed ${name}\n\`\`\`${response}\`\`\``);
return fs.unlinkSync(`${dir}/${name}.js`);
});
m.edit(`:inbox_tray: ${message}`);
if (message) m.edit(`:inbox_tray: ${message}`);
break;
}
case "provider": {
case "providers": {
const dir = path.resolve(`${client.clientBaseDir}/providers/`);
m.edit(`:inbox_tray: \`Loading ${type} into ${dir}/${name}.js...\``);
await fs.writeFileAsync(`${dir}/${name}.js`, res.text).catch(err => client.funcs.log(err, "error"));
Expand All @@ -170,7 +172,7 @@ ${modules}
const category = mod.exports.help.category ? mod.exports.help.category : client.funcs.toTitleCase(folder);
let message;
switch (type) {
case "command": {
case "commands": {
const dir = path.resolve(`${client.clientBaseDir}/commands/${category}`);
m.edit(`:inbox_tray: \`Loading ${type} into ${dir}/${name}.js...\``);
await fs.ensureDirAsync(dir).catch(err => client.funcs.log(err, "error"));
Expand All @@ -183,7 +185,7 @@ ${modules}
if (message) m.edit(`:inbox_tray: ${message}`);
break;
}
case "function": {
case "functions": {
const dir = path.resolve(`${client.clientBaseDir}/functions/`);
m.edit(`:inbox_tray: \`Loading ${type} into ${dir}/${name}.js...\``);
await fs.writeFileAsync(`${dir}/${name}.js`, res.text).catch(err => client.funcs.log(err, "error"));
Expand All @@ -195,7 +197,7 @@ ${modules}
m.edit(`:inbox_tray: ${message}`);
break;
}
case "inhibitor": {
case "inhibitors": {
const dir = path.resolve(`${client.clientBaseDir}/inhibitors/`);
m.edit(`:inbox_tray: \`Loading ${type} into ${dir}/${name}.js...\``);
await fs.writeFileAsync(`${dir}/${name}.js`, res.text).catch(err => client.funcs.log(err, "error"));
Expand All @@ -207,7 +209,7 @@ ${modules}
m.edit(`:inbox_tray: ${message}`);
break;
}
case "monitor": {
case "monitors": {
const dir = path.resolve(`${client.clientBaseDir}/monitors/`);
m.edit(`:inbox_tray: \`Loading ${type} into ${dir}/${name}.js...\``);
await fs.writeFileAsync(`${dir}/${name}.js`, res.text).catch(err => client.funcs.log(err, "error"));
Expand All @@ -219,7 +221,7 @@ ${modules}
m.edit(`:inbox_tray: ${message}`);
break;
}
case "provider": {
case "providers": {
const dir = path.resolve(`${client.clientBaseDir}/providers/`);
m.edit(`:inbox_tray: \`Loading ${type} into ${dir}/${name}.js...\``);
await fs.writeFileAsync(`${dir}/${name}.js`, res.text).catch(err => client.funcs.log(err, "error"));
Expand Down

0 comments on commit ccc4db0

Please sign in to comment.