Code Monkey home page Code Monkey logo

overwolf-discord-rpc-plugin's Introduction

Discord Rich Presence Plugin

Prepare the Discord Application

Login into your Discord Developer account, create a new application. The application name will be the "Playing.." shown on Discord.

Each application has an Application ID, you will use it to initialize the Discord RPC Client.

Upload your assets: every image has a name, called "key" in Discord language. You can use any image as Large or Small image.

The RPC is composed of:

  • Details
  • State
  • Large Image Key
  • Large Image Text (shown as tooltip on hover)
  • Small Image Key (shown on the bottom right corner of the Large Image)
  • Small Image Text (shown as tooltip on hover)

Compile the project

Open the DiscordRPCPlugin.csproj with Visual Studio 2019 (or newer), compile it, and copy DiscordRPCPlugin.dll, DiscordRPC.dll, and Newtonson.Json.dll inside your app, for example, a plugins directory.

This plugin uses discord-rpc-csharp to communicate with Discord.

API

The callback style is the same commonly used in the Overwolf API:

{ "success": bool, "status": "success|error" }

Methods

  • initialize(applicationID, logLevel, callback): Initialize the Discord RPC Client
  • onClientReady(callback): Fired when the RPC Client is ready, sends the current Discord User
  • onPresenceUpdate(callback): Fired when the RPC is updated
  • onClientError(callback): Fired when the RPC Client has errors
  • onLogLine(callback): Fired when a log line is received
  • updatePresence(details, state, largeImageKey, largeImageText, smallImageKey, smallImageText, showTimestamps, endTime, button1Text, button1Url, button2Text, button2Url, callback): Update the Rich Presence
  • updatePresenceWithButtonsArray(details, state, largeImageKey, largeImageText, smallImageKey, smallImageText, showTimestamps, endTime, buttonsJson, callback): Update the Rich Presence with buttons
  • dispose(callback): Clear the Rich Presence and dispose the connection

TypeScript Typings

TypeScript typings for the plugin are available in the types.ts file.

Use the Plugin

Declare the plugin

In manifest.json, declare the plugin under the extra-objects property:

"DiscordRPCPlugin": {
    "file": "plugins/DiscordRPCPlugin.dll",
    "class": "overwolf.plugins.DiscordRPCPlugin"
}

Acquire the plugin from JS

const discordRPCPlugin = await pluginService.getPlugin('DiscordRPCPlugin');

discordRPCPlugin.onClientReady.addListener(console.log);
discordRPCPlugin.onPresenceUpdate.addListener(console.log);
discordRPCPlugin.onClientError.addListener(console.error);
discordRPCPlugin.onLogLine.addListener(console.info);

discordRPCPlugin.initialize('YOUR APPLICATION ID', LogLevel.Info, console.log);

Update the Rich Presence

discordRPCPlugin.updatePresence('My Details', 'My state', 'large_image_key', 'Large image', 'small_image_key', 'Small image', true, 0, 'Button 1', 'https://button1.url', 'Button 2', 'https://button2.url', console.log);
const buttonsJson = '[{"label": "Button 1", "url": "https://button1.url"}, {"label": "Button 2", "url": "https://button2.url"}]';
discordRPCPlugin.updatePresenceWithButtonsArray('My Details', 'My state', 'large_image_key', 'Large image', 'small_image_key', 'Small image', true, 0, buttonsJson, console.log);

Dispose the Rich Presence

discordRPCPlugin.dispose(console.log);

overwolf-discord-rpc-plugin's People

Contributors

dowmeister avatar lmachens avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.