Skip to content

Commit

Permalink
update commands, events, errors
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnek committed Jul 8, 2019
1 parent aa95316 commit 3444ac2
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 84 deletions.
25 changes: 18 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
'use strict';

module.exports = {
extends: 'airbnb',
extends: 'airbnb-base',
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'script',
ecmaFeatures: {
experimentalObjectRestSpread: true,
},
},
env: {
es6: true,
Expand Down Expand Up @@ -39,6 +36,18 @@ module.exports = {
],
rules: {
'strict': ['error', 'global'],
'indent': ['error', 2, {
SwitchCase: 1,
FunctionDeclaration: {
parameters: 'first',
},
FunctionExpression: {
parameters: 'first',
},
CallExpression: {
arguments: 'first',
},
}],
'no-bitwise': 'off',
'no-iterator': 'off',
'global-require': 'off',
Expand All @@ -53,15 +62,14 @@ module.exports = {
'object-curly-newline': 'off',
'prefer-const': ['error', { destructuring: 'all' }],
'class-methods-use-this': 'off',
'operator-linebreak': ['error', 'after'],
'implicit-arrow-linebreak': 'off',
'react/no-this-in-sfc': 'off',
'lines-between-class-members': 'off',
'import/no-dynamic-require': 'off',
'import/no-extraneous-dependencies': ['error', {
devDependencies: true,
}],
'import/extensions': 'off',
'import/no-unresolved': 'off',
'import/prefer-default-export': 'off',
},
globals: {
WebAssembly: false,
Expand All @@ -71,6 +79,9 @@ module.exports = {
URL: false,
Atomics: false,
SharedArrayBuffer: false,
globalThis: false,
FinalizationGroup: false,
WeakRef: false,
queueMicrotask: false,
},
};
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,11 @@
"register-scheme": "github:devsnek/node-register-scheme"
},
"devDependencies": {
"babel-eslint": "^8.2.5",
"discord.js-docgen": "github:discordjs/docgen",
"electron": "^1.7.9",
"eslint": "^5.8.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.11.1",
"eslint": "^5.3.0",
"eslint-config-airbnb-base": "^13.2.0",
"eslint-plugin-import": "^2.18.0",
"jsdoc-strip-async-await": "^0.1.0",
"webpack": "^4.13.0",
"webpack-cli": "^3.0.8"
Expand Down
21 changes: 15 additions & 6 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const EventEmitter = require('events');
const { setTimeout, clearTimeout } = require('timers');
const fetch = require('node-fetch');
const transports = require('./transports');
const { RPCCommands, RPCEvents } = require('./constants');
const { RPCCommands, RPCEvents, RelationshipTypes } = require('./constants');
const { pid: getPid, uuid } = require('./util');

function subKey(event, args) {
Expand Down Expand Up @@ -492,8 +492,8 @@ class RPCClient extends EventEmitter {
}
}
if (
args.largeImageKey || args.largeImageText ||
args.smallImageKey || args.smallImageText
args.largeImageKey || args.largeImageText
|| args.smallImageKey || args.smallImageText
) {
assets = {
large_image: args.largeImageKey,
Expand Down Expand Up @@ -575,15 +575,15 @@ class RPCClient extends EventEmitter {
});
}

async createLobby(type, capacity, metadata) {
createLobby(type, capacity, metadata) {
return this.request(RPCCommands.CREATE_LOBBY, {
type,
capacity,
metadata,
});
}

async updateLobby(lobby, { type, owner, capacity, metadata } = {}) {
updateLobby(lobby, { type, owner, capacity, metadata } = {}) {
return this.request(RPCCommands.UPDATE_LOBBY, {
id: lobby.id || lobby,
type,
Expand All @@ -599,7 +599,7 @@ class RPCClient extends EventEmitter {
});
}

async connectToLobby(id, secret) {
connectToLobby(id, secret) {
return this.request(RPCCommands.CONNECT_TO_LOBBY, {
id,
secret,
Expand Down Expand Up @@ -627,6 +627,15 @@ class RPCClient extends EventEmitter {
});
}

getRelationships() {
const types = Object.keys(RelationshipTypes);
return this.request(RPCCommands.GET_RELATIONSHIPS)
.then((o) => o.relationships.map((r) => ({
...r,

This comment has been minimized.

Copy link
@shirt-dev

shirt-dev Aug 4, 2019

...r causes errors

type: types[r.type],
})));
}

/**
* Subscribe to an event
* @param {string} event Name of event e.g. `MESSAGE_CREATE`
Expand Down
99 changes: 75 additions & 24 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,73 @@ exports.RPCCommands = keyMirror([
'GET_GUILDS',
'GET_CHANNEL',
'GET_CHANNELS',
'GET_RELATIONSHIPS',
'GET_USER',
'SUBSCRIBE',
'UNSUBSCRIBE',
'SET_USER_VOICE_SETTINGS',
'SET_USER_VOICE_SETTINGS_2',
'SELECT_VOICE_CHANNEL',
'GET_SELECTED_VOICE_CHANNEL',
'SELECT_TEXT_CHANNEL',
'GET_VOICE_SETTINGS',
'SET_VOICE_SETTINGS_2',
'SET_VOICE_SETTINGS',
'CAPTURE_SHORTCUT',
'SET_CERTIFIED_DEVICES',
'SET_ACTIVITY',
'SEND_ACTIVITY_JOIN_INVITE',
'SEND_ACTIVITY_JOIN_REQUEST',
'CLOSE_ACTIVITY_JOIN_REQUEST',
'ACTIVITY_INVITE_USER',
'ACCEPT_ACTIVITY_INVITE',
'INVITE_BROWSER',
'DEEP_LINK',
'CONNECTIONS_CALLBACK',
'BRAINTREE_POPUP_BRIDGE_CALLBACK',
'GIFT_CODE_BROWSER',
'OVERLAY',
'BROWSER_HANDOFF',
'SET_CERTIFIED_DEVICES',
'GET_IMAGE',
'CREATE_LOBBY',
'UPDATE_LOBBY',
'DELETE_LOBBY',
'UPDATE_LOBBY_MEMBER',
'CONNECT_TO_LOBBY',
'DISCONNECT_FROM_LOBBY',
'SEND_TO_LOBBY',
'INVITE_BROWSER',
'DEEP_LINK',
'CONNECTIONS_CALLBACK',
'OVERLAY',
'BROWSER_HANDOFF',
'SEARCH_LOBBIES',
'CONNECT_TO_LOBBY_VOICE',
'DISCONNECT_FROM_LOBBY_VOICE',
'SET_OVERLAY_LOCKED',
'OPEN_OVERLAY_ACTIVITY_INVITE',
'OPEN_OVERLAY_GUILD_INVITE',
'OPEN_OVERLAY_VOICE_SETTINGS',
'VALIDATE_APPLICATION',
'GET_ENTITLEMENT_TICKET',
'GET_APPLICATION_TICKET',
'START_PURCHASE',
'GET_SKUS',
'GET_ENTITLEMENTS',
'GET_NETWORKING_CONFIG',
'NETWORKING_SYSTEM_METRICS',
'NETWORKING_PEER_METRICS',
'NETWORKING_CREATE_TOKEN',
'SET_USER_ACHIEVEMENT',
'GET_USER_ACHIEVEMENTS',
]);

exports.RPCEvents = keyMirror([
'CURRENT_USER_UPDATE',
'GUILD_STATUS',
'GUILD_CREATE',
'CHANNEL_CREATE',
'RELATIONSHIP_UPDATE',
'VOICE_CHANNEL_SELECT',
'VOICE_STATE_CREATE',
'VOICE_STATE_DELETE',
'VOICE_STATE_UPDATE',
'VOICE_SETTINGS_UPDATE',
'VOICE_SETTINGS_UPDATE_2',
'VOICE_CONNECTION_STATUS',
'SPEAKING_START',
'SPEAKING_STOP',
Expand All @@ -64,47 +94,59 @@ exports.RPCEvents = keyMirror([
'ACTIVITY_JOIN',
'ACTIVITY_JOIN_REQUEST',
'ACTIVITY_SPECTATE',
'ACTIVITY_INVITE',
'NOTIFICATION_CREATE',
'MESSAGE_CREATE',
'MESSAGE_UPDATE',
'MESSAGE_DELETE',
'CAPTURE_SHORTCUT_CHANGE',
'LOBBY_DELETE',
'LOBBY_UPDATE',
'LOBBY_MEMBER_CONNECT',
'LOBBY_MEMBER_DISCONNECT',
'LOBBY_MEMBER_UPDATE',
'LOBBY_MESSAGE',
'CAPTURE_SHORTCUT_CHANGE',
'OVERLAY',
'OVERLAY_UPDATE',
'ENTITLEMENT_CREATE',
'ENTITLEMENT_DELETE',
'USER_ACHIEVEMENT_UPDATE',
'READY',
'ERROR',
]);

exports.RPCErrors = {
UNKNOWN_ERROR: 1000,
INVALID_PAYLOAD: 4000,
INVALID_VERSION: 4001,
INVALID_COMMAND: 4002,
INVALID_GUILD: 4003,
INVALID_EVENT: 4004,
CAPTURE_SHORTCUT_ALREADY_LISTENING: 5004,
GET_GUILD_TIMED_OUT: 5002,
INVALID_ACTIVITY_JOIN_REQUEST: 4012,
INVALID_ACTIVITY_SECRET: 5005,
INVALID_CHANNEL: 4005,
INVALID_PERMISSIONS: 4006,
INVALID_CLIENTID: 4007,
INVALID_ORIGIN: 4008,
INVALID_TOKEN: 4009,
INVALID_USER: 4010,
INVALID_COMMAND: 4002,
INVALID_ENTITLEMENT: 4015,
INVALID_EVENT: 4004,
INVALID_GIFT_CODE: 4016,
INVALID_GUILD: 4003,
INVALID_INVITE: 4011,
INVALID_ACTIVITY_JOIN_REQUEST: 4012,
INVALID_LOBBY: 4013,
INVALID_LOBBY_SECRET: 4014,
INVALID_ORIGIN: 4008,
INVALID_PAYLOAD: 4000,
INVALID_PERMISSIONS: 4006,
INVALID_TOKEN: 4009,
INVALID_USER: 4010,
LOBBY_FULL: 5007,
NO_ELIGIBLE_ACTIVITY: 5006,
OAUTH2_ERROR: 5000,
PURCHASE_CANCELED: 5008,
PURCHASE_ERROR: 5009,
RATE_LIMITED: 5011,
SELECT_CHANNEL_TIMED_OUT: 5001,
GET_GUILD_TIMED_OUT: 5002,
SELECT_VOICE_FORCE_REQUIRED: 5003,
CAPTURE_SHORTCUT_ALREADY_LISTENING: 5004,
INVALID_ACTIVITY_SECRET: 5005,
NO_ELIGIBLE_ACTIVITY: 5006,
LOBBY_FULL: 5007,
SERVICE_UNAVAILABLE: 1001,
TRANSACTION_ABORTED: 1002,
UNAUTHORIZED_FOR_ACHIEVEMENT: 5010,
UNKNOWN_ERROR: 1000,
};

exports.RPCCloseCodes = {
Expand All @@ -123,3 +165,12 @@ exports.LobbyTypes = {
PRIVATE: 1,
PUBLIC: 2,
};

exports.RelationshipTypes = {
NONE: 0,
FRIEND: 1,
BLOCKED: 2,
PENDING_INCOMING: 3,
PENDING_OUTGOING: 4,
IMPLICIT: 5,
};
41 changes: 0 additions & 41 deletions test/lobby.js

This file was deleted.

7 changes: 7 additions & 0 deletions test/rp.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ client.on('ready', () => {
spectateSecret: 'sniff',
instance: true,
}).then(console.log);

client.getRelationships().then((relations) => {
relations
.filter((r) => r.type === 'IMPLICIT')
.map((r) => `${r.user.username}#${r.user.discriminator}`)
.forEach((c) => console.log(c));
});
});

client.login({ clientId }).catch(console.error);

0 comments on commit 3444ac2

Please sign in to comment.