mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 20:43:30 +01:00
Basic fixes, added test script
This commit is contained in:
@@ -48,7 +48,27 @@ var InternalClient = (function () {
|
|||||||
this.resolver = new Resolver(this);
|
this.resolver = new Resolver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
//def joinVoiceChannel()
|
//def leaveVoiceChannel
|
||||||
|
|
||||||
|
InternalClient.prototype.leaveVoiceChannel = function leaveVoiceChannel(chann) {
|
||||||
|
var self = this;
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
var channel = self.resolver.resolveVoiceChannel(chann);
|
||||||
|
|
||||||
|
if (channel) {
|
||||||
|
if (self.voiceConnections[channel]) {
|
||||||
|
var chan = self.voiceConnections[channel];
|
||||||
|
chan.stopPlaying();
|
||||||
|
self.voiceConnections.remove(chan);
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
reject(new Error("voice channel does not exist"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
//def joinVoiceChannel
|
||||||
|
|
||||||
InternalClient.prototype.joinVoiceChannel = function joinVoiceChannel(chann) {
|
InternalClient.prototype.joinVoiceChannel = function joinVoiceChannel(chann) {
|
||||||
var self = this;
|
var self = this;
|
||||||
@@ -57,9 +77,7 @@ var InternalClient = (function () {
|
|||||||
var channel = self.resolver.resolveVoiceChannel(chann);
|
var channel = self.resolver.resolveVoiceChannel(chann);
|
||||||
|
|
||||||
if (channel) {
|
if (channel) {
|
||||||
if (!self.voiceConnections[channel]) {
|
if (!self.voiceConnections.get("id", channel.id)) {
|
||||||
|
|
||||||
self.voiceConnections[channel] = {};
|
|
||||||
|
|
||||||
var session,
|
var session,
|
||||||
token,
|
token,
|
||||||
@@ -76,7 +94,7 @@ var InternalClient = (function () {
|
|||||||
token = data.d.token;
|
token = data.d.token;
|
||||||
endpoint = data.d.endpoint;
|
endpoint = data.d.endpoint;
|
||||||
|
|
||||||
var chan = self.voiceConnections[channel] = new VoiceConnection(channel, self.client, session, token, server, endpoint);
|
var chan = self.voiceConnections.add(new VoiceConnection(channel, self.client, session, token, server, endpoint));
|
||||||
|
|
||||||
chan.on("ready", resolve);
|
chan.on("ready", resolve);
|
||||||
chan.on("error", reject);
|
chan.on("error", reject);
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ var VoiceConnection = (function (_EventEmitter) {
|
|||||||
if (!Opus) {
|
if (!Opus) {
|
||||||
console.log("HEY! WATCH OUT\n\n discord.js needs node-opus, you don't have it installed.");
|
console.log("HEY! WATCH OUT\n\n discord.js needs node-opus, you don't have it installed.");
|
||||||
}
|
}
|
||||||
|
this.id = channel.id;
|
||||||
this.voiceChannel = channel;
|
this.voiceChannel = channel;
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.session = session;
|
this.session = session;
|
||||||
@@ -64,13 +65,13 @@ var VoiceConnection = (function (_EventEmitter) {
|
|||||||
if (self.playingIntent) {
|
if (self.playingIntent) {
|
||||||
self.stopPlaying();
|
self.stopPlaying();
|
||||||
}
|
}
|
||||||
|
self.playing = true;
|
||||||
var retStream = new StreamIntent();
|
var retStream = new StreamIntent();
|
||||||
var onWarning = false;
|
var onWarning = false;
|
||||||
self.playingIntent = retStream;
|
self.playingIntent = retStream;
|
||||||
|
|
||||||
function send() {
|
function send() {
|
||||||
if (!self.playingIntent) {
|
if (!self.playingIntent || !self.playing) {
|
||||||
self.setSpeaking(false);
|
self.setSpeaking(false);
|
||||||
retStream.emit("end");
|
retStream.emit("end");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -44,7 +44,26 @@ class InternalClient {
|
|||||||
this.resolver = new Resolver(this);
|
this.resolver = new Resolver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
//def joinVoiceChannel()
|
//def leaveVoiceChannel
|
||||||
|
leaveVoiceChannel(chann){
|
||||||
|
var self = this;
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
var channel = self.resolver.resolveVoiceChannel(chann);
|
||||||
|
|
||||||
|
if(channel){
|
||||||
|
if(self.voiceConnections[channel]){
|
||||||
|
var chan = self.voiceConnections[channel];
|
||||||
|
chan.stopPlaying();
|
||||||
|
self.voiceConnections.remove(chan);
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
reject(new Error("voice channel does not exist"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//def joinVoiceChannel
|
||||||
joinVoiceChannel(chann){
|
joinVoiceChannel(chann){
|
||||||
var self = this;
|
var self = this;
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -52,9 +71,7 @@ class InternalClient {
|
|||||||
var channel = self.resolver.resolveVoiceChannel(chann);
|
var channel = self.resolver.resolveVoiceChannel(chann);
|
||||||
|
|
||||||
if(channel){
|
if(channel){
|
||||||
if(!self.voiceConnections[channel]){
|
if(!self.voiceConnections.get("id", channel.id)){
|
||||||
|
|
||||||
self.voiceConnections[channel] = {};
|
|
||||||
|
|
||||||
var session, token, server = channel.server, endpoint, fired = 0;
|
var session, token, server = channel.server, endpoint, fired = 0;
|
||||||
|
|
||||||
@@ -67,7 +84,7 @@ class InternalClient {
|
|||||||
token = data.d.token;
|
token = data.d.token;
|
||||||
endpoint = data.d.endpoint;
|
endpoint = data.d.endpoint;
|
||||||
|
|
||||||
var chan = self.voiceConnections[channel] = new VoiceConnection(channel, self.client, session, token, server, endpoint);
|
var chan = self.voiceConnections.add(new VoiceConnection(channel, self.client, session, token, server, endpoint));
|
||||||
|
|
||||||
chan.on("ready", resolve);
|
chan.on("ready", resolve);
|
||||||
chan.on("error", reject);
|
chan.on("error", reject);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ class VoiceConnection extends EventEmitter{
|
|||||||
if(!Opus){
|
if(!Opus){
|
||||||
console.log("HEY! WATCH OUT\n\n discord.js needs node-opus, you don't have it installed.");
|
console.log("HEY! WATCH OUT\n\n discord.js needs node-opus, you don't have it installed.");
|
||||||
}
|
}
|
||||||
|
this.id = channel.id;
|
||||||
this.voiceChannel = channel;
|
this.voiceChannel = channel;
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.session = session;
|
this.session = session;
|
||||||
@@ -57,13 +58,13 @@ class VoiceConnection extends EventEmitter{
|
|||||||
if (self.playingIntent) {
|
if (self.playingIntent) {
|
||||||
self.stopPlaying();
|
self.stopPlaying();
|
||||||
}
|
}
|
||||||
|
self.playing = true;
|
||||||
var retStream = new StreamIntent();
|
var retStream = new StreamIntent();
|
||||||
var onWarning = false;
|
var onWarning = false;
|
||||||
self.playingIntent = retStream;
|
self.playingIntent = retStream;
|
||||||
|
|
||||||
function send() {
|
function send() {
|
||||||
if (!self.playingIntent) {
|
if (!self.playingIntent || !self.playing) {
|
||||||
self.setSpeaking(false);
|
self.setSpeaking(false);
|
||||||
retStream.emit("end");
|
retStream.emit("end");
|
||||||
return;
|
return;
|
||||||
|
|||||||
105
test/bot.1.js
105
test/bot.1.js
@@ -1,69 +1,52 @@
|
|||||||
var Discord = require("../");
|
var Discord = require("../");
|
||||||
var Member = require("../lib/Member.js");
|
var client = new Discord.Client();
|
||||||
var mybot = new Discord.Client({
|
client.on("debug", (m) => console.log("[debug]",m));
|
||||||
compress : true,
|
client.on("warn", (m) => console.log("[warn]", m));
|
||||||
catchup : "all"
|
var start = Date.now();
|
||||||
});
|
client.on("message", m => {
|
||||||
var fs = require("fs");
|
if(m.content === "&init"){
|
||||||
var request = require("request").defaults({ encoding: null });
|
for(var channel of m.channel.server.channels){
|
||||||
|
if(channel instanceof Discord.VoiceChannel){
|
||||||
Discord.patchStrings();
|
client.joinVoiceChannel(channel).catch(error)
|
||||||
|
.then(connection => {
|
||||||
var server, channel, message, sentMessage = false;
|
connection.playFile("C:/users/amish/desktop/Developers.mp3");
|
||||||
|
});
|
||||||
mybot.on("message", function (message) {
|
break;
|
||||||
|
}
|
||||||
console.log("Everyone mentioned? " + doned);
|
}
|
||||||
doned++;
|
}
|
||||||
if (message.content.substr(0, 3) !== "$$$") {
|
if(m.content.startsWith("$$$ stop")){
|
||||||
return;
|
for(var channel of m.channel.server.channels){
|
||||||
}
|
if(channel instanceof Discord.VoiceChannel){
|
||||||
|
chan = channel;
|
||||||
// we can go ahead :)
|
break;
|
||||||
|
}
|
||||||
var user;
|
}
|
||||||
if (message.mentions.length > 0) {
|
if(client.internal.voiceConnections.get("id", chan.id)){
|
||||||
user = message.mentions[0];
|
var connection = client.internal.voiceConnections.get("id", chan.id);
|
||||||
} else {
|
connection.stopPlaying();
|
||||||
user = message.sender;
|
}
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
mybot.reply(message, "Hello! It has been " + ((Date.now() - message.timestamp) - this.timeoffset) + "ms since you sent that.");
|
if(m.content.startsWith("$$$")){
|
||||||
});
|
var chan;
|
||||||
|
for(var channel of m.channel.server.channels){
|
||||||
var doned = 0;
|
if(channel instanceof Discord.VoiceChannel){
|
||||||
|
chan = channel;
|
||||||
mybot.once("ready", function () {
|
break;
|
||||||
console.log("im ready");
|
}
|
||||||
|
}
|
||||||
for (var server of mybot.servers) {
|
if(client.internal.voiceConnections.get("id", chan.id)){
|
||||||
if (server.name === "test-server") {
|
var connection = client.internal.voiceConnections.get("id", chan.id);
|
||||||
mybot.leaveServer(server);
|
connection.playFile("C:/users/amish/desktop/Developers.mp3");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
mybot.on("messageUpdate", function(newMessage, oldMessage){
|
function error(e){
|
||||||
mybot.reply(newMessage, JSON.stringify(newMessage.embeds));
|
console.log(e.stack);
|
||||||
})
|
process.exit(0);
|
||||||
|
|
||||||
mybot.on("serverUpdate", function (oldserver, newserver) {
|
|
||||||
console.log("server changed! " + mybot.servers.length);
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
mybot.on("channelUpdate", function (oldChan, newChan) {
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
function dump(msg) {
|
|
||||||
console.log("dump", msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function error(err) {
|
|
||||||
console.log(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
mybot.login(process.env["ds_email"], process.env["ds_password"]).catch(error);
|
client.login(process.env["discordEmail"], process.env["discordPass"]).catch((e)=>console.log(e));
|
||||||
Reference in New Issue
Block a user