Metadata-Version: 2.5
Name: nexobots
Version: 0.3.0
Summary: Post stats and check votes on Nexobots, the Discord bot directory.
Project-URL: Homepage, https://nexobots.app
License-Expression: MIT
Requires-Python: >=3.9
Requires-Dist: aiohttp>=3.8
Description-Content-Type: text/markdown

# nexobots

Post stats and check votes on [Nexobots](https://nexobots.app), the Discord bot directory.

```bash
pip install nexobots
```

Get your API token from your bot's page in the Nexobots dashboard, and keep it in your `.env` file.

## Post your server count

```python
import os

from discord.ext import tasks
from nexobots import Nexobots

@tasks.loop(minutes=30)
async def post_stats():
    async with Nexobots(os.environ["NEXOBOTS_TOKEN"], bot.user.id) as nexobots:
        await nexobots.post_stats(server_count=len(bot.guilds), shard_count=bot.shard_count)
```

The API allows one post per 5 minutes.

## Check a vote

```python
async with Nexobots(os.environ["NEXOBOTS_TOKEN"], bot.user.id) as nexobots:
    if await nexobots.has_voted(user.id):
        ...  # Thank them.
```

## Receive vote webhooks

Pass the raw request body, before any JSON parsing.

```python
from nexobots import parse_webhook

vote = parse_webhook(os.environ["NEXOBOTS_WEBHOOK_SECRET"], raw_body, request.headers.get("X-Nexo-Signature"))
if vote is None:
    return Response(status=401)
print(f"{vote['user']} voted")
```

Errors from the API are raised as `NexobotsError`, with `status`, `code` and `message`.

## Uptime

Send a heartbeat every 5 minutes, and your bot's uptime counts on Nexobots without sharing a server with ours.

```python
asyncio.create_task(client.run_heartbeat())
```
