Skip to content

Commit

Permalink
If unibot doesn't have realPass, delete it and recreate it with `re…
Browse files Browse the repository at this point in the history
…alPass`
  • Loading branch information
eyeballcode committed Dec 17, 2015
1 parent 930f902 commit e512c8a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
47 changes: 23 additions & 24 deletions Chatbot-Unibot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,33 @@ var ChatAPI = require('./modules/JS-TFHCAPI');
var mongo = require('mongodb').MongoClient;
var commands = require('./Chatbot-Unibot-Commands');

var unibot;
mongo.connect('mongodb://localhost:27017/TFHWebSite', {}, function (err, db) {
var users = db.collection('users');
users.findOne({name: 'UniBot'}, function (err, unibot2) {
unibot = unibot2;
});
var users;
mongo.connect('mongodb://localhost:27017/TFHWebSite', {}, function (err, db1) {
users = db1.collection('users');
});
module.exports = function (id) {
new ChatAPI('UniBot', unibot.realPass, 'localhost:3000', function (client) {
client.getRoom(id, function (err, room) {
room.join();
room.watch(function (event) {
if (event.getType() === 1) {
if (event.getContent().startsWith('!!/') && event.getContent().length > 3) {
var parts = event.getContent().split(/!!\/([^ ]+) ?(.+)?/).filter(function (e) {
return !!e;
}).map(function (e) {
return e.trim();
});
var command = parts[0];
var args = parts.slice(1);
if (typeof commands[command] !== 'undefined') {
commands[command](args, room, event);
} else {
room.sendMessage('@' + event.getSender().replace(/[ \\|{}\[\];:'",<.>\/?!@#$%^&*\(\)_\-+=]/g, '') + ': Command ' + command + ' is not found.');
users.findOne({name: 'UniBot'}, function (err, unibot) {
new ChatAPI('UniBot', unibot.realPass, 'localhost:3000', function (client) {
client.getRoom(id, function (err, room) {
room.join();
room.watch(function (event) {
if (event.getType() === 1) {
if (event.getContent().startsWith('!!/') && event.getContent().length > 3) {
var parts = event.getContent().split(/!!\/([^ ]+) ?(.+)?/).filter(function (e) {
return !!e;
}).map(function (e) {
return e.trim();
});
var command = parts[0];
var args = parts.slice(1);
if (typeof commands[command] !== 'undefined') {
commands[command](args, room, event);
} else {
room.sendMessage('@' + event.getSender().replace(/[ \\|{}\[\];:'",<.>\/?!@#$%^&*\(\)_\-+=]/g, '') + ': Command ' + command + ' is not found.');
}
}
}
}
});
});
});
});
Expand Down
5 changes: 5 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ mongo.connect('mongodb://localhost:27017/TFHWebSite', {}, function (err, db) {
if (err) throw err;
dbcs.users = collection;
collection.findOne({name: 'UniBot'}, function (err, unibot) {
if (!!unibot) {
if (!unibot.realPass)
collection.findOneAndDelete({name: 'UniBot'});
unibot = null;
}
if (!unibot) {
var keys = '0123456789abcdefghijklmnopqurstuvwxyzABCDEFGHIJKLMNOPQURSTUVWXYZ!@#$%^&8()[]{}\\|;:\'",./<>?-_=+';
var salt = '';
Expand Down

0 comments on commit e512c8a

Please sign in to comment.