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

vote-tracker-js-api-wrapper

v1.0.4

Published

A simple wrapper for the Vote Tracker Discord bot API

Downloads

8

Readme

Vote Tracker js API wrapper

Info

An unofficial wrapper for the Vote Tracker Discord bot API.

To use the Vote Tracker API you must request an API token to Xavinlol (the creator of Vote Tracker and all its related content).
You can do that by joining Vote Tracker's Support Server.

Installation

npm i vote-tracker-js-api-wrapper

IMPORTANT

If you need support with the wrapper join the Vote Tracker's Support Server and ask for help in the related API channel.

Module usage examples

Disclaimer: I haven't put awaited methods in actual async functions just to make the examples look simpler, just remember most of the examples need to go inside async functions.

Vote events

In order to listen to vote events you will need to run a few commands with the Vote Tracker Discord bot.
For example, if you are tracking votes for your bot, and you set up those bot lists:
Example
You will need to use the following commands to make Vote Tracker forward all the webhooks to your server:

dbl?bot setforwardurl 1 http://serverIP:3000/topggRoute
dbl?bot setforwardurl 2 http://serverIP:3000/dbl
dbl?bot setforwardurl 3 http://serverIP:3000/dboats
dbl?bot setforwardurl 4 http://serverIP:3000/bfd

(3000 is just a random port, just make sure to match it in the API wrapper configs like I do in the example below, also, if it's not working, make sure you opened that port in the firewall)

Once you set that up, you can listen to vote events like this:

const VoteTrackerAPIWrapper = require("vote-tracker-js-api-wrapper")

const botID = "the ID of your bot"
const apiToken = "your apiToken"
// Make sure to match the various routes to the ones you have set with the dbl?bot setforwardurl command
const options = {
    webhooks: {
        port: 3000,
        topgg: "/topggRoute",
        dbl: "/dbl",
        dboats: "/dboats",
        bfd: "/bfd"
    }
}
const VoteTracker = new VoteTrackerAPIWrapper(botID, null, apiToken, options)

VoteTracker.once("ready", message => {
    console.log(message);
})

/*
Every voteData object contains the userID property with the ID of the user who voted.
It has a few other properties which you can see in the index.js file or by console logging them.
It also always contain the full webhook data at voteData.fullWebhook
 */
VoteTracker.on("topgg", voteData => {
    console.log(voteData)
})

VoteTracker.on("dbl", voteData => {
    console.log(voteData)
})

VoteTracker.on("dboats", voteData => {
    console.log(voteData)
})

VoteTracker.on("bfd", voteData => {
    console.log(voteData)
})

Check the last time a user has voted for your bot on top.gg

const VoteTrackerAPIWrapper = require("vote-tracker-js-api-wrapper")

const botID = "the ID of your bot"
const apiToken = "your apiToken"
const VoteTracker = new VoteTrackerAPIWrapper(botID, null, apiToken)

const userID = "ID of the user for which you want to check the last vote"
try {
    const lastVote = await VoteTracker.lastVote(userID)
} catch (e) {
    console.log(e)
}
/*
lastVote will be a javascript object with the following properties or it will be null if the user hasn't voted in the last month
 @prop {string} entity_id - the ID of the bot / server
 @prop {string} user_id - the ID of the user who voted
 @prop {string} source - the source ("topgg", "dbl", "dboats", "bfb")
 @prop {string} timestamp - the unix epoch millis timestamp of the last vote of the user
 */

Check if a user has voted in the last 12 hours for your bot on botsfordiscord.com

const VoteTrackerAPIWrapper = require("vote-tracker-js-api-wrapper")

const botID = "the ID of your bot"
const apiToken = "your apiToken"
// Sets the default website to check votes from (can be "topgg", "bfd", "dbl", "dboats")
const options = {
    defaultSource: "bfd"
}
const VoteTracker = new VoteTrackerAPIWrapper(botID, null, apiToken, options)

const userID = "ID of the user for which you want to check the last vote"
try {
    const hasVoted12Hours = await VoteTracker.hasVoted12Hours(userID)
    console.log(hasVoted12Hours) // true | false
} catch (e) {
    console.log(e)
}

// You can also set a different time instead of 12 hours by specifing it via milliseconds, example:
const milliseconds = 3600000 // equals 1 hour
try {
    const hasVoted1Hour = await VoteTracker.hasVoted12Hours(userID, milliseconds)
    console.log(hasVoted1Hour) // true | false
} catch (e) {
    console.log(e)
}

Check if a user has voted in the last 12 hours for your server on top.gg

const VoteTrackerAPIWrapper = require("vote-tracker-js-api-wrapper")

const serverID = "the ID of your server"
const apiToken = "your apiToken"

const VoteTracker = new VoteTrackerAPIWrapper(null, serverID, apiToken)

const userID = "ID of the user for which you want to check the last vote"
try {
    const hasVoted12Hours = await VoteTracker.hasVoted12Hours(userID)
    console.log(hasVoted12Hours) // true | false
} catch (e) {
    console.log(e)
}

Other examples

const VoteTrackerAPIWrapper = require("vote-tracker-js-api-wrapper")

const botID = "the ID of your bot"
const serverID = "the ID of your server"
const apiToken = "your apiToken"
// Sets the default website to check votes from (can be "topgg", "bfd", "dbl", "dboats") and the default type, so if checks for your bot or server by default
const options = {
    defaultSource: "topgg",
    defaultType: "server"
}
const VoteTracker = new VoteTrackerAPIWrapper(botID, serverID, apiToken, options)

const userID = "ID of the user for which you want to check the last vote"
try {
    const lastVote = await VoteTracker.hasVoted12Hours(userID)
    console.log(lastVote) // true | false (has voted in the past 12 hours for your server on top.gg)
} catch (e) {
    console.log(e)
}

let type = "bot"
try {
    const lastVote = await VoteTracker.hasVoted12Hours(userID, null, type)
    console.log(lastVote) // true | false (has voted in the past 12 hours for your bot on top.gg)
} catch (e) {
    console.log(e)
}

const source = "bfb"
type = "bot"
try {
    const lastVote = await VoteTracker.hasVoted12Hours(userID, source, type)
    console.log(lastVote) // true | false (has voted in the past 12 hours for your bot on botsfordiscord.com)
} catch (e) {
    console.log(e)
}
// For more info you can dive into the index.js file, it's pretty easy to understand its comments