Add ChannelPinsUpdate event

This commit is contained in:
Amish Shah
2016-08-28 18:50:50 +01:00
parent 309bc5da1f
commit a91fcd5cab
5 changed files with 42 additions and 19 deletions

File diff suppressed because one or more lines are too long

View File

@@ -38,6 +38,7 @@ class WebSocketPacketManager {
this.register(Constants.WSEvents.MESSAGE_UPDATE, 'MessageUpdate');
this.register(Constants.WSEvents.VOICE_SERVER_UPDATE, 'VoiceServerUpdate');
this.register(Constants.WSEvents.MESSAGE_DELETE_BULK, 'MessageDeleteBulk');
this.register(Constants.WSEvents.CHANNEL_PINS_UPDATE, 'ChannelPinsUpdate');
}
get client() {

View File

@@ -0,0 +1,38 @@
const AbstractHandler = require('./AbstractHandler');
const Constants = require('../../../../util/Constants');
/*
{ t: 'CHANNEL_PINS_UPDATE',
s: 666,
op: 0,
d:
{ last_pin_timestamp: '2016-08-28T17:37:13.171774+00:00',
channel_id: '314866471639044027' } }
*/
class ChannelPinsUpdate extends AbstractHandler {
handle(packet) {
const data = packet.d;
const client = this.packetManager.client;
const channel = client.channels.get(data.channel_id);
const time = new Date(data.last_pin_timestamp);
if (channel && time) {
return client.emit(Constants.Events.CHANNEL_PINS_UPDATE, channel, time);
}
}
}
/**
* Emitted whenever the pins of a Channel are updated. Due to the nature of the WebSocket event, not much information
* can be provided easily here - you need to manually check the pins yourself.
*
* @event Client#channelPinsUpdate
* @param {Channel} channel The channel that the pins update occured in
* @param {Date} time the time of the pins update
*/
module.exports = ChannelPinsUpdate;

View File

@@ -165,6 +165,7 @@ exports.Events = {
RECONNECTING: 'reconnecting',
GUILD_MEMBER_SPEAKING: 'guildMemberSpeaking',
MESSAGE_BULK_DELETE: 'messageDeleteBulk',
CHANNEL_PINS_UPDATE: 'channelPinsUpdate',
};
exports.WSEvents = {
@@ -195,6 +196,7 @@ exports.WSEvents = {
FRIEND_REMOVE: 'RELATIONSHIP_REMOVE',
VOICE_SERVER_UPDATE: 'VOICE_SERVER_UPDATE',
MESSAGE_DELETE_BULK: 'MESSAGE_DELETE_BULK',
CHANNEL_PINS_UPDATE: 'CHANNEL_PINS_UPDATE',
};
const PermissionFlags = exports.PermissionFlags = {

View File

@@ -12,10 +12,6 @@ client.on('ready', () => {
console.log('ready!');
});
client.on('messageDeleteBulk', msgs => {
msgs.array().map(m => console.log(m.content));
});
client.on('message', message => {
if (true) {
if (message.content === 'makechann') {
@@ -109,20 +105,6 @@ function chanLoop(channel) {
channel.setName(channel.name + 'a').then(chanLoop).catch(console.log);
}
client.on('messageDelete', message => {
console.log('Message deleted by', message.author.username);
});
client.on('messageUpdate', (old, message) => {
if (message.author.username === 'hydrabolt')
console.log('Message updated from', old.content, 'to', message.content);
});
client.on('guildMemberSpeaking', (member, speaking) => {
const message = speaking ? `${member.user.username} is speaking` : `${member.user.username} is not speaking`;
member.guild.channels.get(member.guild.id).sendMessage(message);
});
client.on('message', msg => {
if (msg.content.startsWith('?raw')) {
msg.channel.sendMessage('```' + msg.content + '```');