nextcore


Namenextcore JSON
Version 2.0.1 PyPI version JSON
download
home_pagehttps://github.com/nextsnake/nextcore
SummaryA low level Discord API wrapper
upload_time2023-07-09 22:43:20
maintainer
docs_urlNone
authortag-epic
requires_python>=3.8,<4.0
licenseMIT
keywords discord bot wrapper api
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">

  <img alt="" src="docs/_static/logo.svg" width="160px"/>
  
  # Nextcore
  <sub>A low level Discord API wrapper.</sub>
  
</div>

### ✨ Features

- #### Speed

  We try to make the library as fast as possible, without compromising on readability of the code or features.
  
- #### Modularity

  All the components can easily be swapped out with your own.

- #### Control

  Nextcore offers fine-grained control over things most libraries don't support.  
  
  This currently includes:  
  - Setting priority for individual requests
  - Swapping out components

<br>

<div align="center">

  # Examples
  
</div>

### 🏓 Ping pong
A simple "ping pong" example in nextcore.
This will respond with "pong" each time someone sends "ping" in the chat.
```py
import asyncio
from os import environ
from typing import cast

from discord_typings import MessageData

from nextcore.gateway import ShardManager
from nextcore.http import BotAuthentication, HTTPClient, Route

# Constants
AUTHENTICATION = BotAuthentication(environ["TOKEN"])

# Intents are a way to select what intents Discord should send to you.
# For a list of intents see https://discord.dev/topics/gateway#gateway-intents
GUILD_MESSAGES_INTENT = 1 << 9
MESSAGE_CONTENT_INTENT = 1 << 15

INTENTS = GUILD_MESSAGES_INTENT | MESSAGE_CONTENT_INTENT  # Guild messages and message content intents.


# Create a HTTPClient and a ShardManager.
# A ShardManager is just a neat wrapper around Shard objects.
http_client = HTTPClient()
shard_manager = ShardManager(AUTHENTICATION, INTENTS, http_client)


@shard_manager.event_dispatcher.listen("MESSAGE_CREATE")
async def on_message(message: MessageData):
    # This function will be called every time a message is sent.
    if message["content"] == "ping":
        # Send a pong message to respond.
        route = Route("POST", "/channels/{channel_id}/messages", channel_id=message["channel_id"])

        await http_client.request(
            route,
            rate_limit_key=AUTHENTICATION.rate_limit_key,
            json={"content": "pong"},
            headers=AUTHENTICATION.headers,
        )


async def main():
    await http_client.setup()

    # This should return once all shards have started to connect.
    # This does not mean they are connected.
    await shard_manager.connect()

    # Raise a error and exit whenever a critical error occurs
    (error,) = await shard_manager.dispatcher.wait_for(lambda: True, "critical")

    raise cast(Exception, error)


asyncio.run(main())
```

> More examples can be seen in the [examples](examples/) directory.

<br>

