Automatic generation#
This documents describes mechanisms that can be used to automatically generate objects.
Shilling scheme generation#
While the framework supports to manually define a schema, which can be time consuming if you have a lot of guilds to shill into and harder to manage, the framework also supports automatic generation of the schema.
You can automatically generate the schema 2 different ways:
Using the build-in
daf.guild.AutoGUILD
anddaf.message.AutoCHANNEL
,Using PyCord (API wrapper) client,
AutoGUILD, AutoCHANNEL method#
Using this method allows you to have a completely automatically managed system of finding guilds and channels that match a specific regex pattern. It automatically finds new guilds/channels at initialization and also during normal framework operation. This is great because it means you don’t have to do much but it gives very little control of into what to shill.
Automatic GUILD generation#
For a auto-managed GUILD list, use AutoGUILD
which internally generates GUILD
instances.
Simply create a list of AutoGUILD
objects and then pass it to the framework.
It can be passed to the framework exactly the same way as GUILD
(see Quickstart (server_list
) and Dynamically adding objects).
Warning
Messages that are added to AutoGUILD
should have AutoCHANNEL
for the channels
parameters,
otherwise you will be spammed with warnings and only one guild will be shilled.
from datetime import timedelta
import daf
async def main():
# DYNAMIC DEFINITION/ADDITION
auto_guild = daf.guild.AutoGUILD(
include_pattern="David", # Regex pattern of guild names that should be included
exclude_pattern="NFT-Python", # Regex pattern of guild names that should be excluded
remove_after=None, # Never stop automatically managing guilds
messages=[], # Pre-include messages
logging=True, # The generated GUILD objects will have logging enabled
interval=timedelta(hours=1) # Scan for new guilds in a period of one hour
)
await daf.add_object(auto_guild)
await auto_guild.add_message(
daf.message.TextMESSAGE(
None, timedelta(seconds=5), "Buy our NFT today!",
daf.guild.AutoCHANNEL("shill", "promo", timedelta(seconds=60)))
)
daf.run(
token="SomeServerTokenHere",
user_callback=main,
)
Automatic channel generation#
For a auto-managed channel list use AutoCHANNEL
instances.
It can be passed to xMESSAGE objects into the channels
parameters instead of a list.
async def main():
await daf.add_object(
daf.GUILD(
snowflake=123456789,
messages=[
daf.TextMESSAGE(
None, timedelta(seconds=5), "Hello World",
channels=daf.message.AutoCHANNEL("shill", exclude_pattern="shill-[7-9]")
)
],
logging=True
)
)
PyCord scheme generation method#
This is done by using the discord.Client
object.
discord.Client
object should not be created manually as the framework automatically creates it.
To obtain the client, call daf.client.get_client()
function.
To find guilds, we will be using the discord.Client.guilds
property which will return a list of discord.Guild
objects
and then on each guild inside the list, we will be using the discord.Guild.text_channels
property which will return a list of
discord.TextChannel
objects.
Then we will use the daf.core.add_object()
function to add objects to the shilling list (Dynamically adding objects)
from datetime import timedelta
import daf
async def main():
# Get discord.Client object
client = daf.get_client()
# Iterate thru all guilds
for guild in client.guilds:
# Iterate thru all channels
channels = []
for channel in guild.text_channels:
# Channel names must contain word "shill"
if "shill" in channel.name:
channels.append(channel)
# at least one channel was found
if len(channels):
await daf.core.add_object(
daf.guild.GUILD(snowflake=guild, messages=[
daf.message.TextMESSAGE(None,
timedelta(seconds=60),
data="Hello World",
channels=channels)
]
)
)
daf.run(token="KDHJSKLJHDKAJDHS", is_user=False, user_callback=main)