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
================================================
<div align="center">
<br />
<p>
<a href="https://discord.gg/bRCvFy9"><img src="https://discordapp.com/api/guilds/222078108977594368/embed.png" alt="Discord server" /></a>
<a href="https://www.npmjs.com/package/discord-rich-presence"><img src="https://img.shields.io/npm/v/discord-rich-presence.svg?maxAge=3600" alt="NPM version" /></a>
<a href="https://www.npmjs.com/package/discord-rich-presence"><img src="https://img.shields.io/npm/dt/discord-rich-presence.svg?maxAge=3600" alt="NPM downloads" /></a>
<a href="https://david-dm.org/devsnek/discord-rich-presence"><img src="https://img.shields.io/david/devsnek/discord-rich-presence.svg?maxAge=3600" alt="Dependencies" /></a>
</p>
<p>
<a href="https://nodei.co/npm/discord-rich-presence/"><img src="https://nodei.co/npm/discord-rich-presence.png?downloads=true&stars=true" alt="NPM info" /></a>
</p>
</div>
# 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 <me@gus.host>",
"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,
};
gitextract_drg0u9mi/ ├── .github/ │ └── FUNDING.yml ├── .gitignore ├── .npmignore ├── .npmrc ├── README.md ├── index.js ├── package.json ├── test.js └── webpack.config.js
SYMBOL INDEX (1 symbols across 1 files)
FILE: index.js
function makeClient (line 8) | function makeClient(clientId) {
Condensed preview — 9 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (7K chars).
[
{
"path": ".github/FUNDING.yml",
"chars": 446,
"preview": "# These are supported funding model platforms\n\ngithub: [devsnek] # Replace with up to 4 GitHub Sponsors-enabled username"
},
{
"path": ".gitignore",
"chars": 24,
"preview": "node_modules\nbrowser.js\n"
},
{
"path": ".npmignore",
"chars": 49,
"preview": "node_modules\ntest.js\nwebpack.config.js\nREADME.md\n"
},
{
"path": ".npmrc",
"chars": 19,
"preview": "package-lock=false\n"
},
{
"path": "README.md",
"chars": 1530,
"preview": "<div align=\"center\">\n <br />\n <p>\n <a href=\"https://discord.gg/bRCvFy9\"><img src=\"https://discordapp.com/api/guilds"
},
{
"path": "index.js",
"chars": 1746,
"preview": "'use strict';\n\nconst Discord = require('discord-rpc');\nconst EventEmitter = require('events');\n\nconst browser = typeof w"
},
{
"path": "package.json",
"chars": 875,
"preview": "{\n \"name\": \"discord-rich-presence\",\n \"version\": \"0.0.8\",\n \"description\": \"rich presence wrapper for discord-rpc\",\n \""
},
{
"path": "test.js",
"chars": 834,
"preview": "'use strict';\n\nconst client = require('.')('180984871685062656');\n\nclient.on('join', (secret) => {\n console.log('we sho"
},
{
"path": "webpack.config.js",
"chars": 908,
"preview": "const path = require('path');\nconst webpack = require('webpack');\nconst UglifyJSPlugin = require('uglifyjs-webpack-plugi"
}
]
About this extraction
This page contains the full source code of the devsnek/discord-rich-presence GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 9 files (6.3 KB), approximately 1.9k tokens, and a symbol index with 1 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.