mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 01:23:31 +01:00
ESLint stuff...
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
/*
|
||||
|
||||
ABOUT ACTIONS
|
||||
@@ -14,14 +12,14 @@ that WebSocket events don't clash with REST methods.
|
||||
|
||||
class GenericAction {
|
||||
|
||||
constructor(client) {
|
||||
this.client = client;
|
||||
}
|
||||
constructor(client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
handle(data) {
|
||||
handle(data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = GenericAction;
|
||||
|
||||
@@ -1,30 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
const requireAction = name => require(`./${name}`);
|
||||
|
||||
class ActionsManager {
|
||||
constructor(client) {
|
||||
this.client = client;
|
||||
|
||||
this.register('MessageCreate');
|
||||
this.register('MessageDelete');
|
||||
this.register('MessageUpdate');
|
||||
this.register('ChannelCreate');
|
||||
this.register('ChannelDelete');
|
||||
this.register('ChannelUpdate');
|
||||
this.register('GuildDelete');
|
||||
this.register('GuildUpdate');
|
||||
this.register('GuildMemberRemove');
|
||||
this.register('GuildRoleCreate');
|
||||
this.register('GuildRoleDelete');
|
||||
this.register('GuildRoleUpdate');
|
||||
this.register('UserUpdate');
|
||||
}
|
||||
|
||||
register(name) {
|
||||
let Action = requireAction(name);
|
||||
this[name] = new Action(this.client);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ActionsManager;
|
||||
const requireAction = name => require(`./${name}`);
|
||||
|
||||
class ActionsManager {
|
||||
constructor(client) {
|
||||
this.client = client;
|
||||
|
||||
this.register('MessageCreate');
|
||||
this.register('MessageDelete');
|
||||
this.register('MessageUpdate');
|
||||
this.register('ChannelCreate');
|
||||
this.register('ChannelDelete');
|
||||
this.register('ChannelUpdate');
|
||||
this.register('GuildDelete');
|
||||
this.register('GuildUpdate');
|
||||
this.register('GuildMemberRemove');
|
||||
this.register('GuildRoleCreate');
|
||||
this.register('GuildRoleDelete');
|
||||
this.register('GuildRoleUpdate');
|
||||
this.register('UserUpdate');
|
||||
}
|
||||
|
||||
register(name) {
|
||||
const Action = requireAction(name);
|
||||
this[name] = new Action(this.client);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ActionsManager;
|
||||
|
||||
@@ -1,23 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Constants = require('../../util/Constants');
|
||||
const Message = require('../../structures/Message');
|
||||
|
||||
class ChannelCreateAction extends Action {
|
||||
|
||||
constructor(client) {
|
||||
super(client);
|
||||
}
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const channel = client.store.newChannel(data);
|
||||
|
||||
handle(data) {
|
||||
let client = this.client;
|
||||
let channel = client.store.NewChannel(data);
|
||||
|
||||
return {
|
||||
channel,
|
||||
};
|
||||
}
|
||||
};
|
||||
return {
|
||||
channel,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ChannelCreateAction;
|
||||
|
||||
@@ -1,44 +1,36 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Constants = require('../../util/Constants');
|
||||
const Message = require('../../structures/Message');
|
||||
|
||||
class ChannelDeleteAction extends Action {
|
||||
|
||||
constructor(client) {
|
||||
super(client);
|
||||
this.timeouts = [];
|
||||
this.deleted = {};
|
||||
}
|
||||
|
||||
handle(data) {
|
||||
let client = this.client;
|
||||
let channel = client.store.get('channels', data.id);
|
||||
|
||||
if (channel) {
|
||||
|
||||
client.store.KillChannel(channel);
|
||||
this.deleted[channel.id] = channel;
|
||||
this.scheduleForDeletion(channel.id);
|
||||
|
||||
} else if (this.deleted[data.id]) {
|
||||
|
||||
channel = this.deleted[data.id];
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
channel,
|
||||
};
|
||||
}
|
||||
|
||||
scheduleForDeletion(id) {
|
||||
this.timeouts.push(
|
||||
setTimeout(() => delete this.deleted[id],
|
||||
this.client.options.rest_ws_bridge_timeout)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = ChannelDeleteAction;
|
||||
const Action = require('./Action');
|
||||
|
||||
class ChannelDeleteAction extends Action {
|
||||
|
||||
constructor(client) {
|
||||
super(client);
|
||||
this.timeouts = [];
|
||||
this.deleted = {};
|
||||
}
|
||||
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
let channel = client.store.get('channels', data.id);
|
||||
|
||||
if (channel) {
|
||||
client.store.killChannel(channel);
|
||||
this.deleted[channel.id] = channel;
|
||||
this.scheduleForDeletion(channel.id);
|
||||
} else if (this.deleted[data.id]) {
|
||||
channel = this.deleted[data.id];
|
||||
}
|
||||
|
||||
return {
|
||||
channel,
|
||||
};
|
||||
}
|
||||
|
||||
scheduleForDeletion(id) {
|
||||
this.timeouts.push(
|
||||
setTimeout(() => delete this.deleted[id],
|
||||
this.client.options.rest_ws_bridge_timeout)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ChannelDeleteAction;
|
||||
|
||||
@@ -1,39 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Constants = require('../../util/Constants');
|
||||
const CloneObject = require('../../util/CloneObject');
|
||||
const Message = require('../../structures/Message');
|
||||
const cloneObject = require('../../util/CloneObject');
|
||||
|
||||
class ChannelUpdateAction extends Action {
|
||||
|
||||
constructor(client) {
|
||||
super(client);
|
||||
}
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const channel = client.store.get('channels', data.id);
|
||||
|
||||
handle(data) {
|
||||
if (channel) {
|
||||
const oldChannel = cloneObject(channel);
|
||||
channel.setup(data);
|
||||
if (!oldChannel.equals(data)) {
|
||||
client.emit(Constants.Events.CHANNEL_UPDATE, oldChannel, channel);
|
||||
}
|
||||
|
||||
let client = this.client;
|
||||
let channel = client.store.get('channels', data.id);
|
||||
return {
|
||||
old: oldChannel,
|
||||
updated: channel,
|
||||
};
|
||||
}
|
||||
|
||||
if (channel) {
|
||||
let oldChannel = CloneObject(channel);
|
||||
channel.setup(data);
|
||||
if (!oldChannel.equals(data)) {
|
||||
client.emit(Constants.Events.CHANNEL_UPDATE, oldChannel, channel);
|
||||
}
|
||||
|
||||
return {
|
||||
old: oldChannel,
|
||||
updated: channel,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
old: null,
|
||||
updated: null,
|
||||
};
|
||||
}
|
||||
};
|
||||
return {
|
||||
old: null,
|
||||
updated: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ChannelUpdateAction;
|
||||
|
||||
@@ -1,54 +1,49 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Constants = require('../../util/Constants');
|
||||
const Message = require('../../structures/Message');
|
||||
|
||||
class GuildDeleteAction extends Action {
|
||||
|
||||
constructor(client) {
|
||||
super(client);
|
||||
this.deleted = {};
|
||||
this.timeouts = [];
|
||||
}
|
||||
constructor(client) {
|
||||
super(client);
|
||||
this.deleted = {};
|
||||
this.timeouts = [];
|
||||
}
|
||||
|
||||
handle(data) {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
let guild = client.store.get('guilds', data.id);
|
||||
|
||||
let client = this.client;
|
||||
let guild = client.store.get('guilds', data.id);
|
||||
if (guild) {
|
||||
if (guild.available && data.unavailable) {
|
||||
// guild is unavailable
|
||||
guild.available = false;
|
||||
client.emit(Constants.Events.GUILD_UNAVAILABLE, guild);
|
||||
|
||||
if (guild) {
|
||||
if (guild.available && data.unavailable) {
|
||||
// guild is unavailable
|
||||
guild.available = false;
|
||||
client.emit(Constants.Events.GUILD_UNAVAILABLE, guild);
|
||||
// stops the GuildDelete packet thinking a guild was actually deleted,
|
||||
// handles emitting of event itself
|
||||
return {
|
||||
guild: null,
|
||||
};
|
||||
}
|
||||
// delete guild
|
||||
client.store.remove('guilds', guild);
|
||||
this.deleted[guild.id] = guild;
|
||||
this.scheduleForDeletion(guild.id);
|
||||
} else if (this.deleted[data.id]) {
|
||||
guild = this.deleted[data.id];
|
||||
}
|
||||
|
||||
// stops the GuildDelete packet thinking a guild was actually deleted,
|
||||
// handles emitting of event itself
|
||||
return {
|
||||
guild: null,
|
||||
};
|
||||
} else {
|
||||
// delete guild
|
||||
client.store.remove('guilds', guild);
|
||||
this.deleted[guild.id] = guild;
|
||||
this.scheduleForDeletion(guild.id);
|
||||
}
|
||||
} else if (this.deleted[data.id]) {
|
||||
guild = this.deleted[data.id];
|
||||
}
|
||||
return {
|
||||
guild,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
guild,
|
||||
};
|
||||
}
|
||||
|
||||
scheduleForDeletion(id) {
|
||||
this.timeouts.push(
|
||||
setTimeout(() => delete this.deleted[id],
|
||||
this.client.options.rest_ws_bridge_timeout)
|
||||
);
|
||||
}
|
||||
};
|
||||
scheduleForDeletion(id) {
|
||||
this.timeouts.push(
|
||||
setTimeout(() => delete this.deleted[id],
|
||||
this.client.options.rest_ws_bridge_timeout)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildDeleteAction;
|
||||
|
||||
@@ -1,51 +1,48 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Constants = require('../../util/Constants');
|
||||
const Message = require('../../structures/Message');
|
||||
|
||||
class GuildMemberRemoveAction extends Action {
|
||||
|
||||
constructor(client) {
|
||||
super(client);
|
||||
this.timeouts = [];
|
||||
this.deleted = {};
|
||||
}
|
||||
constructor(client) {
|
||||
super(client);
|
||||
this.timeouts = [];
|
||||
this.deleted = {};
|
||||
}
|
||||
|
||||
handle(data) {
|
||||
let client = this.client;
|
||||
let guild = client.store.get('guilds', data.guild_id);
|
||||
if (guild) {
|
||||
let member = guild.store.get('members', data.user.id);
|
||||
if (member) {
|
||||
guild._removeMember(member);
|
||||
this.deleted[guild.id + data.user.id] = member;
|
||||
client.emit(Constants.Events.GUILD_MEMBER_REMOVE, guild, member);
|
||||
this.scheduleForDeletion(guild.id, data.user.id);
|
||||
}
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const guild = client.store.get('guilds', data.guild_id);
|
||||
if (guild) {
|
||||
let member = guild.store.get('members', data.user.id);
|
||||
if (member) {
|
||||
guild._removeMember(member);
|
||||
this.deleted[guild.id + data.user.id] = member;
|
||||
client.emit(Constants.Events.GUILD_MEMBER_REMOVE, guild, member);
|
||||
this.scheduleForDeletion(guild.id, data.user.id);
|
||||
}
|
||||
|
||||
if (!member) {
|
||||
member = this.deleted[guild.id + data.user.id];
|
||||
}
|
||||
if (!member) {
|
||||
member = this.deleted[guild.id + data.user.id];
|
||||
}
|
||||
|
||||
return {
|
||||
g: guild,
|
||||
m: member,
|
||||
};
|
||||
}
|
||||
return {
|
||||
g: guild,
|
||||
m: member,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
g: guild,
|
||||
m: null,
|
||||
};
|
||||
}
|
||||
return {
|
||||
g: guild,
|
||||
m: null,
|
||||
};
|
||||
}
|
||||
|
||||
scheduleForDeletion(guildID, userID) {
|
||||
this.timeouts.push(
|
||||
setTimeout(() => delete this.deleted[guildID + userID],
|
||||
this.client.options.rest_ws_bridge_timeout)
|
||||
);
|
||||
}
|
||||
};
|
||||
scheduleForDeletion(guildID, userID) {
|
||||
this.timeouts.push(
|
||||
setTimeout(() => delete this.deleted[guildID + userID],
|
||||
this.client.options.rest_ws_bridge_timeout)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildMemberRemoveAction;
|
||||
|
||||
@@ -1,38 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Constants = require('../../util/Constants');
|
||||
const Role = require('../../structures/Role');
|
||||
|
||||
class GuildRoleCreate extends Action {
|
||||
|
||||
constructor(client) {
|
||||
super(client);
|
||||
}
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const guild = client.store.get('guilds', data.guild_id);
|
||||
|
||||
handle(data) {
|
||||
if (guild) {
|
||||
const already = guild.store.get('roles', data.role.id);
|
||||
const role = new Role(guild, data.role);
|
||||
guild.store.add('roles', role);
|
||||
|
||||
let client = this.client;
|
||||
let guild = client.store.get('guilds', data.guild_id);
|
||||
if (!already) {
|
||||
client.emit(Constants.Events.GUILD_ROLE_CREATE, guild, role);
|
||||
}
|
||||
|
||||
if (guild) {
|
||||
let already = guild.store.get('roles', data.role.id);
|
||||
let role = new Role(guild, data.role);
|
||||
guild.store.add('roles', role);
|
||||
return {
|
||||
role,
|
||||
};
|
||||
}
|
||||
|
||||
if (!already) {
|
||||
client.emit(Constants.Events.GUILD_ROLE_CREATE, guild, role);
|
||||
}
|
||||
|
||||
return {
|
||||
role,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
role: null,
|
||||
};
|
||||
}
|
||||
};
|
||||
return {
|
||||
role: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildRoleCreate;
|
||||
|
||||
@@ -1,50 +1,47 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Constants = require('../../util/Constants');
|
||||
const Message = require('../../structures/Message');
|
||||
|
||||
class GuildRoleDeleteAction extends Action {
|
||||
|
||||
constructor(client) {
|
||||
super(client);
|
||||
this.timeouts = [];
|
||||
this.deleted = {};
|
||||
}
|
||||
constructor(client) {
|
||||
super(client);
|
||||
this.timeouts = [];
|
||||
this.deleted = {};
|
||||
}
|
||||
|
||||
handle(data) {
|
||||
let client = this.client;
|
||||
let guild = client.store.get('guilds', data.guild_id);
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const guild = client.store.get('guilds', data.guild_id);
|
||||
|
||||
if (guild) {
|
||||
let exists = guild.store.get('roles', data.role_id);
|
||||
if (exists) {
|
||||
guild.store.remove('roles', data.role_id);
|
||||
this.deleted[guild.id + data.role_id] = exists;
|
||||
this.scheduleForDeletion(guild.id, data.role_id);
|
||||
client.emit(Constants.Events.GUILD_ROLE_DELETE, guild, exists);
|
||||
}
|
||||
if (guild) {
|
||||
let exists = guild.store.get('roles', data.role_id);
|
||||
if (exists) {
|
||||
guild.store.remove('roles', data.role_id);
|
||||
this.deleted[guild.id + data.role_id] = exists;
|
||||
this.scheduleForDeletion(guild.id, data.role_id);
|
||||
client.emit(Constants.Events.GUILD_ROLE_DELETE, guild, exists);
|
||||
}
|
||||
|
||||
if (!exists) {
|
||||
exists = this.deleted[guild.id + data.role_id];
|
||||
}
|
||||
if (!exists) {
|
||||
exists = this.deleted[guild.id + data.role_id];
|
||||
}
|
||||
|
||||
return {
|
||||
role: exists,
|
||||
};
|
||||
}
|
||||
return {
|
||||
role: exists,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
role: null,
|
||||
};
|
||||
}
|
||||
return {
|
||||
role: null,
|
||||
};
|
||||
}
|
||||
|
||||
scheduleForDeletion(guildID, roleID) {
|
||||
this.timeouts.push(
|
||||
setTimeout(() => delete this.deleted[guildID + roleID],
|
||||
this.client.options.rest_ws_bridge_timeout)
|
||||
);
|
||||
}
|
||||
};
|
||||
scheduleForDeletion(guildID, roleID) {
|
||||
this.timeouts.push(
|
||||
setTimeout(() => delete this.deleted[guildID + roleID],
|
||||
this.client.options.rest_ws_bridge_timeout)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildRoleDeleteAction;
|
||||
|
||||
@@ -1,44 +1,36 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Constants = require('../../util/Constants');
|
||||
const CloneObject = require('../../util/CloneObject');
|
||||
const Message = require('../../structures/Message');
|
||||
const cloneObject = require('../../util/CloneObject');
|
||||
|
||||
class GuildRoleUpdateAction extends Action {
|
||||
|
||||
constructor(client) {
|
||||
super(client);
|
||||
}
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const guild = client.store.get('guilds', data.guild_id);
|
||||
|
||||
handle(data) {
|
||||
const roleData = data.role;
|
||||
|
||||
let client = this.client;
|
||||
let guild = client.store.get('guilds', data.guild_id);
|
||||
if (guild) {
|
||||
let oldRole;
|
||||
const existingRole = guild.store.get('roles', roleData.id);
|
||||
// exists and not the same
|
||||
if (existingRole && !existingRole.equals(roleData)) {
|
||||
oldRole = cloneObject(existingRole);
|
||||
existingRole.setup(data.role);
|
||||
client.emit(Constants.Events.GUILD_ROLE_UPDATE, guild, oldRole, existingRole);
|
||||
}
|
||||
|
||||
let roleData = data.role;
|
||||
return {
|
||||
old: oldRole,
|
||||
updated: existingRole,
|
||||
};
|
||||
}
|
||||
|
||||
if (guild) {
|
||||
let oldRole;
|
||||
let existingRole = guild.store.get('roles', roleData.id);
|
||||
// exists and not the same
|
||||
if (existingRole && !existingRole.equals(roleData)) {
|
||||
oldRole = CloneObject(existingRole);
|
||||
existingRole.setup(data.role);
|
||||
client.emit(Constants.Events.GUILD_ROLE_UPDATE, guild, oldRole, existingRole);
|
||||
}
|
||||
|
||||
return {
|
||||
old: oldRole,
|
||||
updated: existingRole,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
old: null,
|
||||
updated: null,
|
||||
};
|
||||
}
|
||||
};
|
||||
return {
|
||||
old: null,
|
||||
updated: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildRoleUpdateAction;
|
||||
|
||||
@@ -1,42 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Constants = require('../../util/Constants');
|
||||
const CloneObject = require('../../util/CloneObject');
|
||||
const Message = require('../../structures/Message');
|
||||
const cloneObject = require('../../util/CloneObject');
|
||||
|
||||
class GuildUpdateAction extends Action {
|
||||
|
||||
constructor(client) {
|
||||
super(client);
|
||||
this.deleted = {};
|
||||
this.timeouts = [];
|
||||
}
|
||||
constructor(client) {
|
||||
super(client);
|
||||
this.deleted = {};
|
||||
this.timeouts = [];
|
||||
}
|
||||
|
||||
handle(data) {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const guild = client.store.get('guilds', data.id);
|
||||
|
||||
let client = this.client;
|
||||
let guild = client.store.get('guilds', data.id);
|
||||
if (guild) {
|
||||
const oldGuild = cloneObject(guild);
|
||||
guild.setup(data);
|
||||
|
||||
if (guild) {
|
||||
let oldGuild = CloneObject(guild);
|
||||
guild.setup(data);
|
||||
if (!oldGuild.equals(data)) {
|
||||
client.emit(Constants.Events.GUILD_UPDATE, oldGuild, guild);
|
||||
}
|
||||
|
||||
if (!oldGuild.equals(data)) {
|
||||
client.emit(Constants.Events.GUILD_UPDATE, oldGuild, guild);
|
||||
}
|
||||
return {
|
||||
old: oldGuild,
|
||||
updated: guild,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
old: oldGuild,
|
||||
updated: guild,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
old: null,
|
||||
updated: null,
|
||||
};
|
||||
}
|
||||
};
|
||||
return {
|
||||
old: null,
|
||||
updated: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildUpdateAction;
|
||||
|
||||
@@ -1,31 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Constants = require('../../util/Constants');
|
||||
const Message = require('../../structures/Message');
|
||||
|
||||
class MessageCreateAction extends Action {
|
||||
|
||||
constructor(client) {
|
||||
super(client);
|
||||
}
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const channel = client.store.get('channels', data.channel_id);
|
||||
|
||||
handle(data) {
|
||||
if (channel) {
|
||||
const message = channel._cacheMessage(new Message(channel, data, client));
|
||||
return {
|
||||
m: message,
|
||||
};
|
||||
}
|
||||
|
||||
let client = this.client;
|
||||
let channel = client.store.get('channels', data.channel_id);
|
||||
|
||||
if (channel) {
|
||||
let message = channel._cacheMessage(new Message(channel, data, client));
|
||||
return {
|
||||
m: message,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
m: null,
|
||||
};
|
||||
}
|
||||
};
|
||||
return {
|
||||
m: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MessageCreateAction;
|
||||
|
||||
@@ -1,51 +1,43 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Constants = require('../../util/Constants');
|
||||
const Message = require('../../structures/Message');
|
||||
|
||||
class MessageDeleteAction extends Action {
|
||||
|
||||
constructor(client) {
|
||||
super(client);
|
||||
this.timeouts = [];
|
||||
this.deleted = {};
|
||||
}
|
||||
constructor(client) {
|
||||
super(client);
|
||||
this.timeouts = [];
|
||||
this.deleted = {};
|
||||
}
|
||||
|
||||
handle(data) {
|
||||
let client = this.client;
|
||||
let channel = client.store.get('channels', data.channel_id);
|
||||
if (channel) {
|
||||
let message = channel.store.get('messages', data.id);
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const channel = client.store.get('channels', data.channel_id);
|
||||
if (channel) {
|
||||
let message = channel.store.get('messages', data.id);
|
||||
|
||||
if (message) {
|
||||
if (message) {
|
||||
channel.store.remove('messages', message.id);
|
||||
this.deleted[channel.id + message.id] = message;
|
||||
this.scheduleForDeletion(channel.id, message.id);
|
||||
} else if (this.deleted[channel.id + data.id]) {
|
||||
message = this.deleted[channel.id + data.id];
|
||||
}
|
||||
|
||||
channel.store.remove('messages', message.id);
|
||||
this.deleted[channel.id + message.id] = message;
|
||||
this.scheduleForDeletion(channel.id, message.id);
|
||||
return {
|
||||
m: message,
|
||||
};
|
||||
}
|
||||
|
||||
} else if (this.deleted[channel.id + data.id]) {
|
||||
return {
|
||||
m: null,
|
||||
};
|
||||
}
|
||||
|
||||
message = this.deleted[channel.id + data.id];
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
m: message,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
m: null,
|
||||
};
|
||||
}
|
||||
|
||||
scheduleForDeletion(channelID, messageID) {
|
||||
this.timeouts.push(
|
||||
setTimeout(() => delete this.deleted[channelID + messageID],
|
||||
this.client.options.rest_ws_bridge_timeout)
|
||||
);
|
||||
}
|
||||
};
|
||||
scheduleForDeletion(channelID, messageID) {
|
||||
this.timeouts.push(
|
||||
setTimeout(() => delete this.deleted[channelID + messageID],
|
||||
this.client.options.rest_ws_bridge_timeout)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MessageDeleteAction;
|
||||
|
||||
@@ -1,44 +1,36 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Constants = require('../../util/Constants');
|
||||
const CloneObject = require('../../util/CloneObject');
|
||||
const Message = require('../../structures/Message');
|
||||
const cloneObject = require('../../util/CloneObject');
|
||||
|
||||
class MessageUpdateAction extends Action {
|
||||
|
||||
constructor(client) {
|
||||
super(client);
|
||||
}
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const channel = client.store.get('channels', data.channel_id);
|
||||
|
||||
handle(data) {
|
||||
if (channel) {
|
||||
const message = channel.store.get('messages', data.id);
|
||||
if (message && !message.equals(data, true)) {
|
||||
const oldMessage = cloneObject(message);
|
||||
message.patch(data);
|
||||
client.emit(Constants.Events.MESSAGE_UPDATE, oldMessage, message);
|
||||
return {
|
||||
old: oldMessage,
|
||||
updated: message,
|
||||
};
|
||||
}
|
||||
|
||||
let client = this.client;
|
||||
let channel = client.store.get('channels', data.channel_id);
|
||||
return {
|
||||
old: message,
|
||||
updated: message,
|
||||
};
|
||||
}
|
||||
|
||||
if (channel) {
|
||||
let message = channel.store.get('messages', data.id);
|
||||
if (message && !message.equals(data, true)) {
|
||||
let oldMessage = CloneObject(message);
|
||||
message.patch(data);
|
||||
return {
|
||||
old: oldMessage,
|
||||
updated: message,
|
||||
};
|
||||
client.emit(Constants.Events.MESSAGE_UPDATE, oldMessage, message);
|
||||
}
|
||||
|
||||
return {
|
||||
old: message,
|
||||
updated: message,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
old: null,
|
||||
updated: null,
|
||||
};
|
||||
}
|
||||
};
|
||||
return {
|
||||
old: null,
|
||||
updated: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MessageUpdateAction;
|
||||
|
||||
@@ -1,44 +1,36 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Constants = require('../../util/Constants');
|
||||
const CloneObject = require('../../util/CloneObject');
|
||||
const Message = require('../../structures/Message');
|
||||
const cloneObject = require('../../util/CloneObject');
|
||||
|
||||
class UserUpdateAction extends Action {
|
||||
|
||||
constructor(client) {
|
||||
super(client);
|
||||
}
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
|
||||
handle(data) {
|
||||
if (client.store.user) {
|
||||
if (client.store.user.equals(data)) {
|
||||
return {
|
||||
old: client.store.user,
|
||||
updated: client.store.user,
|
||||
};
|
||||
}
|
||||
|
||||
let client = this.client;
|
||||
const oldUser = cloneObject(client.store.user);
|
||||
client.store.user.setup(data);
|
||||
|
||||
if (client.store.user) {
|
||||
if (client.store.user.equals(data)) {
|
||||
return {
|
||||
old: client.store.user,
|
||||
updated: client.store.user,
|
||||
};
|
||||
}
|
||||
client.emit(Constants.Events.USER_UPDATE, oldUser, client.store.user);
|
||||
|
||||
let oldUser = CloneObject(client.store.user);
|
||||
client.store.user.setup(data);
|
||||
return {
|
||||
old: oldUser,
|
||||
updated: client.store.user,
|
||||
};
|
||||
}
|
||||
|
||||
client.emit(Constants.Events.USER_UPDATE, oldUser, client.store.user);
|
||||
|
||||
return {
|
||||
old: oldUser,
|
||||
updated: client.store.user,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
old: null,
|
||||
updated: null,
|
||||
};
|
||||
}
|
||||
};
|
||||
return {
|
||||
old: null,
|
||||
updated: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = UserUpdateAction;
|
||||
|
||||
Reference in New Issue
Block a user