from dubious import pory¶
- The
dubious.porymodule defines the main class that will act as the bot:
Pory.- It also includes a special subclass,
ConfiguredPory, that makes per-guild (read: per-server) configuration easier.
- exception dubious.pory.CommandFailure(message: str)¶
- This class is a front-facing
Exceptionclass to be thrown when an error is made by a user of the bot.
- It will be caught by
Poryand its error_embed()method will be used to decorate an appropriate error message.- Can be subclassed to alter the
error_embed() method.
- This class is a front-facing
- class dubious.pory.Pory(app_id: dataclasses.InitVar[str], public_key: str, token: str)¶
This class defines bot functionality.
Once an instance is created, commands can be added using its
on_commandCommandGroupas a decorator around the desired callback function.Also contains various utility functions for things like sending messages to specific channels and sending followup responses to interactions.
- app_id: dataclasses.InitVar[str]¶
The application ID shown in the
General Informationsection of the application’s settings. This value is converted into aSnowflakeobject and stored inid.
- public_key: str¶
The public key shown in the
General Informationsection of the application’s settings.
- token: str¶
The token generated by the Reset Token option in the
Botsection of the application’s settings.
- on_command: CommandGroup¶
CommandGroupfor callbacks to register as Slash Commands.
- on_message: CommandGroup¶
CommandGroupfor callbacks to register as Message Commands.
- on_user: CommandGroup¶
CommandGroupfor callbacks to register as User Commands.
- on_modal: CallbackGroup¶
CallbackGroupfor internal callbacks that corespond to Modal (popup) interactions.
- on_component: CallbackGroup¶
CallbackGroupfor internal callbacks that corespond to Message Component interactions.
- flask()¶
The entry point for the app. Starts a
Flaskinstance and acceptsPOSTrequests to the/interactionsendpoint.
- send_followup(token: str, followup: Form)¶
Using an interaction message token, sends a followup response after the initial response.
Shouldn’t be used before an
on_commandcallback returns / yields.
- edit_response(token: str, edit: Form, response_id: str = '@original')¶
Using an interaction message token, edits one of the responses (specified by ID) to that interaction. Defaults to the initial response.
- delete_response(token: str, response_id: str = '@original')¶
Using an interaction message token, deletes one of the responses (specified by ID) to that interaction. Defaults to the initial response.
- send(channel_id: Snowflake, message: Form)¶
Sends a standalone message.
The argument
messageis areq.CreateMessage.Form.
- edit(channel_id: Snowflake, message_id: Snowflake, message: Form)¶
Edits a standalone message.
The argument
messageis areq.EditMessage.Form.
- history(channel_id: Snowflake, limit: int = 200, chunk_size: int = 50)¶
Iterates over a channel’s messages, starting from the earliest message.
The number of messages retrieved depends on
limit. Thereq.GetChannelMessagesrequest will retrieve a chunk of messages from the channel, the size of which is determined bychunk_size, until the limit is reached. A higher chunk size means less total requests, but those requests will take more time.
- class dubious.pory.ChannelSnowflake(r: str | int)¶
This class only serves to differentiate the type of
Snowflakethat’s stored in aConfiguredPory.config_model’s field. Represents the ID of a channel in the guild.
- class dubious.pory.RoleSnowflake(r: str | int)¶
This class only serves to differentiate the type of :class`~.disc.Snowflake` that’s stored in a
ConfiguredPory.config_model’s field. Represents the ID of a role in the guild.
- class dubious.pory.t_ConfigType¶
Represents the config dataclass used with
ConfiguredPory.alias of TypeVar(‘t_ConfigType’)
- class dubious.pory.ConfiguredPory(app_id: dataclasses.InitVar[str], public_key: str, token: str, config_path: str, config_model: type[~dubious.pory.t_ConfigType], guild_configs: dict[~dubious.discord.disc.Snowflake, ~dubious.pory.t_ConfigType] = <factory>)¶
This class adds to
Poryby wrapping aconfig_modeldataclass, storing it per guild as json in a given location, and allowing the bot to do things per guild based on that guild’s dataclass. A guild’s config dataclass instance can be retrieved usingget_current_config(). More info on defining a configuration dataclass can be found inconfig_model.It automatically registers a /config slash command that users with Manage Channel permissions can use to configure the dataclass instance for the guild they’re in.
- config_model: type[t_ConfigType]¶
The dataclass with which to structure the bot.
The dataclass won’t recieve any arguments on instantiation - each of its fields must have a default value (or default_factory for fields that store lists).
ConfiguredPorywill leaf through the dataclass’s fields to find each field that stores one of the above subclasses ofSnowflake:ChannelSnowflakeandRoleSnowflake. It will also find fields that store lists of those snowflake subclasses. For each of the snowflake fields, a subcommand group will be added to the /config slash command that coresponds to that field. Subcommands are then added to that group that will alter that field when used.
- guild_configs: dict[Snowflake, t_ConfigType]¶
The json file, parsed into instances of
config_modelper guild.
- load()¶
Reads the config file from disk.
- write()¶
Writes the current config for all guilds to the disk.
- get_current_config(guild_id: Snowflake | None)¶
Gets the
config_modelinstance for a specified guild. Ifguild_idisNone, raises an appropriateCommandFailure.This method is usually used inside of interaction callbacks. The
guild_idcan be retrieved by addingguild_idto the callback signature as a keyword-specific argument (i.e. an argument that comes after*,). Seedo_callback()for more details.