Skip to content

Commit

Permalink
script commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragon1320 committed Jul 30, 2018
1 parent f0936d3 commit d13403d
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 14 deletions.
67 changes: 55 additions & 12 deletions src/bot/commands/addscript.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,64 @@
"use strict"

const schemas = require("../../db");

const Command = require("../command");

const addscript = new Command("addscript", "adds a new script", "js", 0, "addscript", "command", 0, false, null, function(client, message, guildDoc){

let scriptSplit = message.content.substring(message.content.split(" ").length + 1);
let scriptName = scriptSplit[1]
const addscript = new Command("addscript", "adds a new script", "js", 0, "addscript", "command", 0, false, null, function (client, message, guildDoc) {

const args = message.content.split(" ");
const command = args[0];
const name = args[1];
let code = message.content.substring(command.length + name.length + 2);

if (name === undefined) {
message.reply("name your command please.");
return;
}
if (code === "") {
message.reply("write some code please.");
return;
}

if (code.startsWith("```js")) {
code = code.substring(5);
}
if (code.startsWith("```")) {
code = code.substring(3);
}
if (code.endsWith("```")) {
code = code.substring(0, code.length - 3);
}

schemas.ScriptSchema.findOne({
match: name
}).then(doc => {

message.reply(scriptName)
if (doc === null) {
const newScript = new schemas.ScriptSchema({
local: false,
name: name,
type: "js",
permissions: 0,
match: name
});

//-addscript name code
//["-addscript", "name", "code"...]
newScript.save().then(doc => {
if (doc === null) {
message.reply("oof. doc fucked.")
} else {
message.reply("script successfully saved!")
}

// strip {prefix}addscript
// get name
// get code
// strip ```js or ```
}).catch(error => {
message.reply("oof. error on saving.")
});
return;
}
message.reply("this script name already exists, fucko.")
}).catch(error => {
message.reply("oof. error on match.")
});
});

module.exports = addscript;
module.exports = addscript;
26 changes: 24 additions & 2 deletions src/bot/commands/remscript.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
"use strict"

const schemas = require("../../db");

const Command = require("../command");

const remscript = new Command("remscript", "removes a new script", "js", 0, "remscript", "command", 0, false, null, function(client, message, guildDoc){

const remscript = new Command("remscript", "removes a new script", "js", 0, "remscript", "command", 0, false, null, function (client, message, guildDoc) {

const args = message.content.split(" ");
const command = args[0];
const name = args[1];

if (name === undefined) {
message.reply("what script you deleting, buddy?")
return;
}

schemas.ScriptSchema.findOneAndRemove({
name
}).then(doc => {
if (doc === null) {
message.reply("no script with this name, chum.")
return;
}
message.reply("you deleted a script. why.")
}).catch(error => {
message.reply("here's a nice error for you. database error.")
})
});

module.exports = remscript;

0 comments on commit d13403d

Please sign in to comment.