From 3444ac24d2f0d5f52f59207a8759d928207df0ad Mon Sep 17 00:00:00 2001 From: Gus Caplan Date: Mon, 8 Jul 2019 17:41:13 -0500 Subject: [PATCH] update commands, events, errors --- .eslintrc.js | 25 ++++++++---- package.json | 9 ++--- src/client.js | 21 +++++++--- src/constants.js | 99 ++++++++++++++++++++++++++++++++++++------------ test/lobby.js | 41 -------------------- test/rp.js | 7 ++++ 6 files changed, 118 insertions(+), 84 deletions(-) delete mode 100644 test/lobby.js diff --git a/.eslintrc.js b/.eslintrc.js index 367a809..d38ffad 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -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, @@ -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', @@ -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, @@ -71,6 +79,9 @@ module.exports = { URL: false, Atomics: false, SharedArrayBuffer: false, + globalThis: false, + FinalizationGroup: false, + WeakRef: false, queueMicrotask: false, }, }; diff --git a/package.json b/package.json index a32598f..85d0710 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/client.js b/src/client.js index 78b1ca5..073b907 100644 --- a/src/client.js +++ b/src/client.js @@ -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) { @@ -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, @@ -575,7 +575,7 @@ class RPCClient extends EventEmitter { }); } - async createLobby(type, capacity, metadata) { + createLobby(type, capacity, metadata) { return this.request(RPCCommands.CREATE_LOBBY, { type, capacity, @@ -583,7 +583,7 @@ class RPCClient extends EventEmitter { }); } - async updateLobby(lobby, { type, owner, capacity, metadata } = {}) { + updateLobby(lobby, { type, owner, capacity, metadata } = {}) { return this.request(RPCCommands.UPDATE_LOBBY, { id: lobby.id || lobby, type, @@ -599,7 +599,7 @@ class RPCClient extends EventEmitter { }); } - async connectToLobby(id, secret) { + connectToLobby(id, secret) { return this.request(RPCCommands.CONNECT_TO_LOBBY, { id, secret, @@ -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, + type: types[r.type], + }))); + } + /** * Subscribe to an event * @param {string} event Name of event e.g. `MESSAGE_CREATE` diff --git a/src/constants.js b/src/constants.js index 1fd3a5c..6298905 100644 --- a/src/constants.js +++ b/src/constants.js @@ -19,20 +19,33 @@ 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', @@ -40,22 +53,39 @@ exports.RPCCommands = keyMirror([ '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', @@ -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 = { @@ -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, +}; diff --git a/test/lobby.js b/test/lobby.js deleted file mode 100644 index c3659f3..0000000 --- a/test/lobby.js +++ /dev/null @@ -1,41 +0,0 @@ -'use strict'; - -/* eslint-disable no-console */ - -try { - require('wtfnode').init(); -} catch (err) {} // eslint-disable-line no-empty - -const { Client } = require('../'); - -const { clientId, clientSecret } = require('./auth'); - -const client = new Client({ transport: 'ipc' }); - -client.on('ready', async () => { - console.log(client.user); - - await client.setActivity({ - state: 'slithering', - details: '🐍', - startTimestamp: new Date(), - largeImageKey: 'snek_large', - smallImageKey: 'snek_small', - partyId: 'snek_party', - partySize: 1, - partyMax: 1, - matchSecret: 'slithers', - joinSecret: 'boop', - spectateSecret: 'sniff', - instance: true, - }).then(console.log, console.error); - - // await client.createLobby('private', 2, { hi: 1 }) - // .then(console.log, console.error); -}); - -client.login({ - clientId, - clientSecret, - scopes: ['rpc', 'rpc.api'], -}).catch(console.error); diff --git a/test/rp.js b/test/rp.js index 47bf903..5e73dba 100644 --- a/test/rp.js +++ b/test/rp.js @@ -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);