npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

myheroacademia

v1.1.5

Published

Bot para My Hero Academia.

Downloads

17

Readme

Installation

$ npm install --save discord-leveling

Checkout my package for economy systems on discord bots! discord-economy

Required packages

  • sequelize the DB wrapper of sqlite3 of this project (npm install --save sequelize)
  • sqlite3 Core DB (npm install --save sqlite3)

Optional

ChangeLog

  • 1.1.0 Finally back! For now only some typo fixes and cleaner code.

SetXp

/**
 * @param {string} [UserID] - Somebody's discord user ID.
 * @param {integer} [toSet] - How much xp you want the user to have.
 */

var leveling = require('discord-leveling')
leveling.SetXp(UserID, toSet)

/**
Expected Promise Output
{userid, xp}
 */

SetLevel

/**
* @param {string} [UserID] - Somebody's discord user ID.
* @param {integer} [toSet] - How much levels you want the user to have.
 */

var leveling = require('discord-leveling')
leveling.SetLevel(UserID, toSet)

/**
Expected Promise Output
{userid, level}
 */

AddXp

/**
* @param {string} [UserID] - Somebody's discord user ID.
* @param {integer} [toAdd] - How much xp you want to add.
 */

var leveling = require('discord-leveling')
leveling.AddXp(UserID, toAdd)

/**
Expected Promise Output
{userid, oldxp, newxp}
 */

AddLevel

/**
* @param {string} [UserID] - Somebody's discord user ID.
* @param {integer} [toAdd] - How much levels you want to add.
 */

var leveling = require('discord-leveling')
leveling.AddLevel(UserID, toAdd)

/**
Expected Promise Output
{userid, oldlevel, newlevel}
 */

Leaderboard

/**
 * @param {Object} data - The data you want to attach to the function.
  All keys in this object are optional.
 * @param {integer} data.limit - Limit how much users to fetch.
 * @param {string} data.search - Search the placement of a user in leaderboard.
 */

var leveling = require('discord-leveling')
leveling.Leaderboard({limit: NUMBER, search: 'UserID'})

/**
Expected Promise Output without data.search
[ {userid, level, xp}, {userid, level, xp}, {userid, level, xp} ]
array[0] is the first place of the leaderboard. array[1] second etc.
 */

 /**
Expected Promise Output with data.search
{userid, placement}
 */

Fetch

/**
 * @param {string} [UserID] - Somebody's discord user ID.
 */

var leveling = require('discord-leveling')
leveling.Fetch(UserID)

/**
Expected Promise Output
{userid, xp, level}
 */

Delete

/**
 * @param {string} [UserID] - Somebody's discord user ID.
 */
var leveling = require('discord-leveling')
leveling.Delete(UserID)

/**
Expected Promise Output
{deleted}
 */

Example Bot (discord.js)

/*
If you want to make discord-leveling guild based you have to use message.author.id + message.guild.id as ID for example:
leveling.AddLevel(message.author.id + message.guild.id, toAdd).then(l => console.log(l))

This will create an unique ID for each guild member
*/


//Requiring Packages
const Discord = require('discord.js'); //This can also be discord.js-commando or other node based packages!
const leveling = require('./app.js');

//Create the bot client
const client = new Discord.Client();

//Set the prefix and token of the bot.
const settings = {
  prefix: ';',
  token: 'YOUR TOKEN'
}

//Whenever someone types a message this gets activated.
//(If you use 'await' in your functions make sure you put async here)
client.on('message', async message => {

  //This reads the first part of your message behind your prefix to see which command you want to use.
  var command = message.content.toLowerCase().slice(settings.prefix.length).split(' ')[0];

  //These are the arguments behind the commands.
  var args = message.content.split(' ').slice(1);

  //If the user that types a message is a bot account return.
  if (message.author.bot) return;

  //When someone sends a message add xp
  var profile = await leveling.Fetch(message.author.id)
  leveling.AddXp(message.author.id, 10)
  //If user xp higher than 100 add level
  if (profile.xp + 10 > 100) {
    await leveling.AddLevel(message.author.id, 1)
    await leveling.SetXp(message.author.id, 0)
    message.reply(`You just leveled up!! You are now level: ${profile.level + 1}`)
  }

  //If the message does not start with your prefix return.
  if (!message.content.startsWith(settings.prefix)) return;

  if (command === 'profile') {

    var user = message.mentions.users.first() || message.author

    var output = await leveling.Fetch(user.id)
    message.channel.send(`Hey ${user.tag}! You have ${output.level} level(s)! and ${output.xp} xp!`);
  }

  if (command === 'setxp') {

    var amount = args[0]
    var user = message.mentions.users.first() || message.author

    var output = await leveling.SetXp(user.id, amount)
    message.channel.send(`Hey ${user.tag}! You now have ${amount} xp!`);
  }

  if (command === 'setlevel') {

    var amount = args[0]
    var user = message.mentions.users.first() || message.author

    var output = await leveling.SetLevel(user.id, amount)
    message.channel.send(`Hey ${user.tag}! You now have ${amount} levels!`);
  }

  if (command === 'leaderboard') {

    //If you put a mention behind the command it searches for the mentioned user in database and tells the position.
    if (message.mentions.users.first()) {

      var output = await leveling.Leaderboard({
        search: message.mentions.users.first().id
      })
      message.channel.send(`The user ${message.mentions.users.first().tag} is number ${output.placement} on my leaderboard!`);

      //Searches for the top 3 and outputs it to the user.
    } else {

      leveling.Leaderboard({
        limit: 3 //Only takes top 3 ( Totally Optional )
      }).then(async users => { //make sure it is async

        if (users[0]) var firstplace = await client.fetchUser(users[0].userid) //Searches for the user object in discord for first place
        if (users[1]) var secondplace = await client.fetchUser(users[1].userid) //Searches for the user object in discord for second place
        if (users[2]) var thirdplace = await client.fetchUser(users[2].userid) //Searches for the user object in discord for third place

        message.channel.send(`My leaderboard:

          1 - ${firstplace && firstplace.tag || 'Nobody Yet'} : ${users[0] && users[0].level || 'None'} : ${users[0] && users[0].xp || 'None'}
          2 - ${secondplace && secondplace.tag || 'Nobody Yet'} : ${users[1] && users[1].level || 'None'} : ${users[0] && users[0].xp || 'None'}
          3 - ${thirdplace && thirdplace.tag || 'Nobody Yet'} : ${users[2] && users[2].level || 'None'} : ${users[0] && users[0].xp || 'None'}`)

      })

    }
  }

  if (command == 'delete') { //You want to make this command admin only!

    var user = message.mentions.users.first()
    if (!user) return message.reply('Please specify a user I have to delete in my database!')

    if (!message.guild.me.hasPermission(`ADMINISTRATION`)) return message.reply('You need to be admin to execute this command!')

    var output = await leveling.Delete(user.id)
    if (output.deleted == true) return message.reply('Succesfully deleted the user out of the database!')

    message.reply('Error: Could not find the user in database.')

  }

})

//Your secret token to log the bot in. (never show this to anyone!)
client.login(settings.token)