-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f0936d3
commit d13403d
Showing
2 changed files
with
79 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |