Created
February 27, 2015 03:09
-
-
Save ZucchiniZe/6b18a19b93ca39cdb81f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| var fs = require('fs'); | |
| var mongoose = require('mongoose'); | |
| mongoose.connect(process.env.MONGO_URL); | |
| var BotSchema = mongoose.Schema({ | |
| name: {type: String, default: '', unique: true}, | |
| runs: {type: Number, default: 0}, | |
| owner: Object, | |
| code: {type: String, default: ''} | |
| }); | |
| var Bot = mongoose.model('Bot', BotSchema); | |
| mongoose.connection.on('error', console.error.bind(console, 'connection error:')); | |
| // Grabs the code from the test.js file to be used for default/starter bot code | |
| var defaultCode = fs.readFile('test.js', 'utf8', function (err,data) { | |
| var bot = new Bot({name: 'default', code:defaultCode}) | |
| Bot.count({}).exec().then(function(c) { | |
| if(c < 1) { | |
| bot.save(); | |
| } | |
| }).then(null, function(err) { | |
| console.log(err); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment