mirror of
https://github.com/reality/dbot.git
synced 2024-11-27 22:39:26 +01:00
databankise users listener, add getChannel to users api [#272]
This commit is contained in:
parent
d30aa145aa
commit
aa6a5fce42
@ -25,6 +25,20 @@ var api = function(dbot) {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'getChannel': function(server, channel, callback) {
|
||||||
|
var channel = false;
|
||||||
|
this.db.search('channel_users', {
|
||||||
|
'server': server,
|
||||||
|
'name': channel
|
||||||
|
}, function(result) {
|
||||||
|
channel = result;
|
||||||
|
}, function(err) {
|
||||||
|
if(!err) {
|
||||||
|
callback(channel);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
'getRandomChannelUser': function(server, channel, callback) {
|
'getRandomChannelUser': function(server, channel, callback) {
|
||||||
var channel;
|
var channel;
|
||||||
this.db.search('channel_users', {
|
this.db.search('channel_users', {
|
||||||
|
@ -6,16 +6,6 @@ var _ = require('underscore')._;
|
|||||||
|
|
||||||
var users = function(dbot) {
|
var users = function(dbot) {
|
||||||
this.knownUsers = dbot.db.knownUsers;
|
this.knownUsers = dbot.db.knownUsers;
|
||||||
this.getServerUsers = function(server) {
|
|
||||||
var knownUsers = this.knownUsers;
|
|
||||||
if(!_.has(knownUsers, server)) {
|
|
||||||
knownUsers[server] = { 'users': [], 'aliases': {}, 'channelUsers': {} };
|
|
||||||
}
|
|
||||||
if(!_.has(knownUsers[server], 'channelUsers')) {
|
|
||||||
knownUsers[server].channelUsers = {};
|
|
||||||
}
|
|
||||||
return knownUsers[server];
|
|
||||||
};
|
|
||||||
|
|
||||||
this.updateAliases = function(event, oldUser, newUser) {
|
this.updateAliases = function(event, oldUser, newUser) {
|
||||||
var knownUsers = this.getServerUsers(event.server);
|
var knownUsers = this.getServerUsers(event.server);
|
||||||
@ -35,32 +25,53 @@ var users = function(dbot) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.listener = function(event) {
|
this.listener = function(event) {
|
||||||
/*var knownUsers = this.getServerUsers(event.server);
|
|
||||||
var nick = event.user;
|
|
||||||
|
|
||||||
if(event.action == 'JOIN' && nick != dbot.config.name) {
|
if(event.action == 'JOIN' && nick != dbot.config.name) {
|
||||||
if(!_.has(knownUsers.channelUsers, event.channel.name)) {
|
this.api.resolveUser(event.server, event.user, function(user) {
|
||||||
knownUsers.channelUsers[event.channel.name] = [];
|
if(!user) { // User does not yet exist
|
||||||
}
|
var id = uuid.v4();
|
||||||
var channelUsers = knownUsers.channelUsers[event.channel.name];
|
this.db.create('users', id, {
|
||||||
|
'uuid': id,
|
||||||
|
'primaryNick': event.user,
|
||||||
|
'currentNick': event.user,
|
||||||
|
'server': event.server,
|
||||||
|
'channels': [ event.channel ],
|
||||||
|
'aliases': []
|
||||||
|
}, function(err, result) {
|
||||||
|
if(!err) {
|
||||||
|
user = result;
|
||||||
|
dbot.api.event.emit('new_user', [ user ]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if(this.api.isKnownUser(event.server, nick)) {
|
if(!_.include(user.channels, event.channel)) { // User not yet channel user
|
||||||
nick = this.api.resolveUser(event.server, nick);
|
user.channels.push(event.channel);
|
||||||
} else {
|
this.db.save('users', user.id, user, function(err) {
|
||||||
knownUsers.users.push(nick);
|
if(!err) {
|
||||||
dbot.api.event.emit('new_user', [ event.server, nick ]);
|
this.api.getChannel(event.server, event.channel, function(channel) {
|
||||||
}
|
channel.users.push(user.primaryNick);
|
||||||
|
this.db.save('channel_users', channel.id, channel, function(err)) {
|
||||||
if(!_.include(channelUsers, nick)) {
|
if(!err) {
|
||||||
channelUsers.push(nick);
|
dbot.api.event.emit('new_channel_user', [ user ]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if(event.action == 'NICK') {
|
} else if(event.action == 'NICK') {
|
||||||
var newNick = event.newNick;
|
if(!this.api.isKnownUser(event.newNick)) {
|
||||||
if(!this.api.isKnownUser(newNick)) {
|
this.api.resolveUser(event.server, event.user, function(user) {
|
||||||
knownUsers.aliases[newNick] = this.api.resolveUser(event.server, event.user);
|
user.aliases.push(event.newNick);
|
||||||
dbot.api.event.emit('nick_change', [ event.server, newNick ]);
|
this.db.save('users', user.id, function(err) {
|
||||||
|
if(!err) {
|
||||||
|
dbot.api.event.emit('new_user_alias', [ user, event.newNick ]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
this.on = ['JOIN', 'NICK'];
|
this.on = ['JOIN', 'NICK'];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user