Repository: devsnek/discord-rich-presence Branch: master Commit: e7c9d0b76e46 Files: 9 Total size: 6.3 KB Directory structure: gitextract_drg0u9mi/ ├── .github/ │ └── FUNDING.yml ├── .gitignore ├── .npmignore ├── .npmrc ├── README.md ├── index.js ├── package.json ├── test.js └── webpack.config.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/FUNDING.yml ================================================ # These are supported funding model platforms github: [devsnek] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] patreon: # Replace with a single Patreon username open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel custom: # Replace with a single custom sponsorship URL ================================================ FILE: .gitignore ================================================ node_modules browser.js ================================================ FILE: .npmignore ================================================ node_modules test.js webpack.config.js README.md ================================================ FILE: .npmrc ================================================ package-lock=false ================================================ FILE: README.md ================================================

Discord server NPM version NPM downloads Dependencies

NPM info

# Discord Rich Presence A simple wrapper around [discord-rpc](https://npmjs.org/discord-rpc) ### Example ```javascript const client = require('discord-rich-presence')('180984871685062656'); client.updatePresence({ state: 'slithering', details: '🐍', startTimestamp: Date.now(), endTimestamp: Date.now() + 1337, largeImageKey: 'snek_large', smallImageKey: 'snek_small', instance: true, }); ``` In browser you can import/require it as `discord-rich-presence/browser`. However, it should be noted that currently using rich presence in browser is a feature whitelisted by Discord, and you will most likely be unable to use it. ================================================ FILE: index.js ================================================ 'use strict'; const Discord = require('discord-rpc'); const EventEmitter = require('events'); const browser = typeof window !== 'undefined'; function makeClient(clientId) { const rpc = new Discord.Client({ transport: browser ? 'websocket' : 'ipc' }); let connected = false; let activityCache = null; const instance = new class RP extends EventEmitter { updatePresence(d) { if (connected) { rpc.setActivity(d).catch((e) => this.emit('error', e)); } else { activityCache = d; } } reply(user, response) { const handle = (e) => this.emit('error', e); switch (response) { case 'YES': rpc.sendJoinInvite(user).catch(handle); break; case 'NO': case 'IGNORE': rpc.closeJoinRequest(user).catch(handle); break; default: throw new RangeError('unknown response'); } } disconnect() { rpc.destroy().catch((e) => this.emit('error', e)); } }(); rpc.on('error', (e) => instance.emit('error', e)); rpc.login({ clientId }) .then(() => { instance.emit('connected'); connected = true; rpc.subscribe('ACTIVITY_JOIN', ({ secret }) => { instance.emit('join', secret); }); rpc.subscribe('ACTIVITY_SPECTATE', ({ secret }) => { instance.emit('spectate', secret); }); rpc.subscribe('ACTIVITY_JOIN_REQUEST', (user) => { instance.emit('joinRequest', user); }); if (activityCache) { rpc.setActivity(activityCache).catch((e) => instance.emit('error', e)); activityCache = null; } }) .catch((e) => instance.emit('error', e)); return instance; } module.exports = makeClient; ================================================ FILE: package.json ================================================ { "name": "discord-rich-presence", "version": "0.0.8", "description": "rich presence wrapper for discord-rpc", "main": "index.js", "unpkg": "browser.js", "jsdelivr": "browser.js", "scripts": { "build:browser": "webpack", "prepublishOnly": "env NODE_ENV=production npm run build:browser" }, "repository": { "type": "git", "url": "git+https://github.com/devsnek/discord-rich-presence.git" }, "keywords": [ "discord", "rich", "presence", "rpc" ], "author": "snek ", "license": "MIT", "bugs": { "url": "https://github.com/devsnek/discord-rich-presence/issues" }, "homepage": "https://github.com/devsnek/discord-rich-presence#readme", "dependencies": { "discord-rpc": "github:discordjs/rpc" }, "devDependencies": { "uglifyjs-webpack-plugin": "^1.1.2", "webpack": "^3.10.0" } } ================================================ FILE: test.js ================================================ 'use strict'; const client = require('.')('180984871685062656'); client.on('join', (secret) => { console.log('we should join with', secret); }); client.on('spectate', (secret) => { console.log('we should spectate with', secret); }); client.on('joinRequest', (user) => { if (user.discriminator === '1337') { client.reply(user, 'YES'); } else { client.reply(user, 'IGNORE'); } }); client.on('connected', () => { console.log('connected!'); client.updatePresence({ 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', }); }); process.on('unhandledRejection', console.error); ================================================ FILE: webpack.config.js ================================================ const path = require('path'); const webpack = require('webpack'); const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); const plugins = [ new webpack.optimize.ModuleConcatenationPlugin(), ]; const prod = process.env.NODE_ENV === 'production'; if (prod) { plugins.push(new UglifyJSPlugin({ uglifyOptions: { mangle: { keep_classnames: true }, output: { comments: false }, }, })); } module.exports = { entry: './index.js', output: { path: path.resolve('.'), filename: 'browser.js', library: 'DiscordRichPresence', libraryTarget: 'umd', }, module: { rules: [ { test: /\.md$/, loader: 'ignore-loader' }, ], }, node: { fs: 'empty', dns: 'empty', tls: 'empty', child_process: 'empty', dgram: 'empty', __dirname: true, process: false, path: 'empty', Buffer: false, zlib: 'empty', }, plugins, };