Skip to content

Commit

Permalink
Add command for admin
Browse files Browse the repository at this point in the history
  • Loading branch information
Saverio976 committed Nov 23, 2024
1 parent 1af3f3d commit 7fc21f4
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions worldtimezone/extensions/world_clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,45 @@ async def setIt_autocomplete_timezone(
)


@lightbulb.add_checks(lightbulb.human_only)
@lightbulb.add_checks(lightbulb.owner_only)
@plugin.command
@lightbulb.add_cooldown(5, 1, lightbulb.UserBucket)
@lightbulb.option("timezone", "TimeZone", type=str, required=True, autocomplete=True)
@lightbulb.option("member", "Member", type=hikari.Member, required=True)
@lightbulb.command("set_owner", description="Set your TimeZone", pass_options=True)
@lightbulb.implements(lightbulb.SlashCommand)
async def setItOwner(
ctx: lightbulb.SlashContext, timezone: str, member: hikari.Member
) -> None:
wcd = ctx.bot.d.world_clock_data # pyright: ignore[reportAny]
assert isinstance(wcd, world_clock_data.WorldClockData)
assert ctx.guild_id is not None
user = wcd.get_member(ctx.guild_id, member.id)
if user is None:
guild = wcd.get_guild(ctx.guild_id)
if guild is None:
guild = wcd.create_guild(ctx.guild_id)
user = wcd.create_member(guild, member.id)
res = wcd.set_member_tz(user, timezone)
if res is False:
_ = await ctx.respond(
f"Failed, please provide a working timezone ('{timezone}' is unknow)"
)
return
_ = await ctx.respond(f"Your TimeZone as been set for {member.display_name}!")


@setItOwner.autocomplete("timezone")
async def setIt_autocomplete_timezone(
opt, # pyright: ignore[reportUnknownParameterType, reportMissingParameterType]
inter, # pyright: ignore[reportUnknownParameterType, reportMissingParameterType, reportUnusedParameter]
):
return world_clock_data.match_timezone(
opt.value # pyright: ignore[reportUnknownArgumentType, reportUnknownMemberType]
)


@lightbulb.add_checks(lightbulb.human_only)
@plugin.command
@lightbulb.add_cooldown(5, 1, lightbulb.UserBucket)
Expand Down

0 comments on commit 7fc21f4

Please sign in to comment.