Transformers
ballsdex.core.utils.transformers
This file contains discord.py transformers used to provide autocompletion, parsing and validation for various Ballsdex models.
ModelTransformer
Bases: Transformer
, Generic[T]
Base abstract class for autocompletion from on Tortoise models
Attributes:
-
name
(str
) –Name to qualify the object being listed
-
model
(T
) –The Tortoise model associated to the class derivation
get_from_pk
Return a Tortoise model instance from a primary key.
Raises:
-
KeyError | DoesNotExist
–Entry does not exist
Source code in ballsdex/core/utils/transformers.py
get_options
get_options(interaction: Interaction[BallsDexBot], value: str) -> list[Choice[int]]
Generate the list of options for autocompletion
key
validate
validate(interaction: Interaction[BallsDexBot], item: T)
A function to validate the fetched item before calling back the command.
Raises:
-
ValidationError
–Raised if the item does not pass validation with the message to be displayed
Source code in ballsdex/core/utils/transformers.py
BallInstanceTransformer
Bases: ModelTransformer[BallInstance]
key
key(model: BallInstance) -> str
TTLModelTransformer
Bases: ModelTransformer[T]
Base class for simple Tortoise model autocompletion with TTL cache.
This is used in most cases except for BallInstance which requires special handling depending on the interaction passed.
Attributes:
-
ttl
(float
) –Delay in seconds for
items
to live until refreshed withload_items
, defaults to 300
Source code in ballsdex/core/utils/transformers.py
get_from_pk
Return a Tortoise model instance from a primary key.
Raises:
-
KeyError | DoesNotExist
–Entry does not exist
Source code in ballsdex/core/utils/transformers.py
key
load_items
validate
validate(interaction: Interaction[BallsDexBot], item: T)
A function to validate the fetched item before calling back the command.
Raises:
-
ValidationError
–Raised if the item does not pass validation with the message to be displayed
Source code in ballsdex/core/utils/transformers.py
BallTransformer
Bases: TTLModelTransformer[Ball]
Source code in ballsdex/core/utils/transformers.py
get_from_pk
Return a Tortoise model instance from a primary key.
Raises:
-
KeyError | DoesNotExist
–Entry does not exist
Source code in ballsdex/core/utils/transformers.py
get_options
get_options(interaction: Interaction[BallsDexBot], value: str) -> list[Choice[int]]
Generate the list of options for autocompletion
validate
validate(interaction: Interaction[BallsDexBot], item: T)
A function to validate the fetched item before calling back the command.
Raises:
-
ValidationError
–Raised if the item does not pass validation with the message to be displayed
Source code in ballsdex/core/utils/transformers.py
BallEnabledTransformer
Bases: BallTransformer
Source code in ballsdex/core/utils/transformers.py
get_from_pk
Return a Tortoise model instance from a primary key.
Raises:
-
KeyError | DoesNotExist
–Entry does not exist
Source code in ballsdex/core/utils/transformers.py
get_options
get_options(interaction: Interaction[BallsDexBot], value: str) -> list[Choice[int]]
Generate the list of options for autocompletion
key
validate
validate(interaction: Interaction[BallsDexBot], item: T)
A function to validate the fetched item before calling back the command.
Raises:
-
ValidationError
–Raised if the item does not pass validation with the message to be displayed
Source code in ballsdex/core/utils/transformers.py
SpecialTransformer
Bases: TTLModelTransformer[Special]
Source code in ballsdex/core/utils/transformers.py
get_from_pk
Return a Tortoise model instance from a primary key.
Raises:
-
KeyError | DoesNotExist
–Entry does not exist
Source code in ballsdex/core/utils/transformers.py
get_options
get_options(interaction: Interaction[BallsDexBot], value: str) -> list[Choice[int]]
Generate the list of options for autocompletion
load_items
validate
validate(interaction: Interaction[BallsDexBot], item: T)
A function to validate the fetched item before calling back the command.
Raises:
-
ValidationError
–Raised if the item does not pass validation with the message to be displayed
Source code in ballsdex/core/utils/transformers.py
SpecialEnabledTransformer
Bases: SpecialTransformer
Source code in ballsdex/core/utils/transformers.py
get_from_pk
Return a Tortoise model instance from a primary key.
Raises:
-
KeyError | DoesNotExist
–Entry does not exist
Source code in ballsdex/core/utils/transformers.py
get_options
get_options(interaction: Interaction[BallsDexBot], value: str) -> list[Choice[int]]
Generate the list of options for autocompletion
key
validate
validate(interaction: Interaction[BallsDexBot], item: T)
A function to validate the fetched item before calling back the command.
Raises:
-
ValidationError
–Raised if the item does not pass validation with the message to be displayed
Source code in ballsdex/core/utils/transformers.py
RegimeTransformer
Bases: TTLModelTransformer[Regime]
Source code in ballsdex/core/utils/transformers.py
get_from_pk
Return a Tortoise model instance from a primary key.
Raises:
-
KeyError | DoesNotExist
–Entry does not exist
Source code in ballsdex/core/utils/transformers.py
get_options
get_options(interaction: Interaction[BallsDexBot], value: str) -> list[Choice[int]]
Generate the list of options for autocompletion
validate
validate(interaction: Interaction[BallsDexBot], item: T)
A function to validate the fetched item before calling back the command.
Raises:
-
ValidationError
–Raised if the item does not pass validation with the message to be displayed
Source code in ballsdex/core/utils/transformers.py
EconomyTransformer
Bases: TTLModelTransformer[Economy]
Source code in ballsdex/core/utils/transformers.py
get_from_pk
Return a Tortoise model instance from a primary key.
Raises:
-
KeyError | DoesNotExist
–Entry does not exist
Source code in ballsdex/core/utils/transformers.py
get_options
get_options(interaction: Interaction[BallsDexBot], value: str) -> list[Choice[int]]
Generate the list of options for autocompletion
validate
validate(interaction: Interaction[BallsDexBot], item: T)
A function to validate the fetched item before calling back the command.
Raises:
-
ValidationError
–Raised if the item does not pass validation with the message to be displayed
Source code in ballsdex/core/utils/transformers.py
TradeCommandType
Bases: Enum
If a command is using BallInstanceTransformer
for trading purposes, it should define this
enum to filter out values.