Skip to content

Commit

Permalink
Fix typing
Browse files Browse the repository at this point in the history
  • Loading branch information
novanai committed Feb 19, 2024
1 parent e4144a5 commit 3e654f7
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
TOKEN = os.environ.get("TOKEN") # required
DEBUG = os.environ.get("DEBUG", False)

CHANNEL_IDS = {"lobby": "627542044390457350"}
CHANNEL_IDS: dict[str, int] = {"lobby": 627542044390457350}
10 changes: 3 additions & 7 deletions src/extensions/boosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
hikari.MessageType.USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3,
]

BOOST_MESSAGE_TYPES: list[hikari.MessageType] = BOOST_TIERS + [
hikari.MessageType.USER_PREMIUM_GUILD_SUBSCRIPTION,
]
BOOST_MESSAGE_TYPES: list[hikari.MessageType] = BOOST_TIERS + [hikari.MessageType.USER_PREMIUM_GUILD_SUBSCRIPTION]


def build_boost_message(
Expand All @@ -26,9 +24,7 @@ def build_boost_message(
assert message_type in BOOST_MESSAGE_TYPES

base_message = f"{booster_user.display_name} just boosted the server"
multiple_boosts_message = (
f" **{number_of_boosts}** times" if number_of_boosts else ""
)
multiple_boosts_message = f" **{number_of_boosts}** times" if number_of_boosts else ""

message = base_message + multiple_boosts_message + "!"

Expand All @@ -40,7 +36,7 @@ def build_boost_message(


@plugin.listen()
async def on_message(event: hikari.GuildMessageCreateEvent):
async def on_message(event: hikari.GuildMessageCreateEvent) -> None:
if event.message.type not in BOOST_MESSAGE_TYPES:
return

Expand Down
14 changes: 3 additions & 11 deletions src/extensions/hello_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,10 @@ async def options(
ctx: arc.GatewayContext,
option_str: arc.Option[str, arc.StrParams("A string option")],
option_int: arc.Option[int, arc.IntParams("An integer option")],
option_attachment: arc.Option[
hikari.Attachment, arc.AttachmentParams("An attachment option")
],
option_attachment: arc.Option[hikari.Attachment, arc.AttachmentParams("An attachment option")],
) -> None:
"""A command with lots of options"""
embed = hikari.Embed(
title="There are a lot of options here",
description="Maybe too many",
colour=0x5865F2,
)
embed = hikari.Embed(title="There are a lot of options here", description="Maybe too many", colour=0x5865F2)
embed.set_image(option_attachment)
embed.add_field("String option", option_str, inline=False)
embed.add_field("Integer option", str(option_int), inline=False)
Expand All @@ -52,9 +46,7 @@ async def options(
async def components(ctx: arc.GatewayContext) -> None:
"""A command with components"""
builder = ctx.client.rest.build_message_action_row()
select_menu = builder.add_text_menu(
"select_me", placeholder="I wonder what this does", min_values=1, max_values=2
)
select_menu = builder.add_text_menu("select_me", placeholder="I wonder what this does", min_values=1, max_values=2)
for opt in ("Select me!", "No, select me!", "Select me too!"):
select_menu.add_option(opt, opt)

Expand Down
8 changes: 4 additions & 4 deletions src/extensions/uptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

@plugin.include
@arc.slash_command("uptime", "Show formatted uptime of Blockbot")
async def uptime(ctx):
async def uptime(ctx: arc.GatewayContext) -> None:
up_time = datetime.now() - start_time
d = up_time.days
h, ms = divmod(up_time.seconds, 3600)
m, s = divmod(ms, 60)

def format(val, str):
return f"{val} {str}{'s' if val != 1 else ''}"
def format(val: int, type_: str):
return f"{val} {type_}{'s' if val != 1 else ''}"

message_parts = [(d, "day"), (h, "hour"), (m, "minute"), (s, "second")]
formatted_parts = [format(val, str) for val, str in message_parts if val]
Expand All @@ -25,5 +25,5 @@ def format(val, str):


@arc.loader
def loader(client):
def loader(client: arc.GatewayClient) -> None:
client.add_plugin(plugin)
34 changes: 11 additions & 23 deletions src/extensions/user_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,11 @@ async def add_role(
assert ctx.member

if int(role) in ctx.member.role_ids:
return await ctx.respond(
f"You already have the {role_mention(role)} role.",
flags=hikari.MessageFlag.EPHEMERAL,
)
await ctx.respond(f"You already have the {role_mention(role)} role.", flags=hikari.MessageFlag.EPHEMERAL)
return

await ctx.client.rest.add_role_to_member(
ctx.guild_id, ctx.author, int(role), reason="Self-service role."
)
await ctx.respond(
f"Done! Added {role_mention(role)} to your roles.",
flags=hikari.MessageFlag.EPHEMERAL,
)
await ctx.client.rest.add_role_to_member(ctx.guild_id, ctx.author, int(role), reason="Self-service role.")
await ctx.respond(f"Done! Added {role_mention(role)} to your roles.", flags=hikari.MessageFlag.EPHEMERAL)


@role.include
Expand All @@ -48,18 +41,13 @@ async def remove_role(
assert ctx.member

if int(role) not in ctx.member.role_ids:
return await ctx.respond(
f"You don't have the {role_mention(role)} role.",
flags=hikari.MessageFlag.EPHEMERAL,
)
await ctx.respond(f"You don't have the {role_mention(role)} role.", flags=hikari.MessageFlag.EPHEMERAL)
return

await ctx.client.rest.remove_role_from_member(
ctx.guild_id, ctx.author, int(role), reason=f"{ctx.author} removed role."
)
await ctx.respond(
f"Done! Removed {role_mention(role)} from your roles.",
flags=hikari.MessageFlag.EPHEMERAL,
)
await ctx.respond(f"Done! Removed {role_mention(role)} from your roles.", flags=hikari.MessageFlag.EPHEMERAL)


@role.set_error_handler
Expand All @@ -68,15 +56,15 @@ async def role_error_handler(ctx: arc.GatewayContext, exc: Exception) -> None:
assert role is not None

if isinstance(exc, hikari.ForbiddenError):
return await ctx.respond(
await ctx.respond(
f"❌ Blockbot is not permitted to self-service the {role_mention(role)} role.",
flags=hikari.MessageFlag.EPHEMERAL,
)
return

if isinstance(exc, hikari.NotFoundError):
return await ctx.respond(
"❌ Blockbot can't find that role.", flags=hikari.MessageFlag.EPHEMERAL
)
await ctx.respond("❌ Blockbot can't find that role.", flags=hikari.MessageFlag.EPHEMERAL)
return

raise exc

Expand Down
6 changes: 4 additions & 2 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
from arc import GatewayClient


async def get_guild(client: GatewayClient, event: hikari.GuildMessageCreateEvent):
async def get_guild(
client: GatewayClient, event: hikari.GuildMessageCreateEvent
) -> hikari.GatewayGuild | hikari.RESTGuild:
return event.get_guild() or await client.rest.fetch_guild(event.guild_id)


def role_mention(role_id: hikari.Snowflake | int | str):
def role_mention(role_id: hikari.Snowflake | int | str) -> str:
return f"<@&{role_id}>"

0 comments on commit 3e654f7

Please sign in to comment.