Giter Club home page Giter Club logo

miniplug's Introduction

miniplug

Small plug.dj client for building bots and applications in Node.js, with a Promise-based API.

Installation - Usage - API - Status - Contributing - License: MIT

Installation (install size)

Note: Node v4 or higher is required. Run node -v in your console to check that your Node.js version is up-to-date.

npm install --save miniplug

Usage

const miniplug = require('miniplug')

const mp = miniplug()

// Add an example chat command "!id"
mp.on('chat', (message) => {
  if (/^!id/.test(message.message)) {
    message.reply(`Your user ID is ${message.uid}.`)
  }
})

// Connect to plug.dj
mp.connect({
  email: '[email protected]',
  password: 'hunter2'
}).catch((err) => {
  console.error('Could not connect to plug.dj:')
  console.error(err)
  process.exit(1)
})

// Join a room
mp.join('tastycat').then(() => {
  const room = mp.room()
  mp.chat(`Hello ${room.name}! :wave:`)
})

API

Full API documentation is available in docs/API.md.

For questions, visit the #coding channel in the plug.dj discord!

join the plug.dj discord

Status

Travis npm version David npm downloads

Contributing

Issues/PRs are appreciated!

To build the library, run:

npm run build

The built version will be placed in index.js.

To run tests, do:

npm test

There's not many tests just yet, but it's good to check anyway! This command will also check your code style using Standard.

Changed files will also be tested and linted automatically when you git commit.

License

MIT

miniplug's People

Contributors

goto-bus-stop avatar greenkeeper[bot] avatar greenkeeperio-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

miniplug's Issues

flowtype

Could add annotations to most things, I guess.

An in-range update of debug is breaking the build 🚨

Version 2.4.0 of debug just got published.

Branch Build failing 🚨
Dependency debug
Current Version 2.3.3
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

As debug is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you it’s very likely also breaking them.
I recommend you give this issue a very high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
Commits

