mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Most arrays are now using lists.
This commit is contained in:
42
index.js
42
index.js
@@ -127,7 +127,8 @@ exports.Client.prototype.connectWebsocket = function(cb) {
|
|||||||
var _servers = data.guilds,
|
var _servers = data.guilds,
|
||||||
servers = [];
|
servers = [];
|
||||||
|
|
||||||
var cached = 0, toCache = _servers.length;
|
var cached = 0,
|
||||||
|
toCache = _servers.length;
|
||||||
|
|
||||||
for ( x in _servers ) {
|
for ( x in _servers ) {
|
||||||
_server = _servers[ x ];
|
_server = _servers[ x ];
|
||||||
@@ -186,8 +187,8 @@ exports.Client.prototype.connectWebsocket = function(cb) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
connDat.d.properties = {
|
connDat.d.properties = {
|
||||||
"$os": "DiscordJS",
|
"$os": "discord.js",
|
||||||
"$browser": "Dischromecord", // ;)
|
"$browser": "discord.js",
|
||||||
"$device": "discord.js",
|
"$device": "discord.js",
|
||||||
"$referrer": "",
|
"$referrer": "",
|
||||||
"$referring_domain": ""
|
"$referring_domain": ""
|
||||||
@@ -227,13 +228,31 @@ exports.Client.prototype.createServer = function(details, cb) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.Client.prototype.sendMessage = function(channel, message, cb, _mentions) {
|
exports.Client.prototype.sendMessage = function( channel, message, cb, _mentions, options ) {
|
||||||
|
|
||||||
|
options = options || {};
|
||||||
|
|
||||||
var cb = cb || function() {};
|
var cb = cb || function() {};
|
||||||
|
|
||||||
|
if ( _mentions === false ) {
|
||||||
|
//mentions is false, explicitly don't want to mention someone
|
||||||
|
_mentions = [];
|
||||||
|
} else if ( _mentions === true || _mentions === "auto" || _mentions == null || _mentions == undefined ) {
|
||||||
|
//want to auto sort mentions
|
||||||
|
_mentions = [];
|
||||||
|
var mentionsArray = message.match( /<[^>]*>/g ) || [];
|
||||||
|
for ( mention of mentionsArray ) {
|
||||||
|
_mentions.push( mention.substring( 2, mention.length - 1 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if ( _mentions instanceof Array ) {
|
||||||
|
//specific mentions
|
||||||
for ( mention in _mentions ) {
|
for ( mention in _mentions ) {
|
||||||
_mentions[ mention ] = _mentions[ mention ].id;
|
_mentions[ mention ] = _mentions[ mention ].id;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
var client = this;
|
var client = this;
|
||||||
var details = {
|
var details = {
|
||||||
@@ -246,7 +265,13 @@ exports.Client.prototype.sendMessage = function(channel, message, cb, _mentions)
|
|||||||
.set( "authorization", client.token )
|
.set( "authorization", client.token )
|
||||||
.send( details )
|
.send( details )
|
||||||
.end( function( err, res ) {
|
.end( function( err, res ) {
|
||||||
cb(new Message(res.body, client.channelFromId(res.body.channel_id)));
|
var msg = new Message( res.body, client.channelFromId( res.body.channel_id ) );
|
||||||
|
if ( options.selfDestruct ) {
|
||||||
|
setTimeout( function() {
|
||||||
|
client.deleteMessage( msg );
|
||||||
|
}, options.selfDestruct );
|
||||||
|
}
|
||||||
|
cb( msg );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,9 +285,7 @@ exports.Client.prototype.deleteMessage = function(message) {
|
|||||||
request
|
request
|
||||||
.del( Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id )
|
.del( Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id )
|
||||||
.set( "authorization", client.token )
|
.set( "authorization", client.token )
|
||||||
.end(function(err, res) {
|
.end();
|
||||||
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.Client.prototype.channelFromId = function( id ) {
|
exports.Client.prototype.channelFromId = function( id ) {
|
||||||
@@ -273,7 +296,6 @@ exports.Client.prototype.channelFromId = function(id){
|
|||||||
}
|
}
|
||||||
|
|
||||||
exports.Client.prototype.getChannelLogs = function( channel, amount, cb ) {
|
exports.Client.prototype.getChannelLogs = function( channel, amount, cb ) {
|
||||||
|
|
||||||
amount = amount || 0;
|
amount = amount || 0;
|
||||||
var client = this;
|
var client = this;
|
||||||
|
|
||||||
@@ -294,7 +316,5 @@ exports.Client.prototype.getChannelLogs = function(channel, amount, cb){
|
|||||||
}
|
}
|
||||||
|
|
||||||
cb( datList );
|
cb( datList );
|
||||||
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ exports.List.prototype.removeIndex = function(index){
|
|||||||
this.contents.splice( index, 1 );
|
this.contents.splice( index, 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.List.prototype.removeChild = function(child){
|
exports.List.prototype.removeElement = function( child ) {
|
||||||
|
|
||||||
var index = this.contents.indexOf( child );
|
var index = this.contents.indexOf( child );
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
var User = require( "./user.js" ).User;
|
var User = require( "./user.js" ).User;
|
||||||
|
var List = require( "./list.js" ).List;
|
||||||
|
|
||||||
exports.Message = function(time, author, content, channel, id, mentions){
|
exports.Message = function( time, author, content, channel, id, mentions, everyoneMentioned ) {
|
||||||
|
|
||||||
if ( !content ) {
|
if ( !content ) {
|
||||||
message = time;
|
message = time;
|
||||||
@@ -10,28 +11,22 @@ exports.Message = function(time, author, content, channel, id, mentions){
|
|||||||
content = message.content;
|
content = message.content;
|
||||||
id = message.id;
|
id = message.id;
|
||||||
mentions = message.mentions;
|
mentions = message.mentions;
|
||||||
|
everyoneMentioned = message.mention_everyone;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.time = Date.parse( time );
|
this.time = Date.parse( time );
|
||||||
this.author = new User( author );
|
this.author = new User( author );
|
||||||
this.content = content.replace(/<[^>]*>/g, "").replace(/\s+/g, ' ').trim();
|
this.content = content.replace( /\s+/g, ' ' ).trim(); //content.replace(/<[^>]*>/g, "").replace(/\s+/g, ' ').trim();
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.mentions = mentions || [];
|
this.mentions = new List( "id" );
|
||||||
|
this.everyoneMentioned = everyoneMentioned;
|
||||||
for ( x in mentions ) {
|
for ( x in mentions ) {
|
||||||
var _mention = mentions[ x ];
|
var _mention = mentions[ x ];
|
||||||
this.mentions.push( new User(_mention.username, _mention.id, _mention.discriminator, _mention.avatar) );
|
this.mentions.add( new User( _mention ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.Message.prototype.isMentioned = function( user ) {
|
exports.Message.prototype.isMentioned = function( user ) {
|
||||||
|
return ( this.mentions.filter( "id", user.id ).length > 0 );
|
||||||
for(mention of this.mentions){
|
|
||||||
if(user.equals(mention)){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
var User = require( "./user.js" ).User;
|
var User = require( "./user.js" ).User;
|
||||||
var List = require( "./list.js" ).List;
|
var List = require( "./list.js" ).List;
|
||||||
|
|
||||||
exports.Server = function( region, ownerID, name, id, members ) {
|
exports.Server = function( region, ownerID, name, id, members ) {
|
||||||
|
|
||||||
this.region = region;
|
this.region = region;
|
||||||
|
|||||||
Reference in New Issue
Block a user