Use @interactions.option instead of option list

This commit is contained in:
2022-12-15 01:25:56 +01:00
parent 581a9d1340
commit f0f1339555

View File

@ -7,9 +7,8 @@ from apscheduler.events import EVENT_JOB_ERROR, EVENT_JOB_MISSED
from apscheduler.jobstores.base import JobLookupError from apscheduler.jobstores.base import JobLookupError
from apscheduler.triggers.date import DateTrigger from apscheduler.triggers.date import DateTrigger
from discord_webhook import DiscordWebhook from discord_webhook import DiscordWebhook
from interactions import CommandContext, Embed, Option, OptionType, autodefer from interactions import CommandContext, Embed, OptionType, autodefer
from interactions.ext.paginator import Paginator from interactions.ext.paginator import Paginator
from discord_reminder_bot.countdown import calculate from discord_reminder_bot.countdown import calculate
from discord_reminder_bot.create_pages import create_pages from discord_reminder_bot.create_pages import create_pages
from discord_reminder_bot.parse import parse_time from discord_reminder_bot.parse import parse_time
@ -143,20 +142,9 @@ async def modal_response_edit(ctx: CommandContext, *response: str):
@autodefer() @autodefer()
@bot.command(name="parse", description="Parse the time from a string", options=[ @bot.command(name="parse", description="Parse the time from a string")
Option( @interactions.option(name="time_to_parse", description="The string you want to parse.", type=OptionType.STRING, required=True)
name="time_to_parse", @interactions.option(name="optional_timezone", description="Optional time zone, for example Europe/Stockholm", type=OptionType.STRING, required=False)
description="The string you want to parse.",
type=OptionType.STRING,
required=True,
),
Option(
name="optional_timezone",
description="Optional time zone, for example Europe/Stockholm",
type=OptionType.STRING,
required=False,
),
])
async def parse_command(ctx: interactions.CommandContext, time_to_parse: str, optional_timezone: str | None = None): async def parse_command(ctx: interactions.CommandContext, time_to_parse: str, optional_timezone: str | None = None):
""" """
Find the date and time from a string. Find the date and time from a string.
@ -217,42 +205,12 @@ async def list_command(ctx: interactions.CommandContext):
@autodefer() @autodefer()
@base_command.subcommand( @base_command.subcommand(name="add", description="Set a reminder.")
name="add", @interactions.option(name="message_reason", description="The message I'm going to send you.", type=OptionType.STRING, required=True)
description="Set a reminder.", @interactions.option(name="message_date", description="The date to send the message.", type=OptionType.STRING, required=True)
options=[ @interactions.option(name="different_channel", description="The channel to send the message to.", type=OptionType.CHANNEL, required=False)
Option( @interactions.option(name="send_dm_to_user", description="Send message to a user via DM instead of a channel. Set both_dm_and_channel to send both.", type=OptionType.USER, required=False) # noqa
name="message_reason", @interactions.option(name="both_dm_and_channel", description="Send both DM and message to the channel, needs send_dm_to_user to be set if you want both.", type=OptionType.BOOLEAN, required=False) # noqa
description="The message to send.",
type=OptionType.STRING,
required=True,
),
Option(
name="message_date",
description="The date to send the message.",
type=OptionType.STRING,
required=True,
),
Option(
name="different_channel",
description="The channel to send the message to.",
type=OptionType.CHANNEL,
required=False,
),
Option(
name="send_dm_to_user",
description="Send message to a user via DM instead of a channel. Set both_dm_and_channel to send both.",
type=OptionType.USER,
required=False,
),
Option(
name="both_dm_and_channel",
description="Send both DM and message to the channel, needs send_dm_to_user to be set if you want both.",
type=OptionType.BOOLEAN,
required=False,
),
],
)
async def command_add( async def command_add(
ctx: interactions.CommandContext, ctx: interactions.CommandContext,
message_reason: str, message_reason: str,
@ -346,105 +304,23 @@ async def send_to_user(user_id: int, guild_id: int, message: str):
@base_command.subcommand( @base_command.subcommand(
name="cron", name="cron",
description="Triggers when current time matches all specified time constraints, similarly to the UNIX cron.", description="Triggers when current time matches all specified time constraints, similarly to the UNIX cron.",
options=[
Option(
name="message_reason",
description="The message I'm going to send you.",
type=OptionType.STRING,
required=True,
),
Option(
name="year",
description="4-digit year. (Example: 2042)",
type=OptionType.STRING,
required=False,
),
Option(
name="month",
description="Month (1-12)",
type=OptionType.STRING,
required=False,
),
Option(
name="day",
description="Day of month (1-31)",
type=OptionType.STRING,
required=False,
),
Option(
name="week",
description="ISO week (1-53)",
type=OptionType.STRING,
required=False,
),
Option(
name="day_of_week",
description="Number or name of weekday (0-6 or mon,tue,wed,thu,fri,sat,sun). The first weekday is monday.",
type=OptionType.STRING,
required=False,
),
Option(
name="hour",
description="Hour (0-23)",
type=OptionType.STRING,
required=False,
),
Option(
name="minute",
description="Minute (0-59)",
type=OptionType.STRING,
required=False,
),
Option(
name="second",
description="Second (0-59)",
type=OptionType.STRING,
required=False,
),
Option(
name="start_date",
description="Earliest possible time to trigger on, in the ISO 8601 format. (Example: 2010-10-10 09:30:00)",
type=OptionType.STRING,
required=False,
),
Option(
name="end_date",
description="Latest possible time to trigger on, in the ISO 8601 format. (Example: 2010-10-10 09:30:00)",
type=OptionType.STRING,
required=False,
),
Option(
name="timezone",
description="Time zone to use for the date/time calculations (defaults to scheduler timezone)",
type=OptionType.STRING,
required=False,
),
Option(
name="jitter",
description="Delay the job execution by x seconds at most. Adds a random component to the execution time.",
type=OptionType.INTEGER,
required=False,
),
Option(
name="different_channel",
description="Send the messages to a different channel.",
type=OptionType.CHANNEL,
required=False,
),
Option(
name="send_dm_to_user",
description="Send message to a user via DM instead of a channel. Set both_dm_and_channel to send both.",
type=OptionType.USER,
required=False,
),
Option(
name="both_dm_and_channel",
description="Send both DM and message to the channel, needs send_dm_to_user to be set if you want both.",
type=OptionType.BOOLEAN,
required=False,
),
],
) )
@interactions.option(name="message_reason", description="The message I'm going to send you.", type=OptionType.STRING, required=True)
@interactions.option(name="year", description="4-digit year. (Example: 2042)", type=OptionType.STRING, required=False)
@interactions.option(name="month", description="Month. (1-12)", type=OptionType.STRING, required=False)
@interactions.option(name="day", description="Day of month (1-31)", type=OptionType.STRING, required=False)
@interactions.option(name="week", description="ISO week (1-53)", type=OptionType.STRING, required=False)
@interactions.option(name="day_of_week", description="Number or name of weekday (0-6 or mon,tue,wed,thu,fri,sat,sun).", type=OptionType.STRING, required=False) # noqa
@interactions.option(name="hour", description="Hour (0-23)", type=OptionType.STRING, required=False)
@interactions.option(name="minute", description="Minute (0-59)", type=OptionType.STRING, required=False)
@interactions.option(name="second", description="Second (0-59)", type=OptionType.STRING, required=False)
@interactions.option(name="start_date", description="Earliest possible time to trigger on, in the ISO 8601 format. (Example: 2010-10-10 09:30:00)", type=OptionType.STRING, required=False) # noqa
@interactions.option(name="end_date", description="Latest possible time to trigger on, in the ISO 8601 format. (Example: 2010-10-10 09:30:00)", type=OptionType.STRING, required=False) # noqa
@interactions.option(name="timezone", description="Time zone to use for the date/time calculations (defaults to scheduler timezone)", type=OptionType.STRING, required=False) # noqa
@interactions.option(name="jitter", description="Delay the job execution by x seconds at most. Adds a random component to the execution time.", type=OptionType.INTEGER, required=False) # noqa
@interactions.option(name="different_channel", description="Send the messages to a different channel.", type=OptionType.CHANNEL, required=False) # noqa
@interactions.option(name="send_dm_to_user", description="Send message to a user via DM instead of a channel. Set both_dm_and_channel to send both.", type=OptionType.USER, required=False) # noqa
@interactions.option(name="both_dm_and_channel", description="Send both DM and message to the channel, needs send_dm_to_user to be set if you want both.", type=OptionType.BOOLEAN, required=False) # noqa
async def remind_cron( async def remind_cron(
ctx: interactions.CommandContext, ctx: interactions.CommandContext,
message_reason: str, message_reason: str,
@ -564,91 +440,20 @@ async def remind_cron(
await ctx.send(message) await ctx.send(message)
@autodefer() @base_command.subcommand(name="interval", description="Schedules messages to be run periodically, on selected intervals.")
@base_command.subcommand( @interactions.option(name="message_reason", description="The message I'm going to send you.", type=OptionType.STRING, required=True)
name="interval", @interactions.option(name="weeks", description="Number of weeks to wait", type=OptionType.INTEGER, required=False)
description="Schedules messages to be run periodically, on selected intervals.", @interactions.option(name="days", description="Number of days to wait", type=OptionType.INTEGER, required=False)
options=[ @interactions.option(name="hours", description="Number of hours to wait", type=OptionType.INTEGER, required=False)
Option( @interactions.option(name="minutes", description="Number of minutes to wait", type=OptionType.INTEGER, required=False)
name="message_reason", @interactions.option(name="seconds", description="Number of seconds to wait", type=OptionType.INTEGER, required=False)
description="The message I'm going to send you.", @interactions.option(name="start_date", description="When to start, in the ISO 8601 format. (Example: 2010-10-10 09:30:00)", type=OptionType.STRING, required=False) # noqa
type=OptionType.STRING, @interactions.option(name="end_date", description="When to stop, in the ISO 8601 format. (Example: 2014-06-15 11:00:00)", type=OptionType.STRING, required=False) # noqa
required=True, @interactions.option(name="timezone", description="Time zone to use for the date/time calculations", type=OptionType.STRING, required=False)
), @interactions.option(name="jitter", description="Delay the job execution by x seconds at most. Adds a random component to the execution time.", type=OptionType.INTEGER, required=False) # noqa
Option( @interactions.option(name="different_channel", description="Send the messages to a different channel.", type=OptionType.CHANNEL, required=False)
name="weeks", @interactions.option(name="send_dm_to_user", description="Send message to a user via DM instead of a channel. Set both_dm_and_channel to send both.", type=OptionType.USER, required=False) # noqa
description="Number of weeks to wait", @interactions.option(name="both_dm_and_channel", description="Send both DM and message to the channel, needs send_dm_to_user to be set if you want both.", type=OptionType.BOOLEAN, required=False) # noqa
type=OptionType.INTEGER,
required=False,
),
Option(
name="days",
description="Number of days to wait",
type=OptionType.INTEGER,
required=False,
),
Option(
name="hours",
description="Number of hours to wait",
type=OptionType.INTEGER,
required=False,
),
Option(
name="minutes",
description="Number of minutes to wait",
type=OptionType.INTEGER,
required=False,
),
Option(
name="seconds",
description="Number of seconds to wait.",
type=OptionType.INTEGER,
required=False,
),
Option(
name="start_date",
description="When to start, in the ISO 8601 format. (Example: 2010-10-10 09:30:00)",
type=OptionType.STRING,
required=False,
),
Option(
name="end_date",
description="When to stop, in the ISO 8601 format. (Example: 2014-06-15 11:00:00)",
type=OptionType.STRING,
required=False,
),
Option(
name="timezone",
description="Time zone to use for the date/time calculations",
type=OptionType.STRING,
required=False,
),
Option(
name="jitter",
description="Delay the job execution by x seconds at most. Adds a random component to the execution time.",
type=OptionType.INTEGER,
required=False,
),
Option(
name="different_channel",
description="Send the messages to a different channel.",
type=OptionType.CHANNEL,
required=False,
),
Option(
name="send_dm_to_user",
description="Send message to a user via DM instead of a channel. Set both_dm_and_channel to send both.",
type=OptionType.USER,
required=False,
),
Option(
name="both_dm_and_channel",
description="Send both DM and message to the channel, needs send_dm_to_user to be set if you want both.",
type=OptionType.BOOLEAN,
required=False,
),
],
)
async def remind_interval( async def remind_interval(
ctx: interactions.CommandContext, ctx: interactions.CommandContext,
message_reason: str, message_reason: str,