mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 18:13:29 +01:00
Added startTyping stopTyping and added serverchannel.mention()
This commit is contained in:
@@ -643,6 +643,42 @@ var Client = (function (_EventEmitter) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//def startTyping
|
||||||
|
|
||||||
|
Client.prototype.startTyping = function startTyping(channel) {
|
||||||
|
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1];
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
|
||||||
|
self.internal.startTyping(channel).then(function () {
|
||||||
|
callback(null);
|
||||||
|
resolve();
|
||||||
|
})["catch"](function (e) {
|
||||||
|
callback(e);
|
||||||
|
reject(e);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
//def stopTyping
|
||||||
|
|
||||||
|
Client.prototype.stopTyping = function stopTyping(channel) {
|
||||||
|
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1];
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
|
||||||
|
self.internal.stopTyping(channel).then(function () {
|
||||||
|
callback(null);
|
||||||
|
resolve();
|
||||||
|
})["catch"](function (e) {
|
||||||
|
callback(e);
|
||||||
|
reject(e);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
//def joinVoiceChannel
|
//def joinVoiceChannel
|
||||||
|
|
||||||
Client.prototype.joinVoiceChannel = function joinVoiceChannel(channel) {
|
Client.prototype.joinVoiceChannel = function joinVoiceChannel(channel) {
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ var InternalClient = (function () {
|
|||||||
this.channels = new Cache();
|
this.channels = new Cache();
|
||||||
this.servers = new Cache();
|
this.servers = new Cache();
|
||||||
this.private_channels = new Cache();
|
this.private_channels = new Cache();
|
||||||
|
this.typingIntervals = [];
|
||||||
this.voiceConnection = null;
|
this.voiceConnection = null;
|
||||||
this.resolver = new Resolver(this);
|
this.resolver = new Resolver(this);
|
||||||
this.readyTime = null;
|
this.readyTime = null;
|
||||||
@@ -934,6 +935,53 @@ var InternalClient = (function () {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//def startTyping
|
||||||
|
|
||||||
|
InternalClient.prototype.startTyping = function startTyping(channel) {
|
||||||
|
var self = this;
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
|
||||||
|
self.resolver.resolveChannel(channel).then(next)["catch"](reject);
|
||||||
|
|
||||||
|
function next(channel) {
|
||||||
|
|
||||||
|
if (self.typingIntervals[channel.id]) {
|
||||||
|
// typing interval already exists, leave it alone
|
||||||
|
reject(new Error("Already typing in that channel"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.sendTyping(channel);
|
||||||
|
|
||||||
|
self.typingIntervals[channel.id] = setInterval(function () {
|
||||||
|
return self.sendTyping(channel);
|
||||||
|
}, 4000);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
//def stopTyping
|
||||||
|
|
||||||
|
InternalClient.prototype.stopTyping = function stopTyping(channel) {
|
||||||
|
var self = this;
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
|
||||||
|
self.resolver.resolveChannel(channel).then(next)["catch"](reject);
|
||||||
|
|
||||||
|
function next(channel) {
|
||||||
|
|
||||||
|
if (!self.typingIntervals[channel.id]) {
|
||||||
|
// typing interval doesn't exist
|
||||||
|
reject(new Error("Not typing in that channel"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
clearInterval(self.typingIntervals[channel.id]);
|
||||||
|
self.typingIntervals[channel.id] = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
//def setTopic
|
//def setTopic
|
||||||
|
|
||||||
InternalClient.prototype.setTopic = function setTopic(chann) {
|
InternalClient.prototype.setTopic = function setTopic(chann) {
|
||||||
|
|||||||
@@ -99,10 +99,14 @@ var ServerChannel = (function (_Channel) {
|
|||||||
return this.permissionsOf(user);
|
return this.permissionsOf(user);
|
||||||
};
|
};
|
||||||
|
|
||||||
ServerChannel.prototype.toString = function toString() {
|
ServerChannel.prototype.mention = function mention() {
|
||||||
return "<#" + this.id + ">";
|
return "<#" + this.id + ">";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ServerChannel.prototype.toString = function toString() {
|
||||||
|
return this.mention();
|
||||||
|
};
|
||||||
|
|
||||||
ServerChannel.prototype.setName = function setName() {
|
ServerChannel.prototype.setName = function setName() {
|
||||||
return this.client.setChannelName.apply(this.client, reg(this, arguments));
|
return this.client.setChannelName.apply(this.client, reg(this, arguments));
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -641,6 +641,42 @@ class Client extends EventEmitter {
|
|||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//def startTyping
|
||||||
|
startTyping(channel, callback = function (err) { }) {
|
||||||
|
var self = this;
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
|
self.internal.startTyping(channel)
|
||||||
|
.then(() => {
|
||||||
|
callback(null);
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
.catch(e => {
|
||||||
|
callback(e);
|
||||||
|
reject(e);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//def stopTyping
|
||||||
|
stopTyping(channel, callback = function (err) { }) {
|
||||||
|
var self = this;
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
|
self.internal.stopTyping(channel)
|
||||||
|
.then(() => {
|
||||||
|
callback(null);
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
.catch(e => {
|
||||||
|
callback(e);
|
||||||
|
reject(e);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//def joinVoiceChannel
|
//def joinVoiceChannel
|
||||||
joinVoiceChannel(channel, callback=function(err){}){
|
joinVoiceChannel(channel, callback=function(err){}){
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ class InternalClient {
|
|||||||
this.channels = new Cache();
|
this.channels = new Cache();
|
||||||
this.servers = new Cache();
|
this.servers = new Cache();
|
||||||
this.private_channels = new Cache();
|
this.private_channels = new Cache();
|
||||||
|
this.typingIntervals = [];
|
||||||
this.voiceConnection = null;
|
this.voiceConnection = null;
|
||||||
this.resolver = new Resolver(this);
|
this.resolver = new Resolver(this);
|
||||||
this.readyTime = null;
|
this.readyTime = null;
|
||||||
@@ -997,6 +998,55 @@ class InternalClient {
|
|||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//def startTyping
|
||||||
|
startTyping(channel){
|
||||||
|
var self = this;
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
|
self.resolver.resolveChannel(channel).then(next).catch(reject);
|
||||||
|
|
||||||
|
function next(channel) {
|
||||||
|
|
||||||
|
if(self.typingIntervals[channel.id]){
|
||||||
|
// typing interval already exists, leave it alone
|
||||||
|
reject(new Error("Already typing in that channel"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.sendTyping(channel);
|
||||||
|
|
||||||
|
self.typingIntervals[channel.id] = setInterval(
|
||||||
|
() => self.sendTyping(channel), 4000
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//def stopTyping
|
||||||
|
stopTyping(channel){
|
||||||
|
var self = this;
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
|
self.resolver.resolveChannel(channel).then(next).catch(reject);
|
||||||
|
|
||||||
|
function next(channel) {
|
||||||
|
|
||||||
|
if(!self.typingIntervals[channel.id]){
|
||||||
|
// typing interval doesn't exist
|
||||||
|
reject(new Error("Not typing in that channel"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
clearInterval(self.typingIntervals[channel.id]);
|
||||||
|
self.typingIntervals[channel.id] = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//def setTopic
|
//def setTopic
|
||||||
setTopic(chann, topic = "") {
|
setTopic(chann, topic = "") {
|
||||||
|
|||||||
@@ -60,9 +60,13 @@ class ServerChannel extends Channel{
|
|||||||
permsOf(user){
|
permsOf(user){
|
||||||
return this.permissionsOf(user);
|
return this.permissionsOf(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mention(){
|
||||||
|
return `<#${this.id}>`;
|
||||||
|
}
|
||||||
|
|
||||||
toString(){
|
toString(){
|
||||||
return `<#${this.id}>`;
|
return this.mention();
|
||||||
}
|
}
|
||||||
|
|
||||||
setName(){
|
setName(){
|
||||||
|
|||||||
@@ -6,62 +6,13 @@ client.on("warn", (m) => console.log("[warn]", m));
|
|||||||
var start = Date.now();
|
var start = Date.now();
|
||||||
|
|
||||||
client.on("message", m => {
|
client.on("message", m => {
|
||||||
if(m.content === "death"){
|
|
||||||
m.channel.delete();
|
|
||||||
}
|
|
||||||
if (m.content.startsWith("join: ")) {
|
|
||||||
var invite = m.content.split(" ")[1];
|
|
||||||
client.joinServer(invite).then(console.log).catch(console.log);
|
|
||||||
}
|
|
||||||
if (m.content === "&init") {
|
|
||||||
for (var channel of m.channel.server.channels) {
|
|
||||||
if (channel instanceof Discord.VoiceChannel) {
|
|
||||||
client.reply(m, channel.name + " - " + channel.id);
|
|
||||||
client.joinVoiceChannel(channel).catch(error);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (m.content.startsWith("$$$ stop")) {
|
|
||||||
if (client.internal.voiceConnection) {
|
|
||||||
client.internal.voiceConnection.stopPlaying();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}if (m.content.startsWith("$$$ leave")) {
|
|
||||||
client.internal.leaveVoiceChannel();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (m.content.startsWith("$$$")) {
|
|
||||||
var chan;
|
|
||||||
var rest = m.content.split(" ");
|
|
||||||
rest.splice(0, 1);
|
|
||||||
rest = rest.join(" ");
|
|
||||||
if (client.internal.voiceConnection) {
|
|
||||||
client.reply(m, "ok, I'll play that for you");
|
|
||||||
var connection = client.internal.voiceConnection;
|
|
||||||
connection.playFile("C:/users/amish/desktop/" + rest);
|
|
||||||
}
|
|
||||||
} if (m.content.startsWith("pipeit")) {
|
|
||||||
var chan;
|
|
||||||
var rest = m.content.split(" ");
|
|
||||||
rest.splice(0, 1);
|
|
||||||
rest = rest.join(" ");
|
|
||||||
|
|
||||||
if (client.internal.voiceConnection) {
|
if (m.content === "$$") {
|
||||||
var connection = client.internal.voiceConnection;
|
client.startTyping(m.channel);
|
||||||
var request = require("request");
|
} else if (m.content === "!!") {
|
||||||
connection.playRawStream(request(rest)).then(intent => {
|
client.stopTyping(m.channel);
|
||||||
client.reply(m, "playing!").then((msg) => {
|
|
||||||
|
|
||||||
intent.on("end", () => {
|
|
||||||
client.updateMessage(msg, "that song has finished now.");
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function error(e) {
|
function error(e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user