A Plex bot library for integration with chat bots.
This package should be considered unstable. APIs may change between 0.x releases as I continue to work on it.
npm install plexacious
npm run configure
const Plexacious = require('plexacious');
const config = require('./config');
const bot = new Plexacious();
bot.init(config) // Alternatively, construct your own config object and pass it in
init(config[, callback])
Set up the Plex server information and start the digest timer.
{Object} config
: The configuration settings for the Plex server connection.{function} callback
: (optional) The callback function which will be called when init is complete.
Returns the Plexacious object instance for method chaining.
bot.init({
hostname: 'localhost',
port: 1234,
https: false,
token: 'abcdefg',
refreshDuration: 30,
}, () => console.log('Bot initialized'));
start()
Start the bot. This will start the digest timer. If the bot is already stopped, this will do nothing.
Returns the Plexacious object instance for method chaining.
stop()
Stop the bot. This will clear any existing digest timer. If the bot is already stopped, this will do nothing.
exit(exitCode)
Kills the bot's process completely.
{number} exitCode
: (optional) The exit code with which to exit the process. Defaults to 0 if not provided.
setRefreshDuration(timer)
Clear the current digest timer and set a new interval timer for the digest process. This will also cause the digest to run immediately (so that it's not possible to indefinitely delay the digest by constantly changing the timer).
{integer} timer
: The desired interval between digest processes, in minutes.
Returns the Plexacious object instance for method chaining.
bot.setRefreshDuration(30);
on(event[, callback])
Attach or detach a callback function to an event
{string} event
: The event to which to attach or from which to detach the callback function.{function} callback
: (optional) The callback function to attach to the event. If not provided, the existing callback function on this event will be detached, if any.
Returns the Plexacious object instance for method chaining.
bot.on('mediaAdded', (media) => console.log(media.title));
query(path)
Performs a GET action on the provided path on the Plex server, and returns the objects
{string} path
: The API path to request
A Promise that resolves to an array of objects
let library = await bot.query('/library');
bot.query('/library').then(things => {
console.dir(things);
});
Called every time the digest starts, before any calls to the Plex API are made.
Called every time the digest ends, after all API calls.
Called when a new streaming session is detected. Takes the session object as an argument.
Called when a streaming session is detected to have ended. Takes the session object as an argument.
Called when a new piece of media has been discovered in Plex's "Recently Added" section. Takes the media object as an argument.
bot.on('newMedia', (media) => console.log(media.title));