Schema backup & Script generation (GUI)#

DAF’s graphical interface allows us to define a schema and run it directly from the GUI.

In case our plan is to advertise to a lot of servers it wouldn’t be practical if we had to re-define the schema every time we re-open the GUI. This is why DAF-GUI supports schema backup and restore and can additionally generate a core DAF Python script for shilling from the console (appropriate for servers) without needing the graphical interface.

The backups are saved into JSON files and contain definition of account objects (and it’s members such as guilds, messages), logger list and selected logger & the selected trace configuration.

Schema backup and restore#

Schema backup#

To save a schema after it has been defined, we can click on the Schema button, located in the top left corner of the Schema definition tab and then click the Save schema option.

We will be asked for a file location of the schema backup, where the GUI will save backup our schema.

../../_images/gui-schema-backup-bnt.png ../../_images/gui-schema-backup-file-save.png

Schema restore#

In case we want to restore a backed-up schema, we can click on the Schema button, located in the top left corner of the Schema definition tab and then click the Load schema option.

We will be asked for a file location of the schema backup, from which the GUI will load our schema.

../../_images/gui-schema-restore-bnt.png

Shilling script generation#

Before the graphical interface, DAF could only be run from a Python script in which everything was defined. The graphical interface makes it easier to shill for those who don’t know Python, but it also limits it’s use to a a computer capable of displaying image.

Luckily DAF-GUI allows use to create a (Python) shilling script in the event that we want to run DAF on a server 24/7.

To generate a shilling script , we can click on the Schema button, located in the top left corner of the Schema definition tab and then click the Generate script option. This will open up a file dialog asking us where to save the shilling script. After we save the location our shilling script will be generated and we can run it by using the command python <out script here>.

../../_images/gui-shill-script-gen-bnt.png

Here is an example of the shilling script generated from the above option.

Listing 5 shill_script.py - Example shilling script generated from the GUI.#
"""
Automatically generated file for Discord Advertisement Framework v2.6.0.
This can be run eg. 24/7 on a server without graphical interface.

The file has the required classes and functions imported, then the logger is defined and the
accounts list is defined.

At the bottom of the file the framework is then started with the run function.
"""

# Import the necessary items
from daf.logging._logging import LoggerJSON
from daf.logging.tracing import TraceLEVELS
from daf.client import ACCOUNT
from datetime import timedelta
from datetime import datetime
from _discord.embeds import Embed
from _discord.embeds import EmbedField
from daf.message.text_based import TextMESSAGE
from daf.guild import GUILD
from daf.message.base import AutoCHANNEL

import daf

# Define the logger
logger = LoggerJSON(path="./OutputPath/")

# Defined accounts
accounts = [
    ACCOUNT(
        token="OTM2NzM5NDMxMDczODY1Nzg5.GLSf5S.u-KirCcieqFVZHdFItvrd0S6XFB-sKj-EMb298",
        is_user=False,
        servers=[
            GUILD(
                snowflake=863071397207212052,
                messages=[
                    TextMESSAGE(
                        start_period=None,
                        end_period=timedelta(
                            seconds=10.0,
                        ),
                        data=Embed(
                            title="Test Embed Title",
                            type="rich",
                            description="This is a test embedded message description.",
                            timestamp=datetime(
                                year=2023,
                                month=4,
                                day=2,
                            ),
                            fields=[
                                EmbedField(
                                    name="Field1",
                                    value="Value1",
                                ),
                                EmbedField(
                                    name="Field2",
                                    value="Value2",
                                ),
                            ],
                        ),
                        channels=AutoCHANNEL(
                            include_pattern="shill",
                            interval=timedelta(
                                seconds=5.0,
                            ),
                        ),
                        mode="send",
                        remove_after=datetime(
                            year=2025,
                            month=1,
                            day=1,
                        ),
                    ),
                ],
                logging=True,
                remove_after=datetime(
                    year=2023,
                    month=4,
                    day=26,
                ),
            ),
        ],
    ),
]


# Run the framework (blocking)
daf.run(
    accounts=accounts,
    logger=logger,
    debug=TraceLEVELS.NORMAL
)

We can run the above file with the following command:

$ python shill_script.py

and it will produce the following output while it is running:

[2023-04-02 20:19:33.269412] (NORMAL) | daf.client: Logging in... (None)
[2023-04-02 20:19:36.016167] (NORMAL) | daf.client: Logged in as Aproksimacka (None)
[2023-04-02 20:19:36.016167] (NORMAL) | daf.core: Initialization complete. (None)

Note

The above script will run exactly the same as it would run inside the graphical interface. Graphical interface doesn’t add any functionality it self to the Discord Advertisement Framework it self, it just makes it easier to use, which means that everything that happens in the GUI, can also happen in the core library (except schema backup / restore).