Auto objects#

AutoCHANNEL#

class daf.message.AutoCHANNEL(include_pattern: str, exclude_pattern: str | None = None)#

New in version v2.3.

Changed in version v2.10: daf.message.AutoCHANNEL.remove() will now prevent the channel from being readded again.

Used for creating instances of automatically managed channels. The objects created with this will automatically add new channels at creation and dynamically while the framework is already running, if they match the patterns.

Listing 13 Usage#
# TextMESSAGE is used here, but works for others too
daf.message.TextMESSAGE(
     ..., # Other parameters
     channels=daf.message.AutoCHANNEL(...)
 )
Parameters:
  • include_pattern (str) –

    Regex pattern to match for the channel to be considered.

    For example you can do write .* to match ALL channels you are joined into or specify (parts of) channel names separated with | like so: “name1|name2|name3|name4”

  • exclude_pattern (str) –

    Regex pattern to match for the channel to be excluded from the consideration.

    Note

    If both include_pattern and exclude_pattern yield a match, the guild will be excluded from match.

  • interval (Optional[timedelta] = timedelta(minutes=5)) – Interval at which to scan for new channels.

property channels: List[TextChannel | Thread | VoiceChannel]#

Return a list of found channels

async initialize(parent, channel_getter: Callable)#

Initializes async parts of the instance. This method should be called by parent.

Changed in version v2.10: Changed the channel channel_type into channel_getter, which is now a function that can be used to get a list of all the correct channels.

Parameters:
  • parent (message.BaseMESSAGE) – The message object this AutoCHANNEL instance is in.

  • channel_type (str) – The channel type to look for when searching for channels

remove(channel: TextChannel | Thread | VoiceChannel)#

Removes channel from cache.

Parameters:

channel (Union[discord.TextChannel, discord.VoiceChannel]) – The channel to remove from cache.

Raises:

KeyError – The channel is not in cache.

async update(init_options=None, **kwargs)#

Updates the object with new initialization parameters.

Parameters:

kwargs (Any) – Any number of keyword arguments that appear in the object initialization.

Raises:

Any – Raised from initialize() method.

AutoGUILD#

class daf.guild.AutoGUILD(include_pattern: str, exclude_pattern: str | None = None, remove_after: timedelta | datetime | None = None, messages: List[TextMESSAGE | VoiceMESSAGE] | None = None, logging: bool | None = False, auto_join: GuildDISCOVERY | None = None, invite_track: List[str] | None = None, removal_buffer_length: int = 50)#

Changed in version v3.0:

  • Now works like GUILD and USER.

  • Removed created_at property.

Represents multiple guilds (servers) based on a text pattern.

Parameters:
  • include_pattern (str) –

    Regex pattern to use for searching guild names that are to be included. This is also checked before joining a new guild if auto_guild is given.

    For example you can do write .* to match ALL guilds you are joined into or specify (parts of) guild names separated with | like so: “name1|name2|name3|name4”

  • exclude_pattern (Optional[str] = None) –

    Regex pattern to use for searching guild names that are NOT to be excluded.

    Note

    If both include_pattern and exclude_pattern yield a match, the guild will be excluded from match.

  • remove_after (Optional[Union[timedelta, datetime]] = None) – When to remove this object from the shilling list.

  • logging (Optional[bool] = False) – Set to True if you want the guilds generated to log sent messages.

  • auto_join (Optional[web.GuildDISCOVERY] = None) –

    New in version v2.5.

    Optional GuildDISCOVERY object which will automatically discover and join guilds though the browser. This will open a Google Chrome session.

property removed_messages: List[BaseMESSAGE]#

Returns a list of messages that were removed from server (last removal_buffer_length messages).

property messages: List[TextMESSAGE | VoiceMESSAGE]#

New in version 3.0.

Returns all the (initialized) message objects.

property guilds: List[Guild]#

Returns cached discord.Guild objects.

property remove_after: datetime | None#

Returns the timestamp at which AutoGUILD will be removed or None if it will never be removed.

add_message(message: BaseMESSAGE) Future#

Adds a message to the message list.

Warning

To use this method, the guild must already be added to the framework’s shilling list (or initialized).

This is an asynchronous API operation. When returning from this function, the action is not immediately executed.

Parameters:

message (BaseMESSAGE) – Message object to add.

Returns:

An awaitable object which can be used to await for execution to finish. To wait for the execution to finish, use await like so: await method_name().

Return type:

Awaitable

Raises:
  • TypeError – Raised when the message is not of type the guild allows.

  • Other – Raised from message.initialize() method.

remove_message(message: BaseMESSAGE) Future#

Removes a message from the message list.

Changed in version 3.0: The function is now async.

This is an asynchronous API operation. When returning from this function, the action is not immediately executed.

Parameters:

message (BaseMESSAGE) – Message object to remove.

Returns:

An awaitable object which can be used to await for execution to finish. To wait for the execution to finish, use await like so: await method_name().

Return type:

Awaitable

Raises:
  • TypeError – Raised when the message is not of type the guild allows.

  • ValueError – Raised when the message is not present in the list.

update(init_options=None, **kwargs) Future#

Updates the object with new initialization parameters.

This is an asynchronous API operation. When returning from this function, the action is not immediately executed.

Returns:

  • Awaitable – An awaitable object which can be used to await for execution to finish. To wait for the execution to finish, use await like so: await method_name().

  • .. WARNING:: – After calling this method the entire object is reset (this includes it’s GUILD objects in cache).

async initialize(parent: Any, event_ctrl: EventController)#

Initializes the object.