Skip to content

Instantly share code, notes, and snippets.

@ZucchiniZe
Created February 27, 2015 03:09
Show Gist options
  • Select an option

  • Save ZucchiniZe/6b18a19b93ca39cdb81f to your computer and use it in GitHub Desktop.

Select an option

Save ZucchiniZe/6b18a19b93ca39cdb81f to your computer and use it in GitHub Desktop.
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