Giter VIP home page Giter VIP logo

botblock / discordlists.py Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 2.0 27 KB

A simple API wrapper for botblock.org providing server count posting to all bot lists and fetching bot information from all. [Python - maintained by @MattIPv4]

Home Page: https://botblock.org/api/docs

License: MIT License

Python 100.00%
discord discord-py discord-api discord-bot discordbot discordapp api-wrapper api-client api stats stats-api statistics wrapper wrapper-api wrapper-library python python3 python-3 python-module python-library

discordlists.py's Introduction

discordlists.py

A simple API wrapper for botblock.org providing server count posting to all bot lists and fetching bot information from all.

PyPi Version GitHub Sponsors Patreon Slack


Installation

Install via pip (recommended)

python3 -m pip install discordlists.py -U

Features

  • POST server count
  • AUTOMATIC server count updating
  • ALL bot lists' APIs included
  • GET bot information from all bot lists and Discord

Example Discord.py Cogs

Posting Server Count

from discord.ext import commands

import discordlists


class DiscordListsPost(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        self.api = discordlists.Client(self.bot)  # Create a Client instance
        self.api.set_auth("bots.ondiscord.xyz", "dsag38_auth_token_fda6gs") # Set authorisation token for a bot list
        self.api.set_auth("discordbots.group", "qos56a_auth_token_gfd8g6") # Set authorisation token for a bot list
        self.api.start_loop()  # Posts the server count automatically every 30 minutes

    @commands.command()
    async def post(self, ctx: commands.Context):
        """
        Manually posts guild count using discordlists.py (BotBlock)
        """
        try:
            result = await self.api.post_count()
        except Exception as e:
            await ctx.send("Request failed: `{}`".format(e))
            return

        await ctx.send("Successfully manually posted server count ({:,}) to {:,} lists."
                       "\nFailed to post server count to {:,} lists.".format(self.api.server_count,
                                                                             len(result["success"].keys()),
                                                                             len(result["failure"].keys())))


def setup(bot):
    bot.add_cog(DiscordListsPost(bot))

Getting Bot Info

from discord.ext import commands

import discordlists


class DiscordListsGet(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        self.api = discordlists.Client(self.bot)  # Create a Client instance

    @commands.command()
    async def get(self, ctx: commands.Context, bot_id: int = None):
        """
        Gets a bot using discordlists.py (BotBlock)
        """
        if bot_id is None:
            bot_id = self.bot.user.id
        try:
            result = (await self.api.get_bot_info(bot_id))[1]
        except Exception as e:
            await ctx.send("Request failed: `{}`".format(e))
            return

        await ctx.send("Bot: {}#{} ({})\nOwners: {}\nServer Count: {}".format(
            result['username'], result['discriminator'], result['id'],
            ", ".join(result['owners']) if result['owners'] else "Unknown",
            "{:,}".format(result['server_count']) if result['server_count'] else "Unknown"
        ))


def setup(bot):
    bot.add_cog(DiscordListsGet(bot))

Contributing

Contributions are always welcome to this project!
Take a look at any existing issues on this repository for starting places to help contribute towards, or simply create your own new contribution to the project.

Please make sure to follow the existing standards within the project such as code styles, naming conventions and commenting/documentation.

When you are ready, simply create a pull request for your contribution and I will review it whenever I can!

Donating

You can also help me and the project out by sponsoring me through GitHub Sponsors (preferred), contributing through a donation on PayPal or by supporting me monthly on my Patreon page.

GitHub Sponsors Patreon PayPal

Discussion, Support and Issues

Need support with this project, have found an issue or want to chat with others about contributing to the project?

Please check the project's issues page first for support & bugs!

Not found what you need here?

  • If you have an issue, please create a GitHub issue here to report the situation, include as much detail as you can!
  • or, You can join our Slack workspace to discuss any issue, to get support for the project or to chat with contributors and myself:
Slack

discordlists.py's People

Contributors

mattipv4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

discordlists.py's Issues

Something possibly worth mentioning: discord.Client.guild_ready_timeout

https://discord.readthedocs.io/en/master/api.html#discord.Client

guild_ready_timeout is documented as The maximum number of seconds to wait for the GUILD_CREATE stream to end before preparing the member cache and firing READY. It defaults to 2 seconds, which means for very large bots (such as my own), on_ready can fire before the bot has all of the guilds and therefore will cause discordlists to report the wrong (and often much lower) guild count to the APIs.
image

maybe just mention this in the readme or setup guides? it might also be possible to use some of the code from _delay_ready() to ignore on_ready and wait for all guilds to be ready but I'm not sure how

Posting user

Discordbotlist.com has a field for user.
Is this something that can be added ?

Logging

Implement logging throughout the library using a custom logger name

  • Debug logging - Output full response from botblock every time
  • Error logging - Parse response and log error for each failure from botblock

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.