Types#

data_function#

daf.dtypes.data_function(fnc: Callable)#

Decorator used for wrapping a function that will return data to send when the message is ready.

The fnc function must return data that is of type that the xMESSAGE object supports. If the type returned is not valid, the send attempt will simply be ignored and nothing will be logged at at, this is useful if you want to use the fnc function to control whenever the message is ready to be sent. For example: if we have a function defined like this:

@daf.data_function
def get_data():
    return None

...
daf.TextMESSAGE(..., data=get_data())
...

then no messages will ever be sent, nor will any logs be made since invalid values are simply ignored by the framework.

Parameters:

fnc (Callable) – The function to wrap.

Returns:

A class for creating wrapper objects is returned. These wrapper objects can be used as a data parameter to the Messages objects.

Return type:

FunctionCLASS

from datetime import timedelta
import  daf, datetime
from daf import discord



############################################################################################
# It's VERY IMPORTANT that you use @daf.data_function!
############################################################################################


@daf.data_function
def get_data(parameter):
    l_time = datetime.datetime.now()
    return f"Parameter: {parameter}\nTimestamp: {l_time.day}.{l_time.month}.{l_time.year} :: {l_time.hour}:{l_time.minute}:{l_time.second}"

accounts = [
    daf.ACCOUNT( # ACCOUNT 1
        "JJJKHSAJDHKJHDKJ",
        False,
        [
            daf.USER(123456789,
                     [        
                        daf.DirectMESSAGE(None, timedelta(seconds=15), get_data(123)),  
                     ],
                     True)
        ]
    ),
    daf.ACCOUNT( # ACCOUNT 2
        token="JJJKHSAJDHKJHDKJ",
        is_user=False,
        servers=[
            daf.USER(
                snowflake=123456789, # ID of server (guild) or a discord.Guild object
                messages=[         # List MESSAGE objects 
                    daf.DirectMESSAGE(
                                    start_period=None,                    # If None, messages will be send on a fixed period (end period)
                                    end_period=timedelta(seconds=15),       # If start_period is None, it dictates the fixed sending period,
                                                                            # If start period is defined, it dictates the maximum limit of randomized period
                                    data=get_data(123),                   # Data you want to sent to the function (Can be of types : str, embed, file, list of types to the left
                                                                            # or function that returns any of above types(or returns None if you don't have any data to send yet), 
                                                                            # where if you pass a function you need to use the daf.FUNCTION decorator on top of it ).
                                    mode="send",                          # "send" will send a new message every time, "edit" will edit the previous message, "clear-send" will delete
                                                                            # the previous message and then send a new one
                                    start_in=timedelta(seconds=0),        # Start sending now (True) or wait until period
                                    remove_after=None                     # Remove the message never or after n-times, after specific date or after timedelta
                                    ),  
                ],
                logging=True,       # Generate file log of sent messages (and failed attempts) for this user
                remove_after=None   # When to remove the guild and it's message from the shilling list
            )
        ]
    )
]

############################################################################################

daf.run(accounts=accounts)

FILE#

class daf.dtypes.FILE(filename: str, data: bytes | str | None = None)#

FILE object used as a data parameter to the xMESSAGE objects. This is needed opposed to a normal file object because this way, you can edit the file after the framework has already been started.

Caution

This is used for sending an actual file and NOT it’s contents as text.

Changed in version 2.10: The file’s data is loaded at file creation to support transfers over a remote connection. Additionaly this class replaces daf.dtypes.AUDIO for audio streaming.

New properties: stream, filename, data, hex.

Parameters:
  • filename (str) – The filename of file you want to send.

  • data (Optional[Union[bytes, str]]) –

    Optional raw data or hex string represending raw data.

    If this parameter is not given (set as None), the data will be automatically obtained from filename file. Defaults to None.

    New in version 2.10.

Raises:
property stream: BytesIO#

Returns a stream to data provided at creation.

property filename: str#

The name of the file

property fullpath: str#

The full path to the file

property data: bytes#

Returns the raw binary data

property hex: str#

Returns HEX representation of the data.

to_dict()#

Returns dictionary representation of this data type.

New in version 2.10.

AUDIO#

class daf.dtypes.AUDIO(filename: str)#

Used for streaming audio from file.

Deprecated since version 2.10: Use daf.dtypes.FILE instead.

Parameters:

filename (str) – Path to the file you want streamed.

Raises:
property data: bytes#

Returns the raw binary data

property filename: str#

The name of the file

property fullpath: str#

The full path to the file

property hex: str#

Returns HEX representation of the data.

property stream: BytesIO#

Returns a stream to data provided at creation.

to_dict()#

Returns dictionary representation of this data type.

New in version 2.10.