Auto objects#

AutoCHANNEL#

class daf.message.AutoCHANNEL(include_pattern: str, exclude_pattern: Optional[str] = None, interval: Optional[timedelta] = datetime.timedelta(seconds=300))#

New in version v2.3.

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 14 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.

  • 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[Union[TextChannel, VoiceChannel]]#

Property that returns a list of discord.TextChannel or discord.VoiceChannel (depends on the xMESSAGE type this is in) objects in cache.

async initialize(parent, channel_type: str)#

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

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: Union[TextChannel, 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(**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: Optional[str] = None, remove_after: Optional[Union[timedelta, datetime]] = None, messages: Optional[List[BaseMESSAGE]] = [], logging: Optional[bool] = False, interval: Optional[timedelta] = datetime.timedelta(seconds=600), auto_join: Optional[GuildDISCOVERY] = None)#

Changed in version v2.5: Added auto_join parameter.

Internally automatically creates daf.guild.GUILD objects. Can also automatically join new guilds (auto_join parameter)

Caution

Any objects passed to AutoGUILD get deep-copied meaning, those same objects will not be initialized and cannot be used to obtain/change information regarding AutoGUILD.

Listing 15 Illegal use of AutoGUILD#
auto_ch = daf.AutoCHANNEL(...)
tm = daf.TextMESSAGE(..., channels=auto_ch)

await daf.add_object(AutoGUILD(..., messages=[tm]))

auto_ch.channels # Illegal results in exception
await tm.update(...) # Illegal results in exception

To actually modify message/channel objects inside AutoGUILD, you need to iterate thru each GUILD.

Listing 16 Modifying AutoGUILD messages#
aguild = daf.AutoGUILD(..., messages=[tm])
await daf.add_object(aguild)

for guild in aguild.guilds:
    for message in guild.messages
        await message.update(...)
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.

  • 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.

  • interval (Optional[timedelta] = timedelta(minutes=10)) – Interval at which to scan for new guilds

  • 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 guilds: List[GUILD]#

Returns cached found GUILD objects.

property created_at: datetime#

Returns the datetime of when the object has been created.

property deleted: bool#

Indicates the status of deletion.

Returns:

  • True – The object is no longer in the framework and should no longer be used.

  • False – Object is in the framework in normal operation.

async initialize(parent: Any)#

Initializes the object.

Raises:

ValueError – Auto-join guild functionality requires the account to be provided with username and password.

async add_message(message: BaseMESSAGE)#

Adds a copy of the passed message to each guild inside cache.

Parameters:

message (message.BaseMESSAGE) – Message to add.

Raises:

Any – Any exception raised in daf.guild.GUILD.add_message().

remove_message(message: BaseMESSAGE)#

Removes message from the messages list.

Parameters:

message (BaseMESSAGE) – The message to remove.

Raises:

ValueError – The message is not present in the list.

async update(init_options={}, **kwargs)#

Updates the object with new initialization parameters.

Warning

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