## Contributing
Want to help us out? Please read our [contributing](https://nextcore.readthedocs.io/en/latest/contributing/getting_started.html) docs.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/nextsnake/nextcore",
    "name": "nextcore",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "discord,bot,wrapper,api",
    "author": "tag-epic",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/1c/88/cad19673063056cea838cab695370c54d48e645760d312b8938510c67d33/nextcore-2.0.1.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\n\n  <img alt=\"\" src=\"docs/_static/logo.svg\" width=\"160px\"/>\n  \n  # Nextcore\n  <sub>A low level Discord API wrapper.</sub>\n  \n</div>\n\n### \u2728 Features\n\n- #### Speed\n\n  We try to make the library as fast as possible, without compromising on readability of the code or features.\n  \n- #### Modularity\n\n  All the components can easily be swapped out with your own.\n\n- #### Control\n\n  Nextcore offers fine-grained control over things most libraries don't support.  \n  \n  This currently includes:  \n  - Setting priority for individual requests\n  - Swapping out components\n\n<br>\n\n<div align=\"center\">\n\n  # Examples\n  \n</div>\n\n### \ud83c\udfd3 Ping pong\nA simple \"ping pong\" example in nextcore.\nThis will respond with \"pong\" each time someone sends \"ping\" in the chat.\n```py\nimport asyncio\nfrom os import environ\nfrom typing import cast\n\nfrom discord_typings import MessageData\n\nfrom nextcore.gateway import ShardManager\nfrom nextcore.http import BotAuthentication, HTTPClient, Route\n\n# Constants\nAUTHENTICATION = BotAuthentication(environ[\"TOKEN\"])\n\n# Intents are a way to select what intents Discord should send to you.\n# For a list of intents see https://discord.dev/topics/gateway#gateway-intents\nGUILD_MESSAGES_INTENT = 1 << 9\nMESSAGE_CONTENT_INTENT = 1 << 15\n\nINTENTS = GUILD_MESSAGES_INTENT | MESSAGE_CONTENT_INTENT  # Guild messages and message content intents.\n\n\n# Create a HTTPClient and a ShardManager.\n# A ShardManager is just a neat wrapper around Shard objects.\nhttp_client = HTTPClient()\nshard_manager = ShardManager(AUTHENTICATION, INTENTS, http_client)\n\n\n@shard_manager.event_dispatcher.listen(\"MESSAGE_CREATE\")\nasync def on_message(message: MessageData):\n    # This function will be called every time a message is sent.\n    if message[\"content\"] == \"ping\":\n        # Send a pong message to respond.\n        route = Route(\"POST\", \"/channels/{channel_id}/messages\", channel_id=message[\"channel_id\"])\n\n        await http_client.request(\n            route,\n            rate_limit_key=AUTHENTICATION.rate_limit_key,\n            json={\"content\": \"pong\"},\n            headers=AUTHENTICATION.headers,\n        )\n\n\nasync def main():\n    await http_client.setup()\n\n    # This should return once all shards have started to connect.\n    # This does not mean they are connected.\n    await shard_manager.connect()\n\n    # Raise a error and exit whenever a critical error occurs\n    (error,) = await shard_manager.dispatcher.wait_for(lambda: True, \"critical\")\n\n    raise cast(Exception, error)\n\n\nasyncio.run(main())\n```\n\n> More examples can be seen in the [examples](examples/) directory.\n\n<br>\n\n## Contributing\nWant to help us out? Please read our [contributing](https://nextcore.readthedocs.io/en/latest/contributing/getting_started.html) docs.\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A low level Discord API wrapper",
    "version": "2.0.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/nextsnake/nextcore/issues",
        "Discord": "https://discord.gg/3RFUm3eP5c",
        "Documentation": "https://nextcore.readthedocs.io",
        "Homepage": "https://github.com/nextsnake/nextcore",
        "Repository": "https://github.com/nextsnake/nextcore"
    },
    "split_keywords": [
        "discord",
        "bot",
        "wrapper",
        "api"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6d9845364378c41a4ec82b3ecb9a0ac119d36f327fe2692b77eae337075b98b4",
                "md5": "ac56ffa69dd0f2b3e4897c7e3dc121a7",
                "sha256": "3c84b0366bc2736bf36b226c07119a783a0b756184db1391bef3873cac40acc2"
            },
            "downloads": -1,
            "filename": "nextcore-2.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ac56ffa69dd0f2b3e4897c7e3dc121a7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 74203,
            "upload_time": "2023-07-09T22:43:19",
            "upload_time_iso_8601": "2023-07-09T22:43:19.045118Z",
            "url": "https://files.pythonhosted.org/packages/6d/98/45364378c41a4ec82b3ecb9a0ac119d36f327fe2692b77eae337075b98b4/nextcore-2.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1c88cad19673063056cea838cab695370c54d48e645760d312b8938510c67d33",
                "md5": "7350940dfdf71b5f180dd801710113a1",
                "sha256": "b199ed3c5a1c2dd8d32be0f6e72049fd4505812a7bab30c726d8c5a343223354"
            },
            "downloads": -1,
            "filename": "nextcore-2.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "7350940dfdf71b5f180dd801710113a1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 37286,
            "upload_time": "2023-07-09T22:43:20",
            "upload_time_iso_8601": "2023-07-09T22:43:20.753333Z",
            "url": "https://files.pythonhosted.org/packages/1c/88/cad19673063056cea838cab695370c54d48e645760d312b8938510c67d33/nextcore-2.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-09 22:43:20",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "nextsnake",
    "github_project": "nextcore",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "nextcore"
}
        
Elapsed time: 0.77231s