The new version differs by 7 commits .

  • b82d4e6 release 2.4.0
  • 41002f1 Update bower.json (#342)
  • e58d54b Node: configurable util.inspect() options (#327)
  • 00f3046 Node: %O (big O) pretty-prints the object (#322)
  • bd9faa1 allow colours in workers (#335)
  • 501521f Use same color for same namespace. (#338)
  • e2a1955 Revert "handle regex special characters"

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

mp.dj() return undefined

mp.dj() return undefined if the actual dj is bot.
it's normal things, a bug or i'm just bad ???

Votes score undefined

Hi!
I'm using miniplug to set up my bot, and I am facing an issue. After registering this :
mp.on('advance', eventAdvance);
and
function eventAdvance(next, previous) { console.log(previous.score.positive); }
I have an error telling me that previous.score is undefined.

Please answer me ASAP, thanks :)

HTTP request backoff

To prevent getting locked out of plug.dj because of rate limiting, API requests should be spaced out somewhat.

Get user history

Can use the /_/profile/${id} endpoint now for a mp.user(xyz).getHistory() method.

Add tests

Using Ava and Nock. Will have to run Ava in --serial mode but that's ok :)

Check for Socket Connection after Login

Sometimes (often when plug is having issues) the bot can login but not connect to the socket. This leaves the bot useless and if you run stuff like forever monitor, your bot won't reconnect.

Perhaps a constant monitor of events to make sure the bot is connected could be a method to fix this. Or maybe some type of check after login.

Align vocabulary: time/timestamp

Some properties are named .time (current history entry), while others are .timestamp (notifications). Should pick one and stick with it.

Inconsistent historyEntry format

After advance fires, historyEntry is rebuilt in a different format than history (which also doesn't include the assistance methods such as the newly-added skip()).

Add an event when the socket connection ends

Just the other day, plug was having issues with advancing and whatnot. When the site went down (or perhaps before?), my bot didn't get any type of error, plugMait, etc. event. It just stopped receiving all events from plug.

This is an issue since my bot had no way of knowing plug was down and therefore couldn't auto restart. There should be some kind of timeout where it'll emit an event that there haven't been any events from plug after x amount of time. (probably 30s~1m)

Chat backoff

There's an option to configure chat backoff, but it'd be best to just include a backoff function that spaces out chat messages just right.

Implement/Document socket events

List from plug-socket:

  • ack
  • advance
  • ban
  • banIP
  • chat
  • chatDelete
  • djListCycle
  • djListLocked
  • djListUpdate
  • earn
  • sub
  • cash
  • gift
  • floodChat
  • floodAPI
  • friendRequest
  • friendAccept
  • gifted
  • grab
  • killSession
  • modBan
  • modAddDJ
  • modRemoveDJ
  • modMoveDJ
  • modMute
  • modSkip
  • modStaff
  • nameChanged
  • nameChangedRoom
  • notify
  • playlistCycle
  • plugMaintenance
  • plugMaintenanceAlert
  • plugMessage
  • plugUpdate
  • rateLimit
  • roomNameUpdate
  • roomDescriptionUpdate
  • roomWelcomeUpdate
  • roomMinChatLevelUpdate
  • skip
  • userJoin
  • userLeave
  • userUpdate
  • vote

Seemingly no way to get the response body on error

I need to get the body of the error when mp.addDJ fails, to parse the error message returned.

Example:

{
    "data": ["This request was understood but is forbidden."],
    "meta": {},
    "status": "noValidPlaylist",
    "time": 12.279033660888672
}

But there doesn't seem to be any way to get it through Promise.catch or the second Promise.then parameter. All I get is the native HTTP Error which isn't very useful.

Sorry if I missed a very obvious way of doing this.

[Critical Error] when someone leave dj and no body is in waitlist

When the waitlist is empty and the last song is finish (or skip) :

  waitlist.forEach((id) => {
          ^

TypeError: Cannot read property 'forEach' of undefined
    at wrapWaitlist (c:\Users\Maxime\node_modules\miniplug\index.js:399:11)
    at EventEmitter.ROLE.NONE [as wrapWaitlist] (c:\Users\Maxime\node_modules\miniplug\index.js:72:12)
    at onDjListUpdate (c:\Users\Maxime\node_modules\miniplug\index.js:855:32)
    at WebSocket.onAdvance (c:\Users\Maxime\node_modules\miniplug\index.js:860:7)
    at emitTwo (events.js:111:20)
    at WebSocket.emit (events.js:191:7)
    at c:\Users\Maxime\node_modules\plug-socket\index.js:24:10
    at Array.forEach (native)
    at WebSocket.onmessage (c:\Users\Maxime\node_modules\plug-socket\index.js:21:13)
    at WebSocket.onMessage (c:\Users\Maxime\node_modules\plug-socket\node_modules\ws\lib\EventTarget.js:103:16)
    at emitTwo (events.js:106:13)
    at WebSocket.emit (events.js:191:7)
    at Receiver.EventEmitter.setSocket.head._receiver.onmessage (c:\Users\Maxime\node_modules\plug-socket\node_modules\ws\lib\WebSocket.js:146:54)
    at Receiver.dataMessage (c:\Users\Maxime\node_modules\plug-socket\node_modules\ws\lib\Receiver.js:389:14)
    at Receiver.getData (c:\Users\Maxime\node_modules\plug-socket\node_modules\ws\lib\Receiver.js:330:12)
    at Receiver.startLoop (c:\Users\Maxime\node_modules\plug-socket\node_modules\ws\lib\Receiver.js:165:16)

My .js

const mp = miniplug({
    email: require('./bordel/auth.json').email,
    password: require('./bordel/auth.json').password
})
// Join a room 
mp.join('la-room-francaise').then((room) => {
    mp.chat(mp.me().username+' Online !');
})```

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.