Transformers
ballsdex.core.utils.transformers
This file contains discord.py transformers used to provide autocompletion, parsing and validation for various Ballsdex models.
ModelTransformer
ModelTransformer(**filters: Any)
Bases: Transformer, Converter
Base abstract class for autocompletion from on Django models
This also works with hybrid commands.
Attributes:
-
name(str) –Name to qualify the object being listed
-
column(str) –Column of the model to use for matching text-based conversions. Defaults to "name".
-
model(T) –The Django model associated to the class derivation
-
base(int) –The base in which database IDs are converted. Defaults to decimal (10).
Parameters:
-
**filters(Any, default:{}) –Filters to apply on the model before providing options.
Source code in ballsdex/core/utils/transformers.py
get_from_pk
get_from_pk(value: int) -> T
Return a Django model instance from a primary key.
Raises:
-
KeyError | DoesNotExist–Entry does not exist
Source code in ballsdex/core/utils/transformers.py
get_from_text
get_from_text(value: str) -> T
Return a Django model instance from the raw value entered.
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
key(model: T) -> str
validate
validate(ctx: Context[BallsDexBot], item: T)
A function to validate the fetched item before calling back the command.
Raises:
-
BadArgument–Raised if the item does not pass validation with the message to be displayed
Source code in ballsdex/core/utils/transformers.py
BallInstanceTransformer
BallInstanceTransformer(**filters: Any)
Bases: ModelTransformer[BallInstance]
Source code in ballsdex/core/utils/transformers.py
key
key(model: T) -> str
TTLModelTransformer
TTLModelTransformer(**filters: Any)
Bases: ModelTransformer[T]
Base class for simple Django 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
itemsto live until refreshed withload_items, defaults to 300
Source code in ballsdex/core/utils/transformers.py
get_from_pk
get_from_pk(value: int) -> T
Return a Django model instance from a primary key.
Raises:
-
KeyError | DoesNotExist–Entry does not exist
Source code in ballsdex/core/utils/transformers.py
get_from_text
get_from_text(value: str) -> T
Return a Django model instance from the raw value entered.
Raises:
-
KeyError | DoesNotExist–Entry does not exist
Source code in ballsdex/core/utils/transformers.py
key
key(model: T) -> str
load_items
load_items() -> Iterable[T]
validate
validate(ctx: Context[BallsDexBot], item: T)
A function to validate the fetched item before calling back the command.
Raises:
-
BadArgument–Raised if the item does not pass validation with the message to be displayed
Source code in ballsdex/core/utils/transformers.py
BallTransformer
BallTransformer(**filters: Any)
Bases: TTLModelTransformer[Ball]
Source code in ballsdex/core/utils/transformers.py
get_from_pk
get_from_pk(value: int) -> T
Return a Django model instance from a primary key.
Raises:
-
KeyError | DoesNotExist–Entry does not exist
Source code in ballsdex/core/utils/transformers.py
get_from_text
get_from_text(value: str) -> T
Return a Django model instance from the raw value entered.
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
key(model: T) -> str
load_items
load_items() -> Iterable[T]
validate
validate(ctx: Context[BallsDexBot], item: T)
A function to validate the fetched item before calling back the command.
Raises:
-
BadArgument–Raised if the item does not pass validation with the message to be displayed
Source code in ballsdex/core/utils/transformers.py
SpecialTransformer
SpecialTransformer(**filters: Any)
Bases: TTLModelTransformer[Special]
Source code in ballsdex/core/utils/transformers.py
get_from_pk
get_from_pk(value: int) -> T
Return a Django model instance from a primary key.
Raises:
-
KeyError | DoesNotExist–Entry does not exist
Source code in ballsdex/core/utils/transformers.py
get_from_text
get_from_text(value: str) -> T
Return a Django model instance from the raw value entered.
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
key(model: T) -> str
load_items
load_items() -> Iterable[T]
validate
validate(ctx: Context[BallsDexBot], item: T)
A function to validate the fetched item before calling back the command.
Raises:
-
BadArgument–Raised if the item does not pass validation with the message to be displayed
Source code in ballsdex/core/utils/transformers.py
RegimeTransformer
RegimeTransformer(**filters: Any)
Bases: TTLModelTransformer[Regime]
Source code in ballsdex/core/utils/transformers.py
get_from_pk
get_from_pk(value: int) -> T
Return a Django model instance from a primary key.
Raises:
-
KeyError | DoesNotExist–Entry does not exist
Source code in ballsdex/core/utils/transformers.py
get_from_text
get_from_text(value: str) -> T
Return a Django model instance from the raw value entered.
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
key(model: T) -> str
load_items
load_items() -> Iterable[T]
validate
validate(ctx: Context[BallsDexBot], item: T)
A function to validate the fetched item before calling back the command.
Raises:
-
BadArgument–Raised if the item does not pass validation with the message to be displayed
Source code in ballsdex/core/utils/transformers.py
EconomyTransformer
EconomyTransformer(**filters: Any)
Bases: TTLModelTransformer[Economy]
Source code in ballsdex/core/utils/transformers.py
get_from_pk
get_from_pk(value: int) -> T
Return a Django model instance from a primary key.
Raises:
-
KeyError | DoesNotExist–Entry does not exist
Source code in ballsdex/core/utils/transformers.py
get_from_text
get_from_text(value: str) -> T
Return a Django model instance from the raw value entered.
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
key(model: T) -> str
load_items
load_items() -> Iterable[T]
validate
validate(ctx: Context[BallsDexBot], item: T)
A function to validate the fetched item before calling back the command.
Raises:
-
BadArgument–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.