mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 08:33:30 +01:00
ESLint stuff...
This commit is contained in:
@@ -1,26 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
class Channel {
|
||||
constructor(client, data, guild) {
|
||||
this.client = client;
|
||||
this.typingMap = {};
|
||||
this.typingTimeouts = [];
|
||||
if (guild) {
|
||||
this.guild = guild;
|
||||
}
|
||||
constructor(client, data, guild) {
|
||||
this.client = client;
|
||||
this.typingMap = {};
|
||||
this.typingTimeouts = [];
|
||||
if (guild) {
|
||||
this.guild = guild;
|
||||
}
|
||||
|
||||
if (data) {
|
||||
this.setup(data);
|
||||
}
|
||||
}
|
||||
if (data) {
|
||||
this.setup(data);
|
||||
}
|
||||
}
|
||||
|
||||
setup(data) {
|
||||
this.id = data.id;
|
||||
}
|
||||
setup(data) {
|
||||
this.id = data.id;
|
||||
}
|
||||
|
||||
delete() {
|
||||
return this.client.rest.methods.DeleteChannel(this);
|
||||
}
|
||||
delete() {
|
||||
return this.client.rest.methods.deleteChannel(this);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Channel;
|
||||
|
||||
@@ -1,37 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
const User = require('./User');
|
||||
|
||||
class ClientUser extends User {
|
||||
constructor(client, data) {
|
||||
super(client, data);
|
||||
}
|
||||
setup(data) {
|
||||
super.setup(data);
|
||||
this.verified = data.verified;
|
||||
this.email = data.email;
|
||||
}
|
||||
|
||||
setup(data) {
|
||||
super.setup(data);
|
||||
this.verified = data.verified;
|
||||
this.email = data.email;
|
||||
}
|
||||
setUsername(username) {
|
||||
return this.client.rest.methods.updateCurrentUser({ username });
|
||||
}
|
||||
|
||||
setUsername(username) {
|
||||
return this.client.rest.methods.UpdateCurrentUser({ username, });
|
||||
}
|
||||
setEmail(email) {
|
||||
return this.client.rest.methods.updateCurrentUser({ email });
|
||||
}
|
||||
|
||||
setEmail(email) {
|
||||
return this.client.rest.methods.UpdateCurrentUser({ email, });
|
||||
}
|
||||
setPassword(password) {
|
||||
return this.client.rest.methods.updateCurrentUser({ password });
|
||||
}
|
||||
|
||||
setPassword(password) {
|
||||
return this.client.rest.methods.UpdateCurrentUser({ password, });
|
||||
}
|
||||
setAvatar(avatar) {
|
||||
return this.client.rest.methods.updateCurrentUser({ avatar });
|
||||
}
|
||||
|
||||
setAvatar(avatar) {
|
||||
return this.client.rest.methods.UpdateCurrentUser({ avatar, });
|
||||
}
|
||||
|
||||
edit(data) {
|
||||
return this.client.rest.methods.UpdateCurrentUser(data);
|
||||
}
|
||||
edit(data) {
|
||||
return this.client.rest.methods.updateCurrentUser(data);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ClientUser;
|
||||
|
||||
@@ -1,40 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
const Channel = require('./Channel');
|
||||
const TextBasedChannel = require('./interface/TextBasedChannel');
|
||||
const User = require('./User');
|
||||
const TextChannelDataStore = require('./datastore/TextChannelDataStore');
|
||||
|
||||
class DMChannel extends Channel{
|
||||
constructor(client, data) {
|
||||
super(client, data);
|
||||
this.store = new TextChannelDataStore();
|
||||
}
|
||||
class DMChannel extends Channel {
|
||||
constructor(client, data) {
|
||||
super(client, data);
|
||||
this.store = new TextChannelDataStore();
|
||||
}
|
||||
|
||||
_cacheMessage(message) {
|
||||
let maxSize = this.client.options.max_message_cache;
|
||||
if (maxSize === 0) {
|
||||
// saves on performance
|
||||
return;
|
||||
}
|
||||
_cacheMessage(message) {
|
||||
const maxSize = this.client.options.max_message_cache;
|
||||
if (maxSize === 0) {
|
||||
// saves on performance
|
||||
return;
|
||||
}
|
||||
|
||||
let storeKeys = Object.keys(this.store);
|
||||
if (storeKeys.length >= maxSize) {
|
||||
this.store.remove(storeKeys[0]);
|
||||
}
|
||||
const storeKeys = Object.keys(this.store);
|
||||
if (storeKeys.length >= maxSize) {
|
||||
this.store.remove(storeKeys[0]);
|
||||
}
|
||||
|
||||
this.store.add('messages', message);
|
||||
}
|
||||
this.store.add('messages', message);
|
||||
}
|
||||
|
||||
setup(data) {
|
||||
super.setup(data);
|
||||
this.recipient = this.client.store.add('users', new User(this.client, data.recipient));
|
||||
this.lastMessageID = data.last_message_id;
|
||||
}
|
||||
setup(data) {
|
||||
super.setup(data);
|
||||
this.recipient = this.client.store.add('users', new User(this.client, data.recipient));
|
||||
this.lastMessageID = data.last_message_id;
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.recipient.toString();
|
||||
}
|
||||
toString() {
|
||||
return this.recipient.toString();
|
||||
}
|
||||
}
|
||||
|
||||
TextBasedChannel.applyToClass(DMChannel);
|
||||
|
||||
@@ -1,39 +1,37 @@
|
||||
'use strict';
|
||||
|
||||
const Constants = require('../Util/Constants');
|
||||
const Constants = require('../util/Constants');
|
||||
|
||||
class EvaluatedPermissions {
|
||||
constructor(member, permissions) {
|
||||
this.member = member;
|
||||
this.permissions = permissions;
|
||||
}
|
||||
constructor(member, permissions) {
|
||||
this.member = member;
|
||||
this.permissions = permissions;
|
||||
}
|
||||
|
||||
serialize() {
|
||||
let serializedPermissions = {};
|
||||
for (let permissionName in Constants.PermissionFlags) {
|
||||
serializedPermissions[permissionName] = this.hasPermission(permissionName);
|
||||
}
|
||||
serialize() {
|
||||
const serializedPermissions = {};
|
||||
for (const permissionName in Constants.PermissionFlags) {
|
||||
serializedPermissions[permissionName] = this.hasPermission(permissionName);
|
||||
}
|
||||
|
||||
return serializedPermissions;
|
||||
}
|
||||
return serializedPermissions;
|
||||
}
|
||||
|
||||
hasPermission(permission, explicit) {
|
||||
if (permission instanceof String || typeof permission === 'string') {
|
||||
permission = Constants.PermissionFlags[permission];
|
||||
}
|
||||
hasPermission(permission, explicit) {
|
||||
if (permission instanceof String || typeof permission === 'string') {
|
||||
permission = Constants.PermissionFlags[permission];
|
||||
}
|
||||
|
||||
if (!permission) {
|
||||
throw Constants.Errors.NOT_A_PERMISSION;
|
||||
}
|
||||
if (!permission) {
|
||||
throw Constants.Errors.NOT_A_PERMISSION;
|
||||
}
|
||||
|
||||
if (!explicit) {
|
||||
if ((this.permissions & Constants.PermissionFlags.ADMINISTRATOR) > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (!explicit) {
|
||||
if ((this.permissions & Constants.PermissionFlags.ADMINISTRATOR) > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return ((this.permissions & permission) > 0);
|
||||
}
|
||||
return ((this.permissions & permission) > 0);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = EvaluatedPermissions;
|
||||
|
||||
@@ -1,244 +1,240 @@
|
||||
'use strict';
|
||||
|
||||
const User = require('./User');
|
||||
const GuildMember = require('./GuildMember');
|
||||
const GuildDataStore = require('./datastore/GuildDataStore');
|
||||
const TextChannel = require('./TextChannel');
|
||||
const VoiceChannel = require('./VoiceChannel');
|
||||
const Constants = require('../Util/Constants');
|
||||
const Constants = require('../util/Constants');
|
||||
const Role = require('./Role');
|
||||
|
||||
function arraysEqual(a, b) {
|
||||
if (a === b) return true;
|
||||
if (a.length !== b.length) return false;
|
||||
if (a === b) return true;
|
||||
if (a.length !== b.length) return false;
|
||||
|
||||
for (let itemInd in a) {
|
||||
let item = a[itemInd];
|
||||
let ind = b.indexOf(item);
|
||||
if (ind) {
|
||||
b.splice(ind, 1);
|
||||
}
|
||||
}
|
||||
for (const itemInd in a) {
|
||||
const item = a[itemInd];
|
||||
const ind = b.indexOf(item);
|
||||
if (ind) {
|
||||
b.splice(ind, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return b.length === 0;
|
||||
return b.length === 0;
|
||||
}
|
||||
|
||||
class Guild {
|
||||
constructor(client, data) {
|
||||
this.client = client;
|
||||
this.store = new GuildDataStore();
|
||||
constructor(client, data) {
|
||||
this.client = client;
|
||||
this.store = new GuildDataStore();
|
||||
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.unavailable) {
|
||||
this.available = false;
|
||||
this.id = data.id;
|
||||
} else {
|
||||
this.available = true;
|
||||
this.setup(data);
|
||||
}
|
||||
}
|
||||
if (data.unavailable) {
|
||||
this.available = false;
|
||||
this.id = data.id;
|
||||
} else {
|
||||
this.available = true;
|
||||
this.setup(data);
|
||||
}
|
||||
}
|
||||
|
||||
_addMember(guildUser, noEvent) {
|
||||
if (!(guildUser.user instanceof User)) {
|
||||
guildUser.user = this.client.store.NewUser(guildUser.user);
|
||||
}
|
||||
_addMember(guildUser, noEvent) {
|
||||
if (!(guildUser.user instanceof User)) {
|
||||
guildUser.user = this.client.store.newUser(guildUser.user);
|
||||
}
|
||||
|
||||
guildUser.joined_at = guildUser.joined_at || 0;
|
||||
let member = this.store.add('members', new GuildMember(this, guildUser));
|
||||
if (this.client.ws.status === Constants.Status.READY && !noEvent) {
|
||||
this.client.emit(Constants.Events.GUILD_MEMBER_ADD, this, member);
|
||||
}
|
||||
guildUser.joined_at = guildUser.joined_at || 0;
|
||||
const member = this.store.add('members', new GuildMember(this, guildUser));
|
||||
if (this.client.ws.status === Constants.Status.READY && !noEvent) {
|
||||
this.client.emit(Constants.Events.GUILD_MEMBER_ADD, this, member);
|
||||
}
|
||||
|
||||
return member;
|
||||
}
|
||||
return member;
|
||||
}
|
||||
|
||||
_updateMember(member, data) {
|
||||
let oldRoles = member.roles;
|
||||
_updateMember(member, data) {
|
||||
const oldRoles = member.roles;
|
||||
|
||||
member._roles = data.roles;
|
||||
if (this.client.ws.status === Constants.Status.READY) {
|
||||
this.client.emit(Constants.Events.GUILD_MEMBER_ROLES_UPDATE, this, oldRoles, member.roles);
|
||||
}
|
||||
}
|
||||
member._roles = data.roles;
|
||||
if (this.client.ws.status === Constants.Status.READY) {
|
||||
this.client.emit(Constants.Events.GUILD_MEMBER_ROLES_UPDATE, this, oldRoles, member.roles);
|
||||
}
|
||||
}
|
||||
|
||||
_removeMember(guildMember) {
|
||||
this.store.remove('members', guildMember);
|
||||
}
|
||||
_removeMember(guildMember) {
|
||||
this.store.remove('members', guildMember);
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.name;
|
||||
}
|
||||
toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
kick(member) {
|
||||
return this.member(member).kick();
|
||||
}
|
||||
kick(member) {
|
||||
return this.member(member).kick();
|
||||
}
|
||||
|
||||
member(user) {
|
||||
return this.client.resolver.ResolveGuildMember(this, user);
|
||||
}
|
||||
member(user) {
|
||||
return this.client.resolver.resolveGuildMember(this, user);
|
||||
}
|
||||
|
||||
equals(data) {
|
||||
let base =
|
||||
this.id === data.id &&
|
||||
this.available === !data.unavailable &&
|
||||
this.splash === data.splash &&
|
||||
this.region === data.region &&
|
||||
this.name === data.name &&
|
||||
this.memberCount === data.member_count &&
|
||||
this.large === data.large &&
|
||||
this.icon === data.icon &&
|
||||
arraysEqual(this.features, data.features) &&
|
||||
this.owner.id === data.owner_id &&
|
||||
this.verificationLevel === data.verification_level &&
|
||||
this.embedEnabled === data.embed_enabled;
|
||||
equals(data) {
|
||||
let base =
|
||||
this.id === data.id &&
|
||||
this.available === !data.unavailable &&
|
||||
this.splash === data.splash &&
|
||||
this.region === data.region &&
|
||||
this.name === data.name &&
|
||||
this.memberCount === data.member_count &&
|
||||
this.large === data.large &&
|
||||
this.icon === data.icon &&
|
||||
arraysEqual(this.features, data.features) &&
|
||||
this.owner.id === data.owner_id &&
|
||||
this.verificationLevel === data.verification_level &&
|
||||
this.embedEnabled === data.embed_enabled;
|
||||
|
||||
if (base) {
|
||||
if (this.embedChannel) {
|
||||
if (this.embedChannel.id !== data.embed_channel_id) {
|
||||
base = false;
|
||||
}
|
||||
} else if (data.embed_channel_id) {
|
||||
base = false;
|
||||
}
|
||||
}
|
||||
if (base) {
|
||||
if (this.embedChannel) {
|
||||
if (this.embedChannel.id !== data.embed_channel_id) {
|
||||
base = false;
|
||||
}
|
||||
} else if (data.embed_channel_id) {
|
||||
base = false;
|
||||
}
|
||||
}
|
||||
|
||||
return base;
|
||||
}
|
||||
return base;
|
||||
}
|
||||
|
||||
setup(data) {
|
||||
this.id = data.id;
|
||||
this.available = !data.unavailable;
|
||||
this.splash = data.splash;
|
||||
this.region = data.region;
|
||||
this.name = data.name;
|
||||
this.memberCount = data.member_count;
|
||||
this.large = data.large;
|
||||
this.joinDate = new Date(data.joined_at);
|
||||
this.icon = data.icon;
|
||||
this.features = data.features;
|
||||
this.emojis = data.emojis;
|
||||
this.afkTimeout = data.afk_timeout;
|
||||
this.afkChannelID = data.afk_channel_id;
|
||||
this.embedEnabled = data.embed_enabled;
|
||||
this.verificationLevel = data.verification_level;
|
||||
this.features = data.features || [];
|
||||
setup(data) {
|
||||
this.id = data.id;
|
||||
this.available = !data.unavailable;
|
||||
this.splash = data.splash;
|
||||
this.region = data.region;
|
||||
this.name = data.name;
|
||||
this.memberCount = data.member_count;
|
||||
this.large = data.large;
|
||||
this.joinDate = new Date(data.joined_at);
|
||||
this.icon = data.icon;
|
||||
this.features = data.features;
|
||||
this.emojis = data.emojis;
|
||||
this.afkTimeout = data.afk_timeout;
|
||||
this.afkChannelID = data.afk_channel_id;
|
||||
this.embedEnabled = data.embed_enabled;
|
||||
this.verificationLevel = data.verification_level;
|
||||
this.features = data.features || [];
|
||||
|
||||
if (data.members) {
|
||||
this.store.clear('members');
|
||||
for (let guildUser of data.members) {
|
||||
this._addMember(guildUser);
|
||||
}
|
||||
}
|
||||
if (data.members) {
|
||||
this.store.clear('members');
|
||||
for (const guildUser of data.members) {
|
||||
this._addMember(guildUser);
|
||||
}
|
||||
}
|
||||
|
||||
this.owner = this.store.get('members', data.owner_id);
|
||||
this.owner = this.store.get('members', data.owner_id);
|
||||
|
||||
if (data.channels) {
|
||||
this.store.clear('channels');
|
||||
for (let channel of data.channels) {
|
||||
this.client.store.NewChannel(channel, this);
|
||||
}
|
||||
}
|
||||
if (data.channels) {
|
||||
this.store.clear('channels');
|
||||
for (const channel of data.channels) {
|
||||
this.client.store.newChannel(channel, this);
|
||||
}
|
||||
}
|
||||
|
||||
this.embedChannel = this.store.get('channels', data.embed_channel_id);
|
||||
this.embedChannel = this.store.get('channels', data.embed_channel_id);
|
||||
|
||||
if (data.roles) {
|
||||
this.store.clear('roles');
|
||||
for (let role of data.roles) {
|
||||
this.store.add('roles', new Role(this, role));
|
||||
}
|
||||
}
|
||||
if (data.roles) {
|
||||
this.store.clear('roles');
|
||||
for (const role of data.roles) {
|
||||
this.store.add('roles', new Role(this, role));
|
||||
}
|
||||
}
|
||||
|
||||
if (data.presences) {
|
||||
for (let presence of data.presences) {
|
||||
let user = this.client.store.get('users', presence.user.id);
|
||||
if (user) {
|
||||
user.status = presence.status;
|
||||
user.game = presence.game;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (data.presences) {
|
||||
for (const presence of data.presences) {
|
||||
const user = this.client.store.get('users', presence.user.id);
|
||||
if (user) {
|
||||
user.status = presence.status;
|
||||
user.game = presence.game;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (data.voice_states) {
|
||||
for (let voiceState of data.voice_states) {
|
||||
let member = this.store.get('members', voiceState.user_id);
|
||||
if (member) {
|
||||
member.serverMute = voiceState.mute;
|
||||
member.serverDeaf = voiceState.deaf;
|
||||
member.selfMute = voiceState.self_mute;
|
||||
member.selfDeaf = voiceState.self_deaf;
|
||||
member.voiceSessionID = voiceState.session_id;
|
||||
member.voiceChannelID = voiceState.channel_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (data.voice_states) {
|
||||
for (const voiceState of data.voice_states) {
|
||||
const member = this.store.get('members', voiceState.user_id);
|
||||
if (member) {
|
||||
member.serverMute = voiceState.mute;
|
||||
member.serverDeaf = voiceState.deaf;
|
||||
member.selfMute = voiceState.self_mute;
|
||||
member.selfDeaf = voiceState.self_deaf;
|
||||
member.voiceSessionID = voiceState.session_id;
|
||||
member.voiceChannelID = voiceState.channel_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
createChannel(name, type) {
|
||||
return this.client.rest.methods.CreateChannel(this, name, type);
|
||||
}
|
||||
createChannel(name, type) {
|
||||
return this.client.rest.methods.createChannel(this, name, type);
|
||||
}
|
||||
|
||||
createRole() {
|
||||
return this.client.rest.methods.CreateGuildRole(this);
|
||||
}
|
||||
createRole() {
|
||||
return this.client.rest.methods.createGuildRole(this);
|
||||
}
|
||||
|
||||
leave() {
|
||||
return this.client.rest.methods.LeaveGuild(this);
|
||||
}
|
||||
leave() {
|
||||
return this.client.rest.methods.leaveGuild(this);
|
||||
}
|
||||
|
||||
delete() {
|
||||
return this.client.rest.methods.DeleteGuild(this);
|
||||
}
|
||||
delete() {
|
||||
return this.client.rest.methods.deleteGuild(this);
|
||||
}
|
||||
|
||||
edit(data) {
|
||||
return this.client.rest.methods.UpdateGuild(this, data);
|
||||
}
|
||||
edit(data) {
|
||||
return this.client.rest.methods.updateGuild(this, data);
|
||||
}
|
||||
|
||||
setName(name) {
|
||||
return this.edit({ name, });
|
||||
}
|
||||
setName(name) {
|
||||
return this.edit({ name });
|
||||
}
|
||||
|
||||
setRegion(region) {
|
||||
return this.edit({ region, });
|
||||
}
|
||||
setRegion(region) {
|
||||
return this.edit({ region });
|
||||
}
|
||||
|
||||
setVerificationLevel(verificationLevel) {
|
||||
return this.edit({ verificationLevel, });
|
||||
}
|
||||
setVerificationLevel(verificationLevel) {
|
||||
return this.edit({ verificationLevel });
|
||||
}
|
||||
|
||||
setAFKChannel(afkchannel) {
|
||||
return this.edit({ afkChannel, });
|
||||
}
|
||||
setAFKChannel(afkChannel) {
|
||||
return this.edit({ afkChannel });
|
||||
}
|
||||
|
||||
setAFKTimeout(afkTimeout) {
|
||||
return this.edit({ afkTimeout, });
|
||||
}
|
||||
setAFKTimeout(afkTimeout) {
|
||||
return this.edit({ afkTimeout });
|
||||
}
|
||||
|
||||
setIcon(icon) {
|
||||
return this.edit({ icon, });
|
||||
}
|
||||
setIcon(icon) {
|
||||
return this.edit({ icon });
|
||||
}
|
||||
|
||||
setOwner(owner) {
|
||||
return this.edit({ owner, });
|
||||
}
|
||||
setOwner(owner) {
|
||||
return this.edit({ owner });
|
||||
}
|
||||
|
||||
setSplash(splash) {
|
||||
return this.edit({ splash, });
|
||||
}
|
||||
setSplash(splash) {
|
||||
return this.edit({ splash });
|
||||
}
|
||||
|
||||
get channels() { return this.store.getAsArray('channels'); }
|
||||
get channels() { return this.store.getAsArray('channels'); }
|
||||
|
||||
get $channels() { return this.store.data.channels; }
|
||||
get $channels() { return this.store.data.channels; }
|
||||
|
||||
get roles() { return this.store.getAsArray('roles'); }
|
||||
get roles() { return this.store.getAsArray('roles'); }
|
||||
|
||||
get $roles() { return this.store.data.roles; }
|
||||
get $roles() { return this.store.data.roles; }
|
||||
|
||||
get members() { return this.store.getAsArray('members'); }
|
||||
get members() { return this.store.getAsArray('members'); }
|
||||
|
||||
get $members() { return this.store.data.members; }
|
||||
get $members() { return this.store.data.members; }
|
||||
}
|
||||
|
||||
module.exports = Guild;
|
||||
|
||||
@@ -1,71 +1,69 @@
|
||||
'use strict';
|
||||
|
||||
const TextBasedChannel = require('./interface/TextBasedChannel');
|
||||
|
||||
class GuildMember {
|
||||
constructor(guild, data) {
|
||||
this.client = guild.client;
|
||||
this.guild = guild;
|
||||
this.user = {};
|
||||
this._roles = [];
|
||||
if (data) {
|
||||
this.setup(data);
|
||||
}
|
||||
}
|
||||
constructor(guild, data) {
|
||||
this.client = guild.client;
|
||||
this.guild = guild;
|
||||
this.user = {};
|
||||
this._roles = [];
|
||||
if (data) {
|
||||
this.setup(data);
|
||||
}
|
||||
}
|
||||
|
||||
setup(data) {
|
||||
this.user = data.user;
|
||||
this.serverDeaf = data.deaf;
|
||||
this.serverMute = data.mute;
|
||||
this.selfMute = data.self_mute;
|
||||
this.selfDeaf = data.self_deaf;
|
||||
this.voiceSessionID = data.session_id;
|
||||
this.voiceChannelID = data.channel_id;
|
||||
this.joinDate = new Date(data.joined_at);
|
||||
this._roles = data.roles;
|
||||
}
|
||||
setup(data) {
|
||||
this.user = data.user;
|
||||
this.serverDeaf = data.deaf;
|
||||
this.serverMute = data.mute;
|
||||
this.selfMute = data.self_mute;
|
||||
this.selfDeaf = data.self_deaf;
|
||||
this.voiceSessionID = data.session_id;
|
||||
this.voiceChannelID = data.channel_id;
|
||||
this.joinDate = new Date(data.joined_at);
|
||||
this._roles = data.roles;
|
||||
}
|
||||
|
||||
get roles() {
|
||||
let list = [];
|
||||
let everyoneRole = this.guild.store.get('roles', this.guild.id);
|
||||
get roles() {
|
||||
const list = [];
|
||||
const everyoneRole = this.guild.store.get('roles', this.guild.id);
|
||||
|
||||
if (everyoneRole) {
|
||||
list.push(everyoneRole);
|
||||
}
|
||||
if (everyoneRole) {
|
||||
list.push(everyoneRole);
|
||||
}
|
||||
|
||||
for (let roleID of this._roles) {
|
||||
let role = this.guild.store.get('roles', roleID);
|
||||
if (role) {
|
||||
list.push(role);
|
||||
}
|
||||
}
|
||||
for (const roleID of this._roles) {
|
||||
const role = this.guild.store.get('roles', roleID);
|
||||
if (role) {
|
||||
list.push(role);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
get mute() {
|
||||
return this.selfMute || this.serverMute;
|
||||
}
|
||||
get mute() {
|
||||
return this.selfMute || this.serverMute;
|
||||
}
|
||||
|
||||
get deaf() {
|
||||
return this.selfDeaf || this.serverDeaf;
|
||||
}
|
||||
get deaf() {
|
||||
return this.selfDeaf || this.serverDeaf;
|
||||
}
|
||||
|
||||
get voiceChannel() {
|
||||
return this.guild.store.get('channels', this.voiceChannelID);
|
||||
}
|
||||
get voiceChannel() {
|
||||
return this.guild.store.get('channels', this.voiceChannelID);
|
||||
}
|
||||
|
||||
get id() {
|
||||
return this.user.id;
|
||||
}
|
||||
get id() {
|
||||
return this.user.id;
|
||||
}
|
||||
|
||||
deleteDM() {
|
||||
return this.client.rest.methods.DeleteChannel(this);
|
||||
}
|
||||
deleteDM() {
|
||||
return this.client.rest.methods.deleteChannel(this);
|
||||
}
|
||||
|
||||
kick() {
|
||||
return this.client.rest.methods.KickGuildMember(this.guild, this);
|
||||
}
|
||||
kick() {
|
||||
return this.client.rest.methods.kickGuildMember(this.guild, this);
|
||||
}
|
||||
}
|
||||
|
||||
TextBasedChannel.applyToClass(GuildMember);
|
||||
|
||||
@@ -1,111 +1,117 @@
|
||||
'use strict';
|
||||
|
||||
class Message {
|
||||
constructor(channel, data, client) {
|
||||
this.channel = channel;
|
||||
constructor(channel, data, client) {
|
||||
this.channel = channel;
|
||||
|
||||
if (channel.guild) {
|
||||
this.guild = channel.guild;
|
||||
}
|
||||
if (channel.guild) {
|
||||
this.guild = channel.guild;
|
||||
}
|
||||
|
||||
this.client = client;
|
||||
if (data) {
|
||||
this.setup(data);
|
||||
}
|
||||
}
|
||||
this.client = client;
|
||||
if (data) {
|
||||
this.setup(data);
|
||||
}
|
||||
}
|
||||
|
||||
setup(data) {
|
||||
this.author = this.client.store.NewUser(data.author);
|
||||
this.content = data.content;
|
||||
this.timestamp = new Date(data.timestamp);
|
||||
this.editedTimestamp = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
||||
this.tts = data.tts;
|
||||
this.mentionEveryone = data.mention_everyone;
|
||||
this.nonce = data.nonce;
|
||||
this.embeds = data.embeds;
|
||||
this.attachments = data.attachments;
|
||||
this.mentions = [];
|
||||
this.id = data.id;
|
||||
for (let mention of data.mentions) {
|
||||
let user = this.client.store.get('users', mention.id);
|
||||
if (user) {
|
||||
this.mentions.push(user);
|
||||
} else {
|
||||
user = this.client.store.NewUser(mention);
|
||||
this.mentions.push(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
setup(data) {
|
||||
this.author = this.client.store.newUser(data.author);
|
||||
this.content = data.content;
|
||||
this.timestamp = new Date(data.timestamp);
|
||||
this.editedTimestamp = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
||||
this.tts = data.tts;
|
||||
this.mentionEveryone = data.mention_everyone;
|
||||
this.nonce = data.nonce;
|
||||
this.embeds = data.embeds;
|
||||
this.attachments = data.attachments;
|
||||
this.mentions = [];
|
||||
this.id = data.id;
|
||||
for (const mention of data.mentions) {
|
||||
let user = this.client.store.get('users', mention.id);
|
||||
if (user) {
|
||||
this.mentions.push(user);
|
||||
} else {
|
||||
user = this.client.store.newUser(mention);
|
||||
this.mentions.push(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
patch(data) {
|
||||
if (data.author)
|
||||
this.author = this.client.store.get('users', data.author.id);
|
||||
if (data.content)
|
||||
this.content = data.content;
|
||||
if (data.timestamp)
|
||||
this.timestamp = new Date(data.timestamp);
|
||||
if (data.edited_timestamp)
|
||||
this.editedTimestamp = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
||||
if (data.tts)
|
||||
this.tts = data.tts;
|
||||
if (data.mention_everyone)
|
||||
this.mentionEveryone = data.mention_everyone;
|
||||
if (data.nonce)
|
||||
this.nonce = data.nonce;
|
||||
if (data.embeds)
|
||||
this.embeds = data.embeds;
|
||||
if (data.attachments)
|
||||
this.attachments = data.attachments;
|
||||
if (data.mentions) {
|
||||
for (let mention of data.mentions) {
|
||||
let user = this.client.store.get('users', mention.id);
|
||||
if (user) {
|
||||
this.mentions.push(user);
|
||||
} else {
|
||||
user = this.client.store.NewUser(mention);
|
||||
this.mentions.push(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
patch(data) {
|
||||
if (data.author) {
|
||||
this.author = this.client.store.get('users', data.author.id);
|
||||
}
|
||||
if (data.content) {
|
||||
this.content = data.content;
|
||||
}
|
||||
if (data.timestamp) {
|
||||
this.timestamp = new Date(data.timestamp);
|
||||
}
|
||||
if (data.edited_timestamp) {
|
||||
this.editedTimestamp = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
||||
}
|
||||
if (data.tts) {
|
||||
this.tts = data.tts;
|
||||
}
|
||||
if (data.mention_everyone) {
|
||||
this.mentionEveryone = data.mention_everyone;
|
||||
}
|
||||
if (data.nonce) {
|
||||
this.nonce = data.nonce;
|
||||
}
|
||||
if (data.embeds) {
|
||||
this.embeds = data.embeds;
|
||||
}
|
||||
if (data.attachments) {
|
||||
this.attachments = data.attachments;
|
||||
}
|
||||
if (data.mentions) {
|
||||
for (const mention of data.mentions) {
|
||||
let user = this.client.store.get('users', mention.id);
|
||||
if (user) {
|
||||
this.mentions.push(user);
|
||||
} else {
|
||||
user = this.client.store.newUser(mention);
|
||||
this.mentions.push(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (data.id)
|
||||
this.id = data.id;
|
||||
}
|
||||
if (data.id) {
|
||||
this.id = data.id;
|
||||
}
|
||||
}
|
||||
|
||||
equals(message, rawData) {
|
||||
equals(message, rawData) {
|
||||
const embedUpdate = !message.author && !message.attachments;
|
||||
|
||||
let embedUpdate = !message.author && !message.attachments;
|
||||
if (embedUpdate) {
|
||||
const base = this.id === message.id &&
|
||||
this.embeds.length === message.embeds.length;
|
||||
return base;
|
||||
}
|
||||
let base = this.id === message.id &&
|
||||
this.author.id === message.author.id &&
|
||||
this.content === message.content &&
|
||||
this.tts === message.tts &&
|
||||
this.nonce === message.nonce &&
|
||||
this.embeds.length === message.embeds.length &&
|
||||
this.attachments.length === message.attachments.length;
|
||||
|
||||
if (embedUpdate) {
|
||||
let base = this.id === message.id &&
|
||||
this.embeds.length === message.embeds.length;
|
||||
return base;
|
||||
} else {
|
||||
let base = this.id === message.id &&
|
||||
this.author.id === message.author.id &&
|
||||
this.content === message.content &&
|
||||
this.tts === message.tts &&
|
||||
this.nonce === message.nonce &&
|
||||
this.embeds.length === message.embeds.length &&
|
||||
this.attachments.length === message.attachments.length;
|
||||
if (base && rawData) {
|
||||
base = this.mentionEveryone === message.mentionEveryone &&
|
||||
this.timestamp.getTime() === new Date(rawData.timestamp).getTime() &&
|
||||
this.editedTimestamp === new Date(rawData.edited_timestamp).getTime();
|
||||
}
|
||||
|
||||
if (base && rawData) {
|
||||
base = this.mentionEveryone === message.mentionEveryone &&
|
||||
this.timestamp.getTime() === new Date(data.timestamp).getTime() &&
|
||||
this.editedTimestamp === new Date(data.edited_timestamp).getTime();
|
||||
}
|
||||
return base;
|
||||
}
|
||||
|
||||
return base;
|
||||
}
|
||||
}
|
||||
delete() {
|
||||
return this.client.rest.methods.deleteMessage(this);
|
||||
}
|
||||
|
||||
delete() {
|
||||
return this.client.rest.methods.DeleteMessage(this);
|
||||
}
|
||||
|
||||
edit(content) {
|
||||
return this.client.rest.methods.UpdateMessage(this, content);
|
||||
}
|
||||
edit(content) {
|
||||
return this.client.rest.methods.updateMessage(this, content);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Message;
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
class PermissionOverwrites {
|
||||
constructor(serverChannel, data) {
|
||||
this.channel = serverChannel;
|
||||
if (data) {
|
||||
this.setup(data);
|
||||
}
|
||||
}
|
||||
constructor(serverChannel, data) {
|
||||
this.channel = serverChannel;
|
||||
if (data) {
|
||||
this.setup(data);
|
||||
}
|
||||
}
|
||||
|
||||
setup(data) {
|
||||
this.type = data.type;
|
||||
this.id = data.id;
|
||||
this.denyData = data.deny;
|
||||
this.allowData = data.allow;
|
||||
}
|
||||
setup(data) {
|
||||
this.type = data.type;
|
||||
this.id = data.id;
|
||||
this.denyData = data.deny;
|
||||
this.allowData = data.allow;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PermissionOverwrites;
|
||||
|
||||
@@ -1,92 +1,90 @@
|
||||
'use strict';
|
||||
|
||||
const Constants = require('../Util/Constants');
|
||||
const Constants = require('../util/Constants');
|
||||
|
||||
class Role {
|
||||
constructor(guild, data) {
|
||||
this.guild = guild;
|
||||
this.client = guild.client;
|
||||
if (data) {
|
||||
this.setup(data);
|
||||
}
|
||||
}
|
||||
constructor(guild, data) {
|
||||
this.guild = guild;
|
||||
this.client = guild.client;
|
||||
if (data) {
|
||||
this.setup(data);
|
||||
}
|
||||
}
|
||||
|
||||
equals(role) {
|
||||
return (
|
||||
this.id === role.id &&
|
||||
this.name === role.name &&
|
||||
this.color === role.color &&
|
||||
this.hoist === role.hoist &&
|
||||
this.position === role.position &&
|
||||
this.permissions === role.permissions &&
|
||||
this.managed === role.managed
|
||||
);
|
||||
}
|
||||
equals(role) {
|
||||
return (
|
||||
this.id === role.id &&
|
||||
this.name === role.name &&
|
||||
this.color === role.color &&
|
||||
this.hoist === role.hoist &&
|
||||
this.position === role.position &&
|
||||
this.permissions === role.permissions &&
|
||||
this.managed === role.managed
|
||||
);
|
||||
}
|
||||
|
||||
setup(data) {
|
||||
this.id = data.id;
|
||||
this.name = data.name;
|
||||
this.color = data.color;
|
||||
this.hoist = data.hoist;
|
||||
this.position = data.position;
|
||||
this.permissions = data.permissions;
|
||||
this.managed = data.managed;
|
||||
}
|
||||
setup(data) {
|
||||
this.id = data.id;
|
||||
this.name = data.name;
|
||||
this.color = data.color;
|
||||
this.hoist = data.hoist;
|
||||
this.position = data.position;
|
||||
this.permissions = data.permissions;
|
||||
this.managed = data.managed;
|
||||
}
|
||||
|
||||
delete() {
|
||||
return this.client.rest.methods.DeleteGuildRole(this);
|
||||
}
|
||||
delete() {
|
||||
return this.client.rest.methods.deleteGuildRole(this);
|
||||
}
|
||||
|
||||
edit(data) {
|
||||
return this.client.rest.methods.UpdateGuildRole(this, data);
|
||||
}
|
||||
edit(data) {
|
||||
return this.client.rest.methods.updateGuildRole(this, data);
|
||||
}
|
||||
|
||||
setName(name) {
|
||||
return this.client.rest.methods.UpdateGuildRole(this, {name,});
|
||||
}
|
||||
setName(name) {
|
||||
return this.client.rest.methods.updateGuildRole(this, { name });
|
||||
}
|
||||
|
||||
setColor(color) {
|
||||
return this.client.rest.methods.UpdateGuildRole(this, {color,});
|
||||
}
|
||||
setColor(color) {
|
||||
return this.client.rest.methods.updateGuildRole(this, { color });
|
||||
}
|
||||
|
||||
setHoist(hoist) {
|
||||
return this.client.rest.methods.UpdateGuildRole(this, {hoist,});
|
||||
}
|
||||
setHoist(hoist) {
|
||||
return this.client.rest.methods.updateGuildRole(this, { hoist });
|
||||
}
|
||||
|
||||
setPosition(position) {
|
||||
return this.client.rest.methods.UpdateGuildRole(this, {position,});
|
||||
}
|
||||
setPosition(position) {
|
||||
return this.client.rest.methods.updateGuildRole(this, { position });
|
||||
}
|
||||
|
||||
setPermissions(permissions) {
|
||||
return this.client.rest.methods.UpdateGuildRole(this, {permissions,});
|
||||
}
|
||||
setPermissions(permissions) {
|
||||
return this.client.rest.methods.updateGuildRole(this, { permissions });
|
||||
}
|
||||
|
||||
serialize() {
|
||||
let serializedPermissions = {};
|
||||
for (let permissionName in Constants.PermissionFlags) {
|
||||
serializedPermissions[permissionName] = this.hasPermission(permissionName);
|
||||
}
|
||||
serialize() {
|
||||
const serializedPermissions = {};
|
||||
for (const permissionName in Constants.PermissionFlags) {
|
||||
serializedPermissions[permissionName] = this.hasPermission(permissionName);
|
||||
}
|
||||
|
||||
return serializedPermissions;
|
||||
}
|
||||
return serializedPermissions;
|
||||
}
|
||||
|
||||
hasPermission(permission, explicit) {
|
||||
if (permission instanceof String || typeof permission === 'string') {
|
||||
permission = Constants.PermissionFlags[permission];
|
||||
}
|
||||
hasPermission(permission, explicit) {
|
||||
if (permission instanceof String || typeof permission === 'string') {
|
||||
permission = Constants.PermissionFlags[permission];
|
||||
}
|
||||
|
||||
if (!permission) {
|
||||
throw Constants.Errors.NOT_A_PERMISSION;
|
||||
}
|
||||
if (!permission) {
|
||||
throw Constants.Errors.NOT_A_PERMISSION;
|
||||
}
|
||||
|
||||
if (!explicit) {
|
||||
if ((this.permissions & Constants.PermissionFlags.ADMINISTRATOR) > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (!explicit) {
|
||||
if ((this.permissions & Constants.PermissionFlags.ADMINISTRATOR) > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return ((this.permissions & permission) > 0);
|
||||
}
|
||||
return ((this.permissions & permission) > 0);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Role;
|
||||
|
||||
@@ -1,151 +1,149 @@
|
||||
'use strict';
|
||||
|
||||
const Channel = require('./Channel');
|
||||
const PermissionOverwrites = require('./PermissionOverwrites');
|
||||
const EvaluatedPermissions = require('./EvaluatedPermissions');
|
||||
const Constants = require('../util/Constants');
|
||||
|
||||
function arraysEqual(a, b) {
|
||||
if (a === b) return true;
|
||||
if (a.length !== b.length) return false;
|
||||
if (a === b) return true;
|
||||
if (a.length !== b.length) return false;
|
||||
|
||||
for (let itemInd in a) {
|
||||
let item = a[itemInd];
|
||||
let ind = b.indexOf(item);
|
||||
if (ind) {
|
||||
b.splice(ind, 1);
|
||||
}
|
||||
}
|
||||
for (const itemInd in a) {
|
||||
const item = a[itemInd];
|
||||
const ind = b.indexOf(item);
|
||||
if (ind) {
|
||||
b.splice(ind, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return b.length === 0;
|
||||
return b.length === 0;
|
||||
}
|
||||
|
||||
class ServerChannel extends Channel{
|
||||
constructor(guild, data) {
|
||||
super(guild.client, data, guild);
|
||||
}
|
||||
class ServerChannel extends Channel {
|
||||
constructor(guild, data) {
|
||||
super(guild.client, data, guild);
|
||||
}
|
||||
|
||||
setup(data) {
|
||||
super.setup(data);
|
||||
this.type = data.type;
|
||||
this.topic = data.topic;
|
||||
this.position = data.position;
|
||||
this.name = data.name;
|
||||
this.lastMessageID = data.last_message_id;
|
||||
this.ow = data.permission_overwrites;
|
||||
this.permissionOverwrites = [];
|
||||
if (data.permission_overwrites) {
|
||||
for (let overwrite of data.permission_overwrites) {
|
||||
this.permissionOverwrites.push(new PermissionOverwrites(this, overwrite));
|
||||
}
|
||||
}
|
||||
}
|
||||
setup(data) {
|
||||
super.setup(data);
|
||||
this.type = data.type;
|
||||
this.topic = data.topic;
|
||||
this.position = data.position;
|
||||
this.name = data.name;
|
||||
this.lastMessageID = data.last_message_id;
|
||||
this.ow = data.permission_overwrites;
|
||||
this.permissionOverwrites = [];
|
||||
if (data.permission_overwrites) {
|
||||
for (const overwrite of data.permission_overwrites) {
|
||||
this.permissionOverwrites.push(new PermissionOverwrites(this, overwrite));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
equals(other) {
|
||||
let base = (
|
||||
this.type === other.type &&
|
||||
this.topic === other.topic &&
|
||||
this.position === other.position &&
|
||||
this.name === other.name &&
|
||||
this.id === other.id
|
||||
);
|
||||
equals(other) {
|
||||
let base = (
|
||||
this.type === other.type &&
|
||||
this.topic === other.topic &&
|
||||
this.position === other.position &&
|
||||
this.name === other.name &&
|
||||
this.id === other.id
|
||||
);
|
||||
|
||||
if (base) {
|
||||
if (other.permission_overwrites) {
|
||||
let thisIDSet = this.permissionOverwrites.map(overwrite => overwrite.id);
|
||||
let otherIDSet = other.permission_overwrites.map(overwrite => overwrite.id);
|
||||
if (arraysEqual(thisIDSet, otherIDSet)) {
|
||||
base = true;
|
||||
} else {
|
||||
base = false;
|
||||
}
|
||||
} else {
|
||||
base = false;
|
||||
}
|
||||
}
|
||||
if (base) {
|
||||
if (other.permission_overwrites) {
|
||||
const thisIDSet = this.permissionOverwrites.map(overwrite => overwrite.id);
|
||||
const otherIDSet = other.permission_overwrites.map(overwrite => overwrite.id);
|
||||
if (arraysEqual(thisIDSet, otherIDSet)) {
|
||||
base = true;
|
||||
} else {
|
||||
base = false;
|
||||
}
|
||||
} else {
|
||||
base = false;
|
||||
}
|
||||
}
|
||||
|
||||
return base;
|
||||
}
|
||||
return base;
|
||||
}
|
||||
|
||||
permissionsFor(member) {
|
||||
member = this.client.resolver.ResolveGuildMember(this.guild, member);
|
||||
if (member) {
|
||||
if (this.guild.owner.id === member.id) {
|
||||
return new EvaluatedPermissions(member, Constants.ALL_PERMISSIONS);
|
||||
}
|
||||
permissionsFor(member) {
|
||||
member = this.client.resolver.resolveGuildMember(this.guild, member);
|
||||
if (member) {
|
||||
if (this.guild.owner.id === member.id) {
|
||||
return new EvaluatedPermissions(member, Constants.ALL_PERMISSIONS);
|
||||
}
|
||||
|
||||
let roles = member.roles;
|
||||
let permissions = 0;
|
||||
let overwrites = this.overwritesFor(member, true);
|
||||
const roles = member.roles;
|
||||
let permissions = 0;
|
||||
const overwrites = this.overwritesFor(member, true);
|
||||
|
||||
for (let role of roles) {
|
||||
permissions |= role.permissions;
|
||||
}
|
||||
for (const role of roles) {
|
||||
permissions |= role.permissions;
|
||||
}
|
||||
|
||||
for (let overwrite of overwrites.role.concat(overwrites.member)) {
|
||||
permissions = permissions & ~overwrite.denyData;
|
||||
permissions = permissions | overwrite.allowData;
|
||||
}
|
||||
for (const overwrite of overwrites.role.concat(overwrites.member)) {
|
||||
permissions &= ~overwrite.denyData;
|
||||
permissions |= overwrite.allowData;
|
||||
}
|
||||
|
||||
if (!!(permissions & (Constants.PermissionFlags.MANAGE_ROLES))) {
|
||||
permissions = Constants.ALL_PERMISSIONS;
|
||||
}
|
||||
const admin = Boolean(permissions & (Constants.PermissionFlags.MANAGE_ROLES));
|
||||
if (admin) {
|
||||
permissions = Constants.ALL_PERMISSIONS;
|
||||
}
|
||||
|
||||
return new EvaluatedPermissions(member, permissions);
|
||||
}
|
||||
}
|
||||
return new EvaluatedPermissions(member, permissions);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
overwritesFor(member, verified) {
|
||||
// for speed
|
||||
if (!verified)
|
||||
member = this.client.resolver.ResolveGuildMember(this.guild, member);
|
||||
if (member) {
|
||||
let found = [];
|
||||
let memberRoles = member._roles;
|
||||
overwritesFor(member, verified) {
|
||||
// for speed
|
||||
if (!verified) member = this.client.resolver.resolveGuildMember(this.guild, member);
|
||||
if (member) {
|
||||
const memberRoles = member._roles;
|
||||
|
||||
let roleOverwrites = [];
|
||||
let memberOverwrites = [];
|
||||
const roleOverwrites = [];
|
||||
const memberOverwrites = [];
|
||||
|
||||
for (let overwrite of this.permissionOverwrites) {
|
||||
if (overwrite.id === member.id) {
|
||||
memberOverwrites.push(overwrite);
|
||||
} else if (memberRoles.indexOf(overwrite.id) > -1) {
|
||||
roleOverwrites.push(overwrite);
|
||||
}
|
||||
}
|
||||
for (const overwrite of this.permissionOverwrites) {
|
||||
if (overwrite.id === member.id) {
|
||||
memberOverwrites.push(overwrite);
|
||||
} else if (memberRoles.indexOf(overwrite.id) > -1) {
|
||||
roleOverwrites.push(overwrite);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
role: roleOverwrites,
|
||||
member: memberOverwrites,
|
||||
};
|
||||
}
|
||||
return {
|
||||
role: roleOverwrites,
|
||||
member: memberOverwrites,
|
||||
};
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
edit(data) {
|
||||
return this.client.rest.methods.UpdateChannel(this, data);
|
||||
}
|
||||
edit(data) {
|
||||
return this.client.rest.methods.updateChannel(this, data);
|
||||
}
|
||||
|
||||
setName(name) {
|
||||
return this.client.rest.methods.UpdateChannel(this, { name, });
|
||||
}
|
||||
setName(name) {
|
||||
return this.client.rest.methods.updateChannel(this, { name });
|
||||
}
|
||||
|
||||
setPosition(position) {
|
||||
return this.rest.client.rest.methods.UpdateChannel(this, { position, });
|
||||
}
|
||||
setPosition(position) {
|
||||
return this.rest.client.rest.methods.updateChannel(this, { position });
|
||||
}
|
||||
|
||||
setTopic(topic) {
|
||||
return this.rest.client.rest.methods.UpdateChannel(this, { topic, });
|
||||
}
|
||||
setTopic(topic) {
|
||||
return this.rest.client.rest.methods.updateChannel(this, { topic });
|
||||
}
|
||||
|
||||
setBitrate() {
|
||||
return this.rest.client.rest.methods.UpdateChannel(this, { bitrate, });
|
||||
}
|
||||
setBitrate(bitrate) {
|
||||
return this.rest.client.rest.methods.updateChannel(this, { bitrate });
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.name;
|
||||
}
|
||||
toString() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ServerChannel;
|
||||
|
||||
@@ -1,30 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
const ServerChannel = require('./ServerChannel');
|
||||
const TextChannelDataStore = require('./datastore/TextChannelDataStore');
|
||||
const TextBasedChannel = require('./interface/TextBasedChannel');
|
||||
|
||||
class TextChannel extends ServerChannel {
|
||||
|
||||
constructor(guild, data) {
|
||||
super(guild, data);
|
||||
this.store = new TextChannelDataStore();
|
||||
}
|
||||
constructor(guild, data) {
|
||||
super(guild, data);
|
||||
this.store = new TextChannelDataStore();
|
||||
}
|
||||
|
||||
_cacheMessage(message) {
|
||||
let maxSize = this.client.options.max_message_cache;
|
||||
if (maxSize === 0) {
|
||||
// saves on performance
|
||||
return;
|
||||
}
|
||||
_cacheMessage(message) {
|
||||
const maxSize = this.client.options.max_message_cache;
|
||||
if (maxSize === 0) {
|
||||
// saves on performance
|
||||
return null;
|
||||
}
|
||||
|
||||
let storeKeys = Object.keys(this.store);
|
||||
if (storeKeys.length >= maxSize) {
|
||||
this.store.remove(storeKeys[0]);
|
||||
}
|
||||
const storeKeys = Object.keys(this.store);
|
||||
if (storeKeys.length >= maxSize) {
|
||||
this.store.remove(storeKeys[0]);
|
||||
}
|
||||
|
||||
return this.store.add('messages', message);
|
||||
}
|
||||
return this.store.add('messages', message);
|
||||
}
|
||||
}
|
||||
|
||||
TextBasedChannel.applyToClass(TextChannel);
|
||||
|
||||
@@ -1,89 +1,87 @@
|
||||
'use strict';
|
||||
|
||||
const TextBasedChannel = require('./interface/TextBasedChannel');
|
||||
|
||||
/**
|
||||
* Represents a User on Discord.
|
||||
*/
|
||||
class User {
|
||||
constructor(client, data) {
|
||||
this.client = client;
|
||||
if (data) {
|
||||
this.setup(data);
|
||||
}
|
||||
}
|
||||
constructor(client, data) {
|
||||
this.client = client;
|
||||
if (data) {
|
||||
this.setup(data);
|
||||
}
|
||||
}
|
||||
|
||||
setup(data) {
|
||||
/**
|
||||
* The username of the User
|
||||
* @type {String}
|
||||
*/
|
||||
this.username = data.username;
|
||||
/**
|
||||
* The ID of the User
|
||||
* @type {String}
|
||||
*/
|
||||
this.id = data.id;
|
||||
/**
|
||||
* A discriminator based on username for the User
|
||||
* @type {String}
|
||||
*/
|
||||
this.discriminator = data.discriminator;
|
||||
/**
|
||||
* The ID of the user's avatar
|
||||
* @type {String}
|
||||
*/
|
||||
this.avatar = data.avatar;
|
||||
/**
|
||||
* Whether or not the User is a Bot.
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.bot = Boolean(data.bot);
|
||||
/**
|
||||
* The status of the user:
|
||||
*
|
||||
* * **`online`** - user is online
|
||||
* * **`offline`** - user is offline
|
||||
* * **`idle`** - user is AFK
|
||||
* @type {String}
|
||||
*/
|
||||
this.status = data.status || this.status || 'offline';
|
||||
this.game = data.game || this.game;
|
||||
}
|
||||
setup(data) {
|
||||
/**
|
||||
* The username of the User
|
||||
* @type {String}
|
||||
*/
|
||||
this.username = data.username;
|
||||
/**
|
||||
* The ID of the User
|
||||
* @type {String}
|
||||
*/
|
||||
this.id = data.id;
|
||||
/**
|
||||
* A discriminator based on username for the User
|
||||
* @type {String}
|
||||
*/
|
||||
this.discriminator = data.discriminator;
|
||||
/**
|
||||
* The ID of the user's avatar
|
||||
* @type {String}
|
||||
*/
|
||||
this.avatar = data.avatar;
|
||||
/**
|
||||
* Whether or not the User is a Bot.
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.bot = Boolean(data.bot);
|
||||
/**
|
||||
* The status of the user:
|
||||
*
|
||||
* * **`online`** - user is online
|
||||
* * **`offline`** - user is offline
|
||||
* * **`idle`** - user is AFK
|
||||
* @type {String}
|
||||
*/
|
||||
this.status = data.status || this.status || 'offline';
|
||||
this.game = data.game || this.game;
|
||||
}
|
||||
|
||||
toString() {
|
||||
return `<@${this.id}>`;
|
||||
}
|
||||
toString() {
|
||||
return `<@${this.id}>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a DM Channel (if one exists) between the Client and the User. Resolves with the Channel if successful.
|
||||
* @return {Promise<DMChannel>}
|
||||
*/
|
||||
deleteDM() {
|
||||
return this.client.rest.methods.DeleteChannel(this);
|
||||
}
|
||||
/**
|
||||
* Deletes a DM Channel (if one exists) between the Client and the User. Resolves with the Channel if successful.
|
||||
* @return {Promise<DMChannel>}
|
||||
*/
|
||||
deleteDM() {
|
||||
return this.client.rest.methods.deleteChannel(this);
|
||||
}
|
||||
|
||||
equals(user) {
|
||||
let base = (
|
||||
this.username === user.username &&
|
||||
this.id === user.id &&
|
||||
this.discriminator === user.discriminator &&
|
||||
this.avatar === user.avatar &&
|
||||
this.bot === Boolean(user.bot)
|
||||
);
|
||||
equals(user) {
|
||||
let base = (
|
||||
this.username === user.username &&
|
||||
this.id === user.id &&
|
||||
this.discriminator === user.discriminator &&
|
||||
this.avatar === user.avatar &&
|
||||
this.bot === Boolean(user.bot)
|
||||
);
|
||||
|
||||
if (base) {
|
||||
if (user.status) {
|
||||
base = this.status === user.status;
|
||||
}
|
||||
if (base) {
|
||||
if (user.status) {
|
||||
base = this.status === user.status;
|
||||
}
|
||||
|
||||
if (user.game) {
|
||||
base = this.game === user.game;
|
||||
}
|
||||
}
|
||||
if (user.game) {
|
||||
base = this.game === user.game;
|
||||
}
|
||||
}
|
||||
|
||||
return base;
|
||||
}
|
||||
return base;
|
||||
}
|
||||
}
|
||||
|
||||
TextBasedChannel.applyToClass(User);
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
const ServerChannel = require('./ServerChannel');
|
||||
const VoiceChannelDataStore = require('./datastore/VoiceChannelDataStore');
|
||||
|
||||
class VoiceChannel extends ServerChannel {
|
||||
constructor(guild, data) {
|
||||
super(guild, data);
|
||||
this.store = new VoiceChannelDataStore();
|
||||
}
|
||||
constructor(guild, data) {
|
||||
super(guild, data);
|
||||
this.store = new VoiceChannelDataStore();
|
||||
}
|
||||
|
||||
setup(data) {
|
||||
super.setup(data);
|
||||
this.bitrate = data.bitrate;
|
||||
}
|
||||
setup(data) {
|
||||
super.setup(data);
|
||||
this.bitrate = data.bitrate;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = VoiceChannel;
|
||||
|
||||
@@ -1,43 +1,40 @@
|
||||
'use strict';
|
||||
class AbstractDataStore {
|
||||
constructor() {
|
||||
this.data = {};
|
||||
}
|
||||
|
||||
class AbstractDataStore{
|
||||
constructor() {
|
||||
this.data = {};
|
||||
}
|
||||
register(name) {
|
||||
this.data[name] = {};
|
||||
}
|
||||
|
||||
register(name) {
|
||||
this.data[name] = {};
|
||||
}
|
||||
add(location, object) {
|
||||
if (this.data[location][object.id]) {
|
||||
return this.data[location][object.id];
|
||||
}
|
||||
this.data[location][object.id] = object;
|
||||
return object;
|
||||
}
|
||||
|
||||
add(location, object) {
|
||||
if (this.data[location][object.id]) {
|
||||
return this.data[location][object.id];
|
||||
} else {
|
||||
return this.data[location][object.id] = object;
|
||||
}
|
||||
}
|
||||
clear(location) {
|
||||
this.data[location] = {};
|
||||
}
|
||||
|
||||
clear(location) {
|
||||
this.data[location] = {};
|
||||
}
|
||||
remove(location, object) {
|
||||
const id = (typeof object === 'string' || object instanceof String) ? object : object.id;
|
||||
if (this.data[location][id]) {
|
||||
delete this.data[location][id];
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
remove(location, object) {
|
||||
let id = (typeof object === 'string' || object instanceof String) ? object : object.id;
|
||||
if (this.data[location][id]) {
|
||||
delete this.data[location][id];
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
get(location, value) {
|
||||
return this.data[location][value];
|
||||
}
|
||||
|
||||
get(location, value) {
|
||||
return this.data[location][value];
|
||||
}
|
||||
|
||||
getAsArray(location) {
|
||||
return Object.values(this.data[location]);
|
||||
}
|
||||
getAsArray(location) {
|
||||
return Object.values(this.data[location]);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AbstractDataStore;
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const AbstractDataStore = require('./AbstractDataStore');
|
||||
const Constants = require('../../util/Constants');
|
||||
const CloneObject = require('../../util/CloneObject');
|
||||
const cloneObject = require('../../util/CloneObject');
|
||||
const Guild = require('../Guild');
|
||||
const User = require('../User');
|
||||
const DMChannel = require('../DMChannel');
|
||||
@@ -10,98 +8,99 @@ const TextChannel = require('../TextChannel');
|
||||
const VoiceChannel = require('../VoiceChannel');
|
||||
const ServerChannel = require('../ServerChannel');
|
||||
|
||||
class ClientDataStore extends AbstractDataStore{
|
||||
constructor(client) {
|
||||
super();
|
||||
class ClientDataStore extends AbstractDataStore {
|
||||
constructor(client) {
|
||||
super();
|
||||
|
||||
this.client = client;
|
||||
this.token = null;
|
||||
this.session = null;
|
||||
this.user = null;
|
||||
this.email = null;
|
||||
this.password = null;
|
||||
this.client = client;
|
||||
this.token = null;
|
||||
this.session = null;
|
||||
this.user = null;
|
||||
this.email = null;
|
||||
this.password = null;
|
||||
|
||||
this.register('users');
|
||||
this.register('guilds');
|
||||
this.register('channels');
|
||||
}
|
||||
this.register('users');
|
||||
this.register('guilds');
|
||||
this.register('channels');
|
||||
}
|
||||
|
||||
get pastReady() {
|
||||
return this.client.ws.status === Constants.Status.READY;
|
||||
}
|
||||
get pastReady() {
|
||||
return this.client.ws.status === Constants.Status.READY;
|
||||
}
|
||||
|
||||
NewGuild(data) {
|
||||
let already = this.get('guilds', data.id);
|
||||
let guild = this.add('guilds', new Guild(this.client, data));
|
||||
if (this.pastReady && !already) {
|
||||
this.client.emit(Constants.Events.GUILD_CREATE, guild);
|
||||
}
|
||||
newGuild(data) {
|
||||
const already = this.get('guilds', data.id);
|
||||
const guild = this.add('guilds', new Guild(this.client, data));
|
||||
if (this.pastReady && !already) {
|
||||
this.client.emit(Constants.Events.GUILD_CREATE, guild);
|
||||
}
|
||||
|
||||
return guild;
|
||||
}
|
||||
return guild;
|
||||
}
|
||||
|
||||
NewUser(data) {
|
||||
return this.add('users', new User(this.client, data));
|
||||
}
|
||||
newUser(data) {
|
||||
return this.add('users', new User(this.client, data));
|
||||
}
|
||||
|
||||
NewChannel(data, guild) {
|
||||
let already = this.get('channels', data.id);
|
||||
let channel;
|
||||
if (data.is_private) {
|
||||
channel = new DMChannel(this.client, data);
|
||||
}else {
|
||||
guild = guild || this.get('guilds', data.guild_id);
|
||||
if (guild) {
|
||||
if (data.type === 'text') {
|
||||
channel = new TextChannel(guild, data);
|
||||
guild.store.add('channels', channel);
|
||||
}else if (data.type === 'voice') {
|
||||
channel = new VoiceChannel(guild, data);
|
||||
guild.store.add('channels', channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
newChannel(data, $guild) {
|
||||
let guild = $guild;
|
||||
const already = this.get('channels', data.id);
|
||||
let channel;
|
||||
if (data.is_private) {
|
||||
channel = new DMChannel(this.client, data);
|
||||
} else {
|
||||
guild = guild || this.get('guilds', data.guild_id);
|
||||
if (guild) {
|
||||
if (data.type === 'text') {
|
||||
channel = new TextChannel(guild, data);
|
||||
guild.store.add('channels', channel);
|
||||
} else if (data.type === 'voice') {
|
||||
channel = new VoiceChannel(guild, data);
|
||||
guild.store.add('channels', channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (channel) {
|
||||
if (this.pastReady && !already) {
|
||||
this.client.emit(Constants.Events.CHANNEL_CREATE, channel);
|
||||
}
|
||||
if (channel) {
|
||||
if (this.pastReady && !already) {
|
||||
this.client.emit(Constants.Events.CHANNEL_CREATE, channel);
|
||||
}
|
||||
|
||||
return this.add('channels', channel);
|
||||
}
|
||||
}
|
||||
return this.add('channels', channel);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
KillGuild(guild) {
|
||||
let already = this.get('guilds', guilds.id);
|
||||
this.remove('guilds', guild);
|
||||
if (already && this.pastReady) {
|
||||
this.client.emit(Constants.Events.GUILD_DELETE, guild);
|
||||
}
|
||||
}
|
||||
killGuild(guild) {
|
||||
const already = this.get('guilds', guild.id);
|
||||
this.remove('guilds', guild);
|
||||
if (already && this.pastReady) {
|
||||
this.client.emit(Constants.Events.GUILD_DELETE, guild);
|
||||
}
|
||||
}
|
||||
|
||||
KillUser(user) {
|
||||
this.remove('users', user);
|
||||
}
|
||||
killUser(user) {
|
||||
this.remove('users', user);
|
||||
}
|
||||
|
||||
KillChannel(channel) {
|
||||
this.remove('channels', channel);
|
||||
if (channel instanceof ServerChannel) {
|
||||
channel.guild.store.remove('channels', channel);
|
||||
}
|
||||
}
|
||||
killChannel(channel) {
|
||||
this.remove('channels', channel);
|
||||
if (channel instanceof ServerChannel) {
|
||||
channel.guild.store.remove('channels', channel);
|
||||
}
|
||||
}
|
||||
|
||||
UpdateGuild(currentGuild, newData) {
|
||||
let oldGuild = CloneObject(currentGuild);
|
||||
currentGuild.setup(newData);
|
||||
if (this.pastReady) {
|
||||
this.client.emit(Constants.Events.GUILD_UPDATE, oldGuild, currentGuild);
|
||||
}
|
||||
}
|
||||
updateGuild(currentGuild, newData) {
|
||||
const oldGuild = cloneObject(currentGuild);
|
||||
currentGuild.setup(newData);
|
||||
if (this.pastReady) {
|
||||
this.client.emit(Constants.Events.GUILD_UPDATE, oldGuild, currentGuild);
|
||||
}
|
||||
}
|
||||
|
||||
UpdateChannel(currentChannel, newData) {
|
||||
let oldChannel = CloneObject(currentChannel);
|
||||
currentChannel.setup(newData);
|
||||
}
|
||||
updateChannel(currentChannel, newData) {
|
||||
currentChannel.setup(newData);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ClientDataStore;
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
const AbstractDataStore = require('./AbstractDataStore');
|
||||
|
||||
class GuildDataStore extends AbstractDataStore{
|
||||
constructor() {
|
||||
super();
|
||||
class GuildDataStore extends AbstractDataStore {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.register('members');
|
||||
this.register('channels');
|
||||
}
|
||||
this.register('members');
|
||||
this.register('channels');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildDataStore;
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
const AbstractDataStore = require('./AbstractDataStore');
|
||||
|
||||
class TextChannelDataStore extends AbstractDataStore{
|
||||
constructor() {
|
||||
super();
|
||||
this.register('messages');
|
||||
}
|
||||
class TextChannelDataStore extends AbstractDataStore {
|
||||
constructor() {
|
||||
super();
|
||||
this.register('messages');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TextChannelDataStore;
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
const AbstractDataStore = require('./AbstractDataStore');
|
||||
|
||||
class VoiceChannelDataStore extends AbstractDataStore{
|
||||
constructor() {
|
||||
super();
|
||||
this.register('members');
|
||||
}
|
||||
class VoiceChannelDataStore extends AbstractDataStore {
|
||||
constructor() {
|
||||
super();
|
||||
this.register('members');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = VoiceChannelDataStore;
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
const AbstractDataStore = require('./AbstractDataStore');
|
||||
|
||||
class WebSocketManagerDataStore extends AbstractDataStore{
|
||||
constructor() {
|
||||
super();
|
||||
this.sessionID = null;
|
||||
this.sequence = -1;
|
||||
this.gateway = null;
|
||||
}
|
||||
class WebSocketManagerDataStore extends AbstractDataStore {
|
||||
constructor() {
|
||||
super();
|
||||
this.sessionID = null;
|
||||
this.sequence = -1;
|
||||
this.gateway = null;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = WebSocketManagerDataStore;
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
function sendMessage(content, options) {
|
||||
options = options || {};
|
||||
return this.client.rest.methods.SendMessage(this, content, options.tts);
|
||||
function sendMessage(content, options = {}) {
|
||||
return this.client.rest.methods.sendMessage(this, content, options.tts);
|
||||
}
|
||||
|
||||
function sendTTSMessage(content, options) {
|
||||
options = options || {};
|
||||
return this.client.rest.methods.SendMessage(this, content, true);
|
||||
function sendTTSMessage(content) {
|
||||
return this.client.rest.methods.sendMessage(this, content, true);
|
||||
}
|
||||
|
||||
exports.applyToClass = structure => {
|
||||
structure.prototype.sendMessage = sendMessage;
|
||||
structure.prototype.sendMessage = sendMessage;
|
||||
structure.prototype.sendTTSMessage = sendTTSMessage;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user