korone.modules.utils.filters package¶
Submodules¶
- class korone.modules.utils.filters.admin.IsAdmin(client, update)[source]¶
Bases:
KoroneFilter
Filter to check if a user is an administrator.
This filter checks if a user is an administrator in a chat. It can be used to restrict access to certain commands or features.
- Parameters:
client (
hydrogram.Client
) – The client instance used to interact with the Telegram Bot API.update (
hydrogram.types.Message
orhydrogram.types.CallbackQuery
) – The update object representing the incoming message or callback query.
- client¶
- update¶
- exception korone.modules.utils.filters.command.CommandError[source]¶
Bases:
Exception
Represents an error that occurs during command processing.
CommandError is a subclass of the Exception class. It is raised when an error occurs during command processing.
- class korone.modules.utils.filters.command.CommandObject(message=None, prefix='/', command='', mention=None, args=None, regexp_match=None, magic_result=None)[source]¶
Bases:
object
Represents a command object.
CommandObject is a dataclass that represents a command object. It contains the command prefix, name, mention, arguments, regular expression match object, and magic result. It is used by the
Command
filter to store the command information. It also provides a method to parse the command from a message.- message¶
The message object.
- Type:
hydrogram.types.Message | None
- parse()[source]¶
Parse the command from the given message.
Parses the command from the given message by extracting the command prefix, name, mention, and arguments. If the command is a regular expression, the regular expression match object is stored in the command object.
- Returns:
CommandObject
– The parsed command object.- Raises:
CommandError – If no message is provided.
CommandError – If the message has no text.
- class korone.modules.utils.filters.command.Command(*values, commands=None, prefix='/', ignore_case=False, ignore_mention=False, magic=None, disableable=True)[source]¶
Bases:
KoroneFilter
A filter that matches specific commands in messages.
The
Command
class is a subclass of the Filter class. It provides functionality to match specific commands in messages. The class takes in various parameters such as commands, prefix, ignore_case, ignore_mention, and magic to customize the behavior of the filter.- Parameters:
*values (
CommandPatternType
) – Additional commands to match.commands (
typing.Sequence[CommandPatternType] | CommandPatternType | None
, optional) – Specific commands to match. Can be a single command or a sequence of commands.prefix (
str
, optional) – The prefix used before the command. Defaults to “/”.ignore_case (
bool
, optional) – Whether to ignore the case when matching commands. Defaults to False.ignore_mention (
bool
, optional) – Whether to ignore mentions when matching commands. Defaults to False.magic (
magic_filter.MagicFilter
orNone
, optional) – A magic filter to apply to the command. Defaults to None.disableable (
bool
, optional) – If the command can be disabled. Defaults to True.
- Raises:
ValueError – If the commands parameter is not a valid type.
- commands¶
- prefix¶
- ignore_case¶
- ignore_mention¶
- magic¶
- validate_prefix(command)[source]¶
Validate the prefix of the command.
Validate the prefix of the command by checking if it matches the prefix provided in the filter. If the prefix is invalid, a CommandError is raised.
- Parameters:
command (
CommandObject
) – The command object to validate.- Raises:
CommandError – If the prefix is invalid.
- async validade_mention(client, command)[source]¶
Validate the mention in the command.
Validate the mention in the command by checking if it matches the bot’s username. If the mention is invalid, a CommandError is raised.
- Parameters:
client (
hydrogram.Client
) – The client instance.command (
CommandObject
) – The command object to validate.
- Raises:
CommandError – If the mention is invalid.
- validate_command(command)[source]¶
Validate the command itself.
Validate the command itself by checking if it matches any of the allowed commands. If the command is a regular expression, the regular expression match object is stored in the command object.
- Parameters:
command (
CommandObject
) – The command object to validate.- Returns:
CommandObject
– The validated command object.- Raises:
CommandError – If the command is invalid.
- async parse_command(client, message)[source]¶
Parse the command from the message and apply necessary validations.
Parse the command from the message and apply the necessary validations such as prefix, mention, and command itself. If the command is valid, it applies the magic filter (if provided) to the command.
- Parameters:
client (
hydrogram.Client
) – The client instance.message (
hydrogram.types.Message
) – The message to parse.
- Returns:
CommandObject
– The parsed and validated command object.- Raises:
CommandError – If the command is invalid or any validation fails.
- do_magic(command)[source]¶
Apply the magic filter to the command.
The magic filter is applied to the command if the magic filter is provided and the command is valid. If the command is rejected by the magic filter, a CommandError is raised.
- Parameters:
command (
CommandObject
) – The command object to apply the magic filter to.- Returns:
CommandObject
– The command object with the magic filter applied.- Raises:
CommandError – If the command is rejected by the magic filter.
- class korone.modules.utils.filters.sudo.IsSudo(client, update)[source]¶
Bases:
KoroneFilter
Check if the user is a sudoer.
This filter checks if the user is authorized as a sudoer based on their user ID.
- Parameters:
client (
hydrogram.Client
) – The client object used for communication.update (
hydrogram.types.Message
orhydrogram.types.Message
) – The update object representing the incoming message or callback query.
- sudoers¶
- client¶
- update¶