Skip to main content

Discord library built on discord.py to simplify source code by rendering templates of embeds and menus

Project description

Discord-Qalib Tests codecov Codacy Badge Python Version Gitmoji PyPI PyPI - Downloads

Discord templating engine built on discord.py, to help separate text of embeds from the source code. Inspired by Flask.


Key Features:

  • use of xml files to hold the various template responses
  • allows for pagination, in an abstract form simplifying the interface in the source code

:gear: Installing:

Python3.8 or higher is required

:test_tube: Tests

To run the tests, run the following command in the root directory:

Windows:

python -m unittest tests -v 

Linux:

python3 -m unittest tests -v

:zap: Usage

This is explained in more detail in the wiki

Wrap expressions that need to evaluated with {}, such as {player.name} or {todays_date}

Sample XML file:

<discord>
    <message key="test_key">
        <embed>
            <title>Test</title>
            <description>Test Description</description>
            <colour>magenta</colour>
            <timestamp format="%Y-%m-%d %H:%M:%S.%f">{todays_date}</timestamp>
            <url>https://www.discord.com</url>
            <fields>
                <field>
                    <name>Test Field</name>
                    <value>Test Text</value>
                </field>
            </fields>
            <footer>
                <text>Test Footer</text>
                <icon>https://cdn.discordapp.com/embed/avatars/0.png</icon>
            </footer>
            <thumbnail>https://cdn.discordapp.com/embed/avatars/0.png</thumbnail>
            <image>https://cdn.discordapp.com/embed/avatars/0.png</image>
            <author>
                <name>Test Author</name>
                <icon>https://cdn.discordapp.com/embed/avatars/0.png</icon>
                <url>https://discordapp.com</url>
            </author>
        </embed>
        <view>
            <components>
                <button key="understood_button">
                    <label>Understood</label>
                    <style>success</style>
                </button>
            </components>
        </view>
    </message>
</discord>

using the above xml file, for example, you can create an embed with the following code:

import datetime
from typing import Literal

import discord
from discord.ext import commands

import qalib
from qalib.template_engines import formatter

bot = commands.AutoShardedBot(command_prefix="!", intents=discord.Intents.all())

Messages = Literal["test_key"]


async def acknowledged(interaction: discord.Interaction):
    await interaction.response.send_message("Acknowledged", ephemeral=True)


@bot.command()
@qalib.qalib_context(formatter.Formatter(), "templates/test.xml")
async def test(ctx: qalib.QalibContext[Messages]):
    callables = {"understood_button": acknowledged}

    await ctx.rendered_send("test_key", callables, keywords={
        "todays_date": datetime.datetime.now()
    })

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

discord_qalib-2.5.10.tar.gz (30.1 kB view details)

Uploaded Source

Built Distribution

discord_qalib-2.5.10-py3-none-any.whl (39.5 kB view details)

Uploaded Python 3

File details

Details for the file discord_qalib-2.5.10.tar.gz.

File metadata

  • Download URL: discord_qalib-2.5.10.tar.gz
  • Upload date:
  • Size: 30.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for discord_qalib-2.5.10.tar.gz
Algorithm Hash digest
SHA256 064868f301d68301b65e01d49fb3a6185976c8a029072c84f4b1245c3ba5885e
MD5 eed5b4799d891bf6ed38f4d5e0bed21a
BLAKE2b-256 56b5d7418751a10080d7e5dbe865fb03b1d23470b232f6a472cc4a42c2ece5f7

See more details on using hashes here.

File details

Details for the file discord_qalib-2.5.10-py3-none-any.whl.

File metadata

File hashes

Hashes for discord_qalib-2.5.10-py3-none-any.whl
Algorithm Hash digest
SHA256 aa1a6d02e01d18c624aa1e6f2fa9870fc5ddf2d6c34be19e61843612b124be28
MD5 23fddd17c618bc70f6faf64b11ba91e2
BLAKE2b-256 a4bd21fa374c4d2605c37a9efea5973c893b926fa7bc20d74388777bd8a721ed

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page