Fixed start PM

This commit is contained in:
hydrabolt
2015-10-31 23:46:46 +00:00
parent 6d6dcf533a
commit 3c16a9f2a4
8 changed files with 35 additions and 71 deletions

View File

@@ -129,6 +129,9 @@ class InternalClient {
request
.post(`${Endpoints.USER_CHANNELS(user.id) }`)
.set("authorization", self.token)
.send({
recipient_id: user.id
})
.end((err, res) => {
if (err) {
reject(new Error(err.response.text));
@@ -169,7 +172,7 @@ class InternalClient {
self.resolver.resolveChannel(where)
.then(next)
.catch(e => reject(new Error("Error resolving destination")));
.catch(e => reject(new Error("Error resolving destination - "+e)));
function next(destination) {
//var destination;

View File

@@ -10,8 +10,8 @@ var User = require("../../Structures/User.js"),
Message = require("../../Structures/Message.js");
class Resolver {
constructor(client) {
this.client = client;
constructor(internal) {
this.internal = internal;
}
resolveMentions(resource) {
@@ -41,7 +41,9 @@ class Resolver {
accepts a Message, Channel, Server, String ID, User, PMChannel
*/
var found = null;
if (resource instanceof Message) {
if( resource instanceof User ){
found = resource;
}else if (resource instanceof Message) {
found = resource.author;
} else if (resource instanceof TextChannel) {
var lmsg = resource.lastMessage;
@@ -87,11 +89,11 @@ class Resolver {
} else if (resource instanceof Server) {
found = resource.channels.get("id", resource.id);
} else if (resource instanceof String || typeof resource === "string") {
found = self.client.internal.channels.get("id", resource);
found = self.internal.channels.get("id", resource);
} else if (resource instanceof User) {
// see if a PM exists
var chatFound = false;
for (var pmchat of self.client.internal.private_channels) {
for (var pmchat of self.internal.private_channels) {
if (pmchat.recipient.equals(resource)) {
chatFound = pmchat;
break;
@@ -102,7 +104,7 @@ class Resolver {
found = chatFound;
} else {
// PM does not exist :\
self.client.internal.startPM(resource)
self.internal.startPM(resource)
.then(pmchannel => resolve(pmchannel))
.catch(e => reject(e));
return;

View File

@@ -1,7 +1,9 @@
"use strict";
var Channel = require("./Channel.js");
var User = require("./User.js");
var Equality = require("../Util/Equality.js");
var Cache = require("../Util/Cache.js");
class PMChannel extends Equality{
constructor(data, client){
@@ -11,7 +13,8 @@ class PMChannel extends Equality{
this.type = data.type || "text";
this.id = data.id;
this.lastMessageId = data.last_message_id;
this.recipient = this.client.internal.users.add(data.recipient);
this.messages = new Cache("id", 1000);
this.recipient = this.client.internal.users.add(new User(data.recipient, this.client));
}
/* warning! may return null */

View File

@@ -7,12 +7,7 @@ a.on("debug", (m) => console.log("[debug]",m));
a.on("message", m => {
if(m.content === "$$$")
a.reply(m, "hi man!")
.then( m => {
a.updateMessage(m, "!!!").then( m => {
a.updateMessage(m, "the old content was " + m.content);
});
});
a.sendMessage(m.author, "hi!").catch(e => console.log(e));
});
a.login(process.env["discordEmail"], process.env["discordPass"]).catch((e)=>console.log(e));