Stateless component manager for hikari with type-safe API.
Project description
Flare
Stateless component manager for hikari with type-safe API.
Example
import flare
import hikari
@flare.button(label="Test Button", style=hikari.ButtonStyle.PRIMARY)
async def test_button(
ctx: flare.Context,
) -> None:
await ctx.respond(content="Hello World!")
@flare.button(label="State Button", style=hikari.ButtonStyle.PRIMARY)
async def state_button(
ctx: flare.Context,
# Args and kwargs are used for state.
number: int,
) -> None:
await ctx.respond(content=f"The number is: {number}")
bot = hikari.GatewayBot("...")
flare.install(bot)
@bot.listen()
async def buttons(event: hikari.GuildMessageCreateEvent) -> None:
# Ignore other bots or webhooks pinging us
if not event.is_human:
return
me = bot.get_me()
# If the bot is mentioned
if me.id in event.message.user_mentions_ids:
# Set custom state for components that need it
row = await flare.Row(test_button(), state_button(5))
message = await event.message.respond("Hello Flare!", component=row)
bot.run()
The API can also be accessed at a lower level if components need typed attributes.
class Button(flare.Button):
a: int
b: str
async def callback(self, ctx: flare.Context) -> None:
typing_extensions.reveal_type(self.a) # int
typing_extensions.reveal_type(self.b) # str
await ctx.respond("Hello flare!")
Converters
Converters allow you to serialize and deserialize types. Here in an example of an int converter.
Converters for int
, str
, typing.Literal
, and enum.Enum
are built in.
class IntConverter(Converter[int]):
async def to_str(self, obj: int) -> str:
return str(obj)
async def from_str(self, obj: str) -> int:
return int(obj)
flare.add_converter(
int, # The typehint this converter is used for.
IntConverter # The converter class.
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
hikari-flare-0.1.0b1.tar.gz
(31.7 kB
view hashes)
Built Distribution
Close
Hashes for hikari_flare-0.1.0b1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f96f41c999df75170f4e0a0ba4786991556f9f8925d05d485d6e79eb004329b |
|
MD5 | 2455f31b3508deb24619a86c326ef063 |
|
BLAKE2b-256 | f958545250a9c7d0eabb6b3721d150fbfc5c510d30b920056bf70c6f8a4c9c7a |