Giter Club home page Giter Club logo

topgg-autoposter's Introduction

Top.gg AutoPoster

Easy AutoPosting via the top.gg sdk

How to

It's really really simple! All you gotta do is:

const { AutoPoster } = require('topgg-autoposter')

const poster = AutoPoster('topggtoken', client) // your discord.js or eris client

// optional
poster.on('posted', (stats) => { // ran when succesfully posted
  console.log(`Posted stats to Top.gg | ${stats.serverCount} servers`)
})

You can also do poster.on('error', (err) => { ... }) and this will stop errors from being logged and left for you to handle

And that's it!

It will begin to post your server count, and shard count every 30 minutes.

This even work on individual Discord.JS shards that are process separated.

If you would like to do specific clients, DJSPoster & ErisPoster & DJSSharderPoster & RosePoster are all exported classes!

Traditional Discord.JS Sharding:

If you use Discord.JS' traditional ShardingManager sharder, you can also append the AutoPoster to the sharding manager like so:

const sharder = new Discord.ShardingManager(...)

const poster = AutoPoster('topggtoken', sharder)

sharder.spawn() // rest of your stuff!

This will run broadcastEval's and automatically fetch your statistics!

Discord-Rose posting

const master = new Master(...)

const poster = AutoPoster('topggtoken', master)

And it will run everything through comms.getStats() function

topgg-autoposter's People

Contributors

alexanderpaolini avatar jpbberry avatar officialpiyush avatar superchupudev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

topgg-autoposter's Issues

Build Issue with TypeScript

As I'm rebuilding my Discord bot from JavaScript to TypeScript, I seemed to get a build error every time:

node_modules/@top-gg/sdk/dist/structs/Webhook.d.ts:1:49 - error TS2307: Cannot find module 'express' or its corresponding type declarations.

1 import { Request, Response, NextFunction } from "express";
                                                  ~~~~~~~~~


Found 1 error.

I'm assuming it's due to @top-gg/sdk not being updated in package.json? I haven't manually installed @top-gg/sdk on my package.json, so it has to be this package. A pull request was merged to fix this error, and this package hasn't been updated to use the new version(s): Top-gg-Community/node-sdk#56. Although I'm not sure if that is what's causing the error, it's the conclusion I have came to. As for now, I've downloaded the express types as a dev dependency, which solves the build issue.

TopGGAPIError: 504 Gateway Timeout

TopGGAPIError: 504 Gateway Timeout
    at Api._request (/home/pi/PanaisV2/node_modules/@top-gg/sdk/dist/structs/Api.js:61:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Api.postStats (/home/pi/PanaisV2/node_modules/@top-gg/sdk/dist/structs/Api.js:86:9) {
  response: {
    statusCode: 504,
    headers: {
      date: 'Fri, 23 Feb 2024 18:17:23 GMT',
      'content-type': 'text/plain; charset=UTF-8',
      'content-length': '15',
      connection: 'keep-alive',
      'strict-transport-security': 'max-age=15552000; includeSubDomains; preload',
      'x-content-type-options': 'nosniff',
      'x-frame-options': 'SAMEORIGIN',
      'referrer-policy': 'same-origin',
      'cache-control': 'private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0',
      expires: 'Thu, 01 Jan 1970 00:00:01 GMT',
      server: 'cloudflare',
      'cf-ray': '85a175a8eeca3d17-CDG',
      'alt-svc': 'h3=":443"; ma=86400'
    },
    trailers: {},
    opaque: null,
    body: BodyReadable {
      _readableState: [ReadableState],
      _read: [Function: bound resume],
      _events: [Object: null prototype],
      _eventsCount: 3,
      _maxListeners: undefined,
      [Symbol(kCapture)]: false,
      [Symbol(abort)]: [Function (anonymous)],
      [Symbol(kConsume)]: [Object],
      [Symbol(kBody)]: null,
      [Symbol(kContentType)]: 'text/plain; charset=UTF-8',
      [Symbol(kReading)]: false
    },
    context: undefined
  }
}

License?

Is this software available under an free software license to execute, modify, and redistribute? Thanks for your consideration.

Issue when using typescript

So I'm using topgg-autoposter with typescript and when i run tsc I get the following

node_modules/topgg-autoposter/dist/structs/BasePoster.d.ts(4,29): error TS2304: Cannot find name 'BotStats'.
node_modules/topgg-autoposter/dist/structs/DJSPoster.d.ts(16,25): error TS2304: Cannot find name 'BotStats'.
node_modules/topgg-autoposter/dist/structs/DJSSharderPoster.d.ts(16,25): error TS2304: Cannot find name 'BotStats'.
node_modules/topgg-autoposter/dist/structs/ErisPoster.d.ts(16,25): error TS2304: Cannot find name 'BotStats'.

504 Timeout Leads to Bot Crashing

Hi there, I'm using autoposter to update stats to the API. However sometimes my bot runs into 504 errors with the API, which leads to the bot crashing. Is there a way to gracefully handle this?

Thanks!

TopGGAPIError: 504 Gateway Time-out
at Api._request (/home/bot/node_modules/@top-gg/sdk/dist/structs/Api.js:76:19)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Api.postStats (/home/bot/node_modules/@top-gg/sdk/dist/structs/Api.js:99:9) {
   response: Response {
      size: 0,
      timeout: 0,
      [Symbol(Body internals)]: { body: [PassThrough], disturbed: true, error: null },
      [Symbol(Response internals)]: {
         url: 'https://top.gg/api/bots/stats',
         status: 504,
         statusText: 'Gateway Time-out',
         headers: [Headers],
         counter: 0
      }
   }
}

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.