mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 04:53:30 +01:00
Add GroupDMChannel support
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -6,6 +6,7 @@ const DMChannel = require('../structures/DMChannel');
|
|||||||
const TextChannel = require('../structures/TextChannel');
|
const TextChannel = require('../structures/TextChannel');
|
||||||
const VoiceChannel = require('../structures/VoiceChannel');
|
const VoiceChannel = require('../structures/VoiceChannel');
|
||||||
const GuildChannel = require('../structures/GuildChannel');
|
const GuildChannel = require('../structures/GuildChannel');
|
||||||
|
const GroupDMChannel = require('../structures/GroupDMChannel');
|
||||||
|
|
||||||
class ClientDataManager {
|
class ClientDataManager {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
@@ -48,6 +49,8 @@ class ClientDataManager {
|
|||||||
let channel;
|
let channel;
|
||||||
if (data.type === Constants.ChannelTypes.DM) {
|
if (data.type === Constants.ChannelTypes.DM) {
|
||||||
channel = new DMChannel(this.client, data);
|
channel = new DMChannel(this.client, data);
|
||||||
|
} else if (data.type === Constants.ChannelTypes.groupDM) {
|
||||||
|
channel = new GroupDMChannel(this.client, data);
|
||||||
} else {
|
} else {
|
||||||
guild = guild || this.client.guilds.get(data.guild_id);
|
guild = guild || this.client.guilds.get(data.guild_id);
|
||||||
if (guild) {
|
if (guild) {
|
||||||
|
|||||||
133
src/structures/GroupDMChannel.js
Normal file
133
src/structures/GroupDMChannel.js
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
const Channel = require('./Channel');
|
||||||
|
const TextBasedChannel = require('./interface/TextBasedChannel');
|
||||||
|
const Collection = require('../util/Collection');
|
||||||
|
|
||||||
|
/*
|
||||||
|
{ type: 3,
|
||||||
|
recipients:
|
||||||
|
[ { username: 'Charlie',
|
||||||
|
id: '123',
|
||||||
|
discriminator: '6631',
|
||||||
|
avatar: '123' },
|
||||||
|
{ username: 'Ben',
|
||||||
|
id: '123',
|
||||||
|
discriminator: '2055',
|
||||||
|
avatar: '123' },
|
||||||
|
{ username: 'Adam',
|
||||||
|
id: '123',
|
||||||
|
discriminator: '2406',
|
||||||
|
avatar: '123' } ],
|
||||||
|
owner_id: '123',
|
||||||
|
name: null,
|
||||||
|
last_message_id: '123',
|
||||||
|
id: '123',
|
||||||
|
icon: null }
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
function arraysEqual(a, b) {
|
||||||
|
if (a === b) return true;
|
||||||
|
if (a.length !== b.length) return false;
|
||||||
|
|
||||||
|
for (const itemInd in a) {
|
||||||
|
const item = a[itemInd];
|
||||||
|
const ind = b.indexOf(item);
|
||||||
|
if (ind) {
|
||||||
|
b.splice(ind, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return b.length === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a Group DM on Discord
|
||||||
|
* @extends {Channel}
|
||||||
|
* @implements {TextBasedChannel}
|
||||||
|
*/
|
||||||
|
class GroupDMChannel extends Channel {
|
||||||
|
|
||||||
|
constructor(client, data) {
|
||||||
|
super(client, data);
|
||||||
|
|
||||||
|
this.messages = new Collection();
|
||||||
|
}
|
||||||
|
|
||||||
|
equals(other) {
|
||||||
|
const base = (
|
||||||
|
this.id === other.id &&
|
||||||
|
this.name === other.name &&
|
||||||
|
this.icon === other.icon &&
|
||||||
|
this.owner.id === other.owner_id
|
||||||
|
);
|
||||||
|
|
||||||
|
if (base) {
|
||||||
|
const thisIDs = this.recipients.array().map(r => r.id);
|
||||||
|
const otherIDs = other.recipients.map(r => r.id);
|
||||||
|
return arraysEqual(thisIDs, otherIDs);
|
||||||
|
}
|
||||||
|
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
|
||||||
|
setup(data) {
|
||||||
|
super.setup(data);
|
||||||
|
|
||||||
|
if (!this.recipients) {
|
||||||
|
/**
|
||||||
|
* A collection of the recipients of this DM, mapped by their ID.
|
||||||
|
* @type {Collection<String, User>}
|
||||||
|
*/
|
||||||
|
this.recipients = new Collection();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.recipients) {
|
||||||
|
for (const recipient of data.recipients) {
|
||||||
|
const user = this.client.dataManager.newUser(recipient);
|
||||||
|
this.recipients.set(user.id, user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* The name of this Group DM, can be null if one isn't set.
|
||||||
|
* @type {String}
|
||||||
|
*/
|
||||||
|
this.name = data.name;
|
||||||
|
/**
|
||||||
|
* The ID of this Group DM Channel.
|
||||||
|
* @type {String}
|
||||||
|
*/
|
||||||
|
this.id = data.id;
|
||||||
|
/**
|
||||||
|
* A hash of the Group DM icon.
|
||||||
|
* @type {String}
|
||||||
|
*/
|
||||||
|
this.icon = data.icon;
|
||||||
|
/**
|
||||||
|
* The ID of the last message in the channel, if one was sent.
|
||||||
|
* @type {?String}
|
||||||
|
*/
|
||||||
|
this.lastMessageID = data.last_message_id;
|
||||||
|
/**
|
||||||
|
* The owner of this Group DM.
|
||||||
|
* @type {User}
|
||||||
|
*/
|
||||||
|
this.owner = this.client.users.get(data.owner_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
sendMessage() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sendTTSMessage() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_cacheMessage() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TextBasedChannel.applyToClass(GroupDMChannel, true);
|
||||||
|
|
||||||
|
module.exports = GroupDMChannel;
|
||||||
@@ -249,7 +249,7 @@ class Message {
|
|||||||
* Reply to a message
|
* Reply to a message
|
||||||
* @param {String} content the content of the message
|
* @param {String} content the content of the message
|
||||||
* @param {MessageOptions} [options = {}] the options to provide
|
* @param {MessageOptions} [options = {}] the options to provide
|
||||||
* @returns {Promise<Message>}
|
* @returns {Promise<Message, Error>}
|
||||||
* @example
|
* @example
|
||||||
* // reply to a message
|
* // reply to a message
|
||||||
* message.reply('Hey, I'm a reply!')
|
* message.reply('Hey, I'm a reply!')
|
||||||
@@ -257,7 +257,8 @@ class Message {
|
|||||||
* .catch(console.log);
|
* .catch(console.log);
|
||||||
*/
|
*/
|
||||||
reply(content, options = {}) {
|
reply(content, options = {}) {
|
||||||
return this.client.rest.methods.sendMessage(this.channel, this.guild ? `${this.author}, ${content}` : content, options.tts);
|
const newContent = this.guild ? `${this.author}, ${content}` : content;
|
||||||
|
return this.client.rest.methods.sendMessage(this.channel, newContent, options.tts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user