mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
add channel.sendMessage and channel.sendTTSMessage
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const Channel = require('./Channel');
|
||||
const TextBasedChannel = require('./interface/TextBasedChannel');
|
||||
const User = require('./User');
|
||||
const TextChannelDataStore = require('./datastore/TextChannelDataStore');
|
||||
|
||||
@@ -26,6 +27,7 @@ class DMChannel extends Channel{
|
||||
}
|
||||
|
||||
setup(data) {
|
||||
super.setup(data);
|
||||
this.recipient = this.client.store.add('users', new User(this.client, data.recipient));
|
||||
this.lastMessageID = data.last_message_id;
|
||||
}
|
||||
@@ -35,4 +37,6 @@ class DMChannel extends Channel{
|
||||
}
|
||||
}
|
||||
|
||||
TextBasedChannel.applyToClass(DMChannel);
|
||||
|
||||
module.exports = DMChannel;
|
||||
|
||||
@@ -1,16 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
class Message {
|
||||
constructor(serverChannel, data) {
|
||||
this.channel = serverChannel;
|
||||
this.guild = serverChannel.guild;
|
||||
constructor(channel, data, client) {
|
||||
this.channel = channel;
|
||||
|
||||
if (channel.guild) {
|
||||
this.guild = channel.guild;
|
||||
}
|
||||
|
||||
this.client = client;
|
||||
if (data) {
|
||||
this.setup(data);
|
||||
}
|
||||
}
|
||||
|
||||
setup(data) {
|
||||
this.author = this.guild.client.store.NewUser(data.author);
|
||||
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;
|
||||
@@ -22,11 +27,11 @@ class Message {
|
||||
this.mentions = [];
|
||||
this.id = data.id;
|
||||
for (let mention of data.mentions) {
|
||||
let user = this.guild.client.store.get('users', mention.id);
|
||||
let user = this.client.store.get('users', mention.id);
|
||||
if (user) {
|
||||
this.mentions.push(user);
|
||||
} else {
|
||||
user = this.guild.client.store.NewUser(mention);
|
||||
user = this.client.store.NewUser(mention);
|
||||
this.mentions.push(user);
|
||||
}
|
||||
}
|
||||
@@ -34,7 +39,7 @@ class Message {
|
||||
|
||||
patch(data) {
|
||||
if (data.author)
|
||||
this.author = this.guild.client.store.get('users', data.author.id);
|
||||
this.author = this.client.store.get('users', data.author.id);
|
||||
if (data.content)
|
||||
this.content = data.content;
|
||||
if (data.timestamp)
|
||||
@@ -53,11 +58,11 @@ class Message {
|
||||
this.attachments = data.attachments;
|
||||
if (data.mentions) {
|
||||
for (let mention of data.mentions) {
|
||||
let user = this.guild.client.store.get('users', mention.id);
|
||||
let user = this.client.store.get('users', mention.id);
|
||||
if (user) {
|
||||
this.mentions.push(user);
|
||||
} else {
|
||||
user = this.guild.client.store.NewUser(mention);
|
||||
user = this.client.store.NewUser(mention);
|
||||
this.mentions.push(user);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
const ServerChannel = require('./ServerChannel');
|
||||
const TextChannelDataStore = require('./datastore/TextChannelDataStore');
|
||||
const TextBasedChannel = require('./interface/TextBasedChannel');
|
||||
|
||||
class TextChannel extends ServerChannel {
|
||||
|
||||
@@ -26,4 +27,6 @@ class TextChannel extends ServerChannel {
|
||||
}
|
||||
}
|
||||
|
||||
TextBasedChannel.applyToClass(TextChannel);
|
||||
|
||||
module.exports = TextChannel;
|
||||
|
||||
20
src/structures/interface/TextBasedChannel.js
Normal file
20
src/structures/interface/TextBasedChannel.js
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
function sendMessage(content, options) {
|
||||
options = 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);
|
||||
}
|
||||
|
||||
exports.applyToClass = structure => {
|
||||
if (structure.name !== 'TextChannel' && structure.name !== 'DMChannel') {
|
||||
throw new Error(structure + ' cannot implement TextBasedChannel');
|
||||
}
|
||||
|
||||
structure.prototype.sendMessage = sendMessage;
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user