Skip to content

Commit

Permalink
2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnek committed Dec 8, 2016
1 parent 6e4404a commit 8150e71
Show file tree
Hide file tree
Showing 8 changed files with 6,336 additions and 5 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ const client = new RPCClient({
OAUTH2_CLIENT_ID: 'xyzxyzxyz'
});

client.evts.on('READY', () => {
client.on('ready', () => {
console.log('Authenticated!');
console.log('User:' `${client.user.username}#${client.user.discriminator}`, client.user.id)
console.log('Application:', client.application.name, client.application.id);
client.request('GET_CHANNELS', {}, (err, data) => {
// data.channels is an array of channels :)
client.getChannels().then(res => {
// res is an array of channels :)
});

client.selectVoiceChannel('1234567890').then(channel => {
console.log('the voice channel was set to', channel.id);
})

// if you are so lucky as to have the rpc.api scope, you can have a little fun
client.rest.sendMessage('some channel id', 'hello, how are you?');
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "discord-rpc",
"version": "1.1.5",
"version": "2.0.0",
"description": "A simple RPC client for Discord somewhat stolen from the Discord StreamKit.",
"main": "src/index.js",
"repository": {
Expand Down
111 changes: 111 additions & 0 deletions src/Client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
const RPCClient = require('./RPCClient');
const EventEmitter = require('events').EventEmitter;

class Client extends EventEmitter {
constructor ({ OAUTH2_CLIENT_ID } = {}) {
super();
this.rpc = new RPCClient({ OAUTH2_CLIENT_ID });
this.rpc.evts.on('READY', () => {
this.user = this.rpc.user;
this.application = this.rpc.application;
this.emit('ready');
});
this.rpc.evts.on('ERROR', (err) => this.emit('error', err));
this.rest = this.rpc.rest;
}

getGuild (id, timeout) {
return new Promise((resolve, reject) => {
this.rpc.request('GET_GUILD', { guild_id: id, timeout }, (err, res) => {
if (err) reject(err);
resolve(res.data);
});
});
}

getGuilds () {
return new Promise((resolve, reject) => {
this.rpc.request('GET_GUILDS', {}, (err, res) => {
if (err) reject(err);
resolve(res.data.guilds);
});
});
}

getChannel (id, timeout) {
return new Promise((resolve, reject) => {
this.rpc.request('GET_CHANNEL', { channel_id: id, timeout }, (err, res) => {
if (err) reject(err);
resolve(res.data);
});
});
}

getChannels () {
return new Promise((resolve, reject) => {
this.rpc.request('GET_CHANNELS', {}, (err, res) => {
if (err) reject(err);
resolve(res.data.channels);
});
});
}

setUserVoiceSettings (args) {
return new Promise((resolve, reject) => {
this.rpc.request('SET_USER_VOICE_SETTINGS', args, (err, res) => {
if (err) reject(err);
resolve(res.data);
});
});
}

selectVoiceChannel (id, timeout, force = false) {
return new Promise((resolve, reject) => {
this.rpc.request('SELECT_VOICE_CHANNEL', { channel_id: id, timeout, force }, (err, res) => {
if (err) reject(err);
resolve(res.data);
});
});
}

selectTextChannel (id, timeout, force = false) {
return new Promise((resolve, reject) => {
this.rpc.request('SELECT_TEXT_CHANNEL', { channel_id: id, timeout, force }, (err, res) => {
if (err) reject(err);
resolve(res.data);
});
});
}

getVoiceSettings () {
return new Promise((resolve, reject) => {
this.rpc.request('GET_VOICE_SETTINGS', {}, (err, res) => {
if (err) reject(err);
resolve(res.data);
});
});
}

setVoiceSettings (args) {
return new Promise((resolve, reject) => {
this.rpc.request('SET_VOICE_SETTINGS', args, (err, res) => {
if (err) reject(err);
resolve(res.data);
});
});
}

subscribe (event, args, callback) {
return this.rpc.subscribe(event, args, callback);
}

unsubscribe (event, args, callback) {
return this.rpc.unsubscribe(event, args, callback);
}

connect (token) {
return this.rpc.connect(token);
}
}

module.exports = Client;
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
version: require('../package.json').version,
Client: require('./RPCClient'),
Client: require('./Client'),
RPC: require('./RPCClient'),
Rest: require('./RESTClient'),
Constants: require('./Constants')
}
Expand Down
Loading

0 comments on commit 8150e71

Please sign in to comment.