change maps to Collections

This commit is contained in:
Amish Shah
2016-08-23 00:17:41 +01:00
parent 725e0a8cfe
commit 1deefbd8cd
9 changed files with 153 additions and 35 deletions

View File

@@ -1,6 +1,7 @@
const Channel = require('./Channel');
const TextBasedChannel = require('./interface/TextBasedChannel');
const User = require('./User');
const Collection = require('../util/Collection');
/**
* Represents a Direct Message Channel between two users.
@@ -10,7 +11,7 @@ const User = require('./User');
class DMChannel extends Channel {
constructor(client, data) {
super(client, data);
this.messages = new Map();
this.messages = new Collection();
}
setup(data) {

View File

@@ -2,6 +2,7 @@ const User = require('./User');
const GuildMember = require('./GuildMember');
const Constants = require('../util/Constants');
const Role = require('./Role');
const Collection = require('../util/Collection');
function arraysEqual(a, b) {
if (a === b) return true;
@@ -30,22 +31,22 @@ class Guild {
this.client = client;
/**
* A Map of members that are in this Guild. The key is the member's ID, the value is the member.
* @type {Map<String, GuildMember>}
* A Collection of members that are in this Guild. The key is the member's ID, the value is the member.
* @type {Collection<String, GuildMember>}
*/
this.members = new Map();
this.members = new Collection();
/**
* A Map of channels that are in this Guild. The key is the channel's ID, the value is the channel.
* @type {Map<String, GuildChannel>}
* A Collection of channels that are in this Guild. The key is the channel's ID, the value is the channel.
* @type {Collection<String, GuildChannel>}
*/
this.channels = new Map();
this.channels = new Collection();
/**
* A Map of roles that are in this Guild. The key is the role's ID, the value is the role.
* @type {Map<String, Role>}
* A Collection of roles that are in this Guild. The key is the role's ID, the value is the role.
* @type {Collection<String, Role>}
*/
this.roles = new Map();
this.roles = new Collection();
if (!data) {
return;

View File

@@ -3,6 +3,7 @@ const PermissionOverwrites = require('./PermissionOverwrites');
const Role = require('./Role');
const EvaluatedPermissions = require('./EvaluatedPermissions');
const Constants = require('../util/Constants');
const Collection = require('../util/Collection');
function arraysEqual(a, b) {
if (a === b) return true;
@@ -53,9 +54,9 @@ class GuildChannel extends Channel {
this.ow = data.permission_overwrites;
/**
* A map of permission overwrites in this channel for roles and users.
* @type {Map<String, PermissionOverwrites>}
* @type {Collection<String, PermissionOverwrites>}
*/
this.permissionOverwrites = new Map();
this.permissionOverwrites = new Collection();
if (data.permission_overwrites) {
for (const overwrite of data.permission_overwrites) {
this.permissionOverwrites.set(overwrite.id, new PermissionOverwrites(this, overwrite));

View File

@@ -1,3 +1,4 @@
const Collection = require('../util/Collection');
/**
* Represents a Message on Discord
*/
@@ -79,16 +80,16 @@ class Message {
*/
this.attachments = data.attachments;
/**
* An object containing a further users or roles map
* An object containing a further users, roles or channels collections
* @type {Object}
* @property {Map<String, User>} mentions.users Mentioned users, maps their ID to the user object.
* @property {Map<String, Role>} mentions.roles Mentioned roles, maps their ID to the role object.
* @property {Map<String, GuildChannel>} mentions.channels Mentioned channels, maps their ID to the channel object.
* @property {Collection<String, User>} mentions.users Mentioned users, maps their ID to the user object.
* @property {Collection<String, Role>} mentions.roles Mentioned roles, maps their ID to the role object.
* @property {Collection<String, GuildChannel>} mentions.channels Mentioned channels, maps their ID to the channel object.
*/
this.mentions = {
users: new Map(),
roles: new Map(),
channels: new Map(),
users: new Collection(),
roles: new Collection(),
channels: new Collection(),
};
/**
* The ID of the message (unique in the channel it was sent)
@@ -174,7 +175,7 @@ class Message {
if (data.id) {
this.id = data.id;
}
if (this.channel.guild) {
if (this.channel.guild && data.content) {
const channMentionsRaw = data.content.match(/<#([0-9]{14,20})>/g) || [];
for (const raw of channMentionsRaw) {
const chan = this.channel.guild.channels.get(raw.match(/([0-9]{14,20})/g)[0]);

View File

@@ -1,5 +1,6 @@
const GuildChannel = require('./GuildChannel');
const TextBasedChannel = require('./interface/TextBasedChannel');
const Collection = require('../util/Collection');
/**
* Represents a Server Text Channel on Discord.
@@ -10,7 +11,7 @@ class TextChannel extends GuildChannel {
constructor(guild, data) {
super(guild, data);
this.messages = new Map();
this.messages = new Collection();
}
setup(data) {

View File

@@ -1,4 +1,5 @@
const GuildChannel = require('./GuildChannel');
const Collection = require('../util/Collection');
/**
* Represents a Server Voice Channel on Discord.
@@ -9,9 +10,9 @@ class VoiceChannel extends GuildChannel {
super(guild, data);
/**
* The members in this Voice Channel.
* @type {Map<String, GuildMember>}
* @type {Collection<String, GuildMember>}
*/
this.members = new Map();
this.members = new Collection();
}
setup(data) {

View File

@@ -1,3 +1,5 @@
const Collection = require('../../util/Collection');
/**
* Interface for classes that have text-channel-like features
* @interface
@@ -6,10 +8,10 @@ class TextBasedChannel {
constructor() {
/**
* A Map containing the messages sent to this channel.
* @type {Map<String, Message>}
* A Collection containing the messages sent to this channel.
* @type {Collection<String, Message>}
*/
this.messages = new Map();
this.messages = new Collection();
}
/**
* Send a message to this channel