Skip to content
This repository has been archived by the owner on Mar 25, 2020. It is now read-only.

View Channel Permission for VOICE CHANNELS #267

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ A small, single-file, fully featured [Discordapp](https://discordapp.com) librar

[![Discord](https://discordapp.com/api/guilds/66192955777486848/widget.png)](https://discord.gg/0MvHMfHcTKVVmIGP) [![NPM](https://img.shields.io/npm/v/discord.io.svg)](https://img.shields.io/npm/v/gh-badges.svg)

**You are probably here for the gateway_v6 branch. (https://github.com/Woor/discord.io/tree/gateway_v6) **

### Requirements
**Required**:
* **Node.js 0.10.x** or greater
Expand Down
65 changes: 59 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,22 @@ DCP.sendMessage = function(input, callback) {
message.tts = (input.tts === true);
message.nonce = input.nonce || message.nonce;

if (input.typing === true) {
if (typeof input.typing === "boolean" && input.typing === true) {
return simulateTyping(
this,
input.to,
message,
( (message.content.length * 0.12) * 1000 ),
callback
);
} else if (typeof input.typing === "number") {
return simulateTyping(
this,
input.to,
message,
input.typing,
callback
);
}

sendMessage(this, input.to, message, callback);
Expand Down Expand Up @@ -920,7 +928,7 @@ DCP.createChannel = function(input, callback) {
DCP.createDMChannel = function(userID, callback) {
var client = this;
this._req('post', Endpoints.USER(client.id) + "/channels", {recipient_id: userID}, function(err, res) {
if (!err && goodResponse(res)) client._uIDToDM[res.body.recipient.id] = res.body.id;
if (!err && goodResponse(res)) client._uIDToDM[res.body.recipient_id] = res.body.id;
handleResCB("Unable to create DM Channel", err, res, callback);
});
};
Expand Down Expand Up @@ -1000,8 +1008,8 @@ DCP.editChannelPermissions = function(input, callback) { //Will shrink this up l
channel = this.channels[ input.channelID ];
permissions = channel.permissions[pType][ID] || { allow: 0, deny: 0 };
allowed_values = [0, 4, 28].concat((channel.type === 'text' ?
[10, 11, 12, 13, 14, 15, 16, 17, 18] :
[20, 21, 22, 23, 24, 25] ));
[6, 10, 11, 12, 13, 14, 15, 16, 17, 18] :
[20, 21, 22, 23, 24, 25, 29] ));

//Take care of allow first
if (type(input.allow) === 'array') {
Expand Down Expand Up @@ -1129,7 +1137,52 @@ DCP.editRole = function(input, callback) {
});
} catch(e) {return handleErrCB(('[editRole] ' + e), callback);}
};

/**
* Move a role up or down relative to it's current position.
* @arg {Object} input
* @arg {Snowflake} input.serverID
* @arg {Snowflake} input.roleID - The ID of the role.
* @arg {Number} input.position - A relative number to move the role up or down.
*/
DCP.moveRole = function(input,callback){
if(input.position===0)return handleErrCB("Desired role position is same as current", callback); //Don't do anything if they dont want it to move

try {
var role = new Role(this.servers[input.serverID].roles[input.roleID]);
var curPos = role.position;
var newPos = curPos + input.position;

if(newPos < 1)
newPos = 1; //make sure it doesn't go under the possible positions

if(newPos > Object.keys(this.servers[input.serverID].roles).length-1)
newPos = Object.keys(this.servers[input.serverID].roles).length-1; //make sure it doesn't go above the possible positions

var currentOrder = [];
for(var roleID in this.servers[input.serverID].roles){
if(roleID == input.serverID) continue; //the everyone role cannot be changed, so best to not try.
var _role = new Role(this.servers[input.serverID].roles[roleID]);
currentOrder[_role.position] = roleID;
}
var payload = [];


for(var pos in currentOrder){
var roleID = currentOrder[pos];
if(newPos>curPos && curPos < pos && pos <= newPos)
payload.push({id:roleID, position:pos-1});
if(curPos>newPos && curPos > pos && pos >= newPos)
payload.push({id:roleID, position:(pos-(-1))});
}
payload.push({id:input.roleID,position:newPos});

this._req('patch', Endpoints.ROLES(input.serverID), payload, function(err, res) {
handleResCB("Unable to move role", err, res, callback);
});
} catch(e) {return handleErrCB(e, callback);}
};

/**
* Delete a role.
* @arg {Object} input
Expand Down Expand Up @@ -1465,7 +1518,7 @@ function APIRequest(method, url) {
});
});
});
if (type(data) === 'object' || method.toLowerCase() === 'get') req.setHeader("Content-Type", "application/json; charset=utf-8");
if (typeof(data) == 'object' || method.toLowerCase() === 'get') req.setHeader("Content-Type", "application/json; charset=utf-8");
if (data instanceof Multipart) req.setHeader("Content-Type", "multipart/form-data; boundary=" + data.boundary);
if (data) req.write( data.result || JSON.stringify(data), data.result ? 'binary' : 'utf-8' );
req.end();
Expand All @@ -1486,7 +1539,7 @@ function APIRequest(method, url) {
callback(null, req);
}
};
if (type(data) === 'object' || method.toLowerCase() === 'get') req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
if (typeof(data) == 'object' || method.toLowerCase() === 'get') req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
if (data instanceof Multipart) req.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + data.boundary);
if (data) return req.send( data.result ? data.result : JSON.stringify(data) );
req.send(null);
Expand Down
49 changes: 45 additions & 4 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ declare interface permissions {
GENERAL_MANAGE_ROLES?: boolean;
GENERAL_MANAGE_NICKNAMES?: boolean;
GENERAL_CHANGE_NICKNAME?: boolean;
GENERAL_MANAGE_WEBHOOKS?: boolean;

TEXT_ADD_REACTIONS?: boolean;
TEXT_READ_MESSAGES?: boolean;
TEXT_SEND_MESSAGES?: boolean;
TEXT_SEND_TTS_MESSAGE?: boolean;
Expand All @@ -120,10 +122,36 @@ declare interface permissions {
*/
declare type sendMessageOpts = {
to: string,
message: string,
message?: string,
tts?: boolean,
nonce?: string,
typing?: boolean
typing?: boolean,
embed?: embedMessageOpts
}

declare type embedMessageOpts = {
author?: {
icon_url?: string,
name: string,
url?: string
},
color?: number,
description?: string,
fields?: [{
name: string,
value?: string,
inline?: boolean
}],
thumbnail?: {
url: string
},
title: string,
timestamp?: Date
url?: string,
footer?: {
icon_url?: string,
text: string
}
}

declare type uploadFileOpts = {
Expand Down Expand Up @@ -325,6 +353,12 @@ declare type getMembersOpts = {
after: string
}

declare type reactionOpts = {
channelID: string,
messageID: string,
reaction: string
}

/**
* CLASSES
*/
Expand Down Expand Up @@ -373,11 +407,18 @@ declare namespace Discord {
}

export class DMChannel extends Resource {
recipient: Object;
recipient: DMRecipient;
last_message_id: string;
id: string;
}

export class DMRecipient extends Resource {
username: string;
id: string;
discriminator: string;
avatar: string;
}

export class User extends Resource {
username: string;
id: string;
Expand Down Expand Up @@ -506,7 +547,7 @@ declare namespace Discord {
pinMessage(options: pinMessageOpts, callback?: callbackFunc): void
deletePinnedMessage(options: deletePinnedMessageOpts, callback?: callbackFunc): void
getPinnedMessages(options: getPinnedMessagesOpts, callback?: callbackFunc): void

addReaction(options: reactionOpts, callback?: callbackFunc): void
/**
* VOICE CHANNELS
*/
Expand Down