Skip to content

A Deno wrapper for the PluralKit API, written in TypeScript.

License

Notifications You must be signed in to change notification settings

aronson/pkapi.ts

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pkapi.js

A PluralKit API wrapper for NodeJS, written in TypeScript

About

PluralKit is an incredibly useful tool for plurals, trans folks, and roleplayers that comes with an API for use alongside the bot. This wrapper was created to make interacting with the API in Node.js applications easier

This wrapper comes with features like:

  • Full coverage of the API (up to v2)
  • More options for setting values (eg: "red" is a valid member.color)
  • Options to fetch members, fronters, and switches when fetching a system
  • Promise based and object oriented

And more!

Installation

With Node 14.x or higher, use this to install:
npm install pkapi.js

Dependencies

This library uses only a few dependencies, which are:

  • axios - for request handling
  • @vvo/tzdb - for verifying timezones
  • chrono-node - for parsing birthdays
  • tinycolor2 - for parsing colors
  • valid-url - for verifying avatar urls

Setup

The wrapper itself requires zero setup. However, there are still some options you can use:

// cjs, or commonJS
const PKAPI = require('pkapi.js').default;

// esm
import PKAPI from 'pkapi.js';

// shown values are defaults!
const api = new PKAPI({
	base_url: "https://api.pluralkit.me", // base api url
	version: 2, // api version
	token: undefined // for authing requests. only set if you're using this for a single system!
})

Note: This library currently supports up to APIv2.

Examples

Using the above setup; note that exmpl is a real system

// get a system by id
var system = await api.getSystem({system: 'exmpl'});

// authed version of above
var system = await api.getSystem({system: 'exmpl', token: process.env.TOKEN});

// edit the system
system.tz = "est";
system.description = "Test system";

// patch
await system.patch(process.env.TOKEN);

// see the changes
console.log(system)
// get member
var member = await api.getMember({member: 'gaznz'};

// edit
member.name = "Test Name";
member.visibility = true; // public
member.name_privacy = false; // private
await member.patch(process.env.TOKEN)

console.log(member)

Docs

Check out the wiki for documentation

About

A Deno wrapper for the PluralKit API, written in TypeScript.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%