Say what the problem is when error
This commit is contained in:
@ -5,6 +5,7 @@ import dateparser
|
|||||||
import interactions
|
import interactions
|
||||||
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 dateparser.conf import SettingValidationError
|
||||||
from interactions import CommandContext, Embed, Option, OptionType
|
from interactions import CommandContext, Embed, Option, OptionType
|
||||||
from interactions.ext.paginator import Paginator
|
from interactions.ext.paginator import Paginator
|
||||||
from interactions.ext.wait_for import setup
|
from interactions.ext.wait_for import setup
|
||||||
@ -84,14 +85,19 @@ async def modal_response_edit(ctx: CommandContext, *response: str):
|
|||||||
msg = f"Modified job {job_id}.\n"
|
msg = f"Modified job {job_id}.\n"
|
||||||
if old_date is not None:
|
if old_date is not None:
|
||||||
if new_date:
|
if new_date:
|
||||||
parsed_date = dateparser.parse(
|
try:
|
||||||
f"{new_date}",
|
parsed_date = dateparser.parse(
|
||||||
settings={
|
f"{new_date}",
|
||||||
"PREFER_DATES_FROM": "future",
|
settings={
|
||||||
"TIMEZONE": f"{config_timezone}",
|
"PREFER_DATES_FROM": "future",
|
||||||
"TO_TIMEZONE": f"{config_timezone}",
|
"TIMEZONE": f"{config_timezone}",
|
||||||
},
|
"TO_TIMEZONE": f"{config_timezone}",
|
||||||
)
|
},
|
||||||
|
)
|
||||||
|
except SettingValidationError as e:
|
||||||
|
return await ctx.send(f"Timezone is possible wrong?: {e}", ephemeral=True)
|
||||||
|
except ValueError as e:
|
||||||
|
return await ctx.send(f"Failed to parse date. Unknown language: {e}", ephemeral=True)
|
||||||
|
|
||||||
if not parsed_date:
|
if not parsed_date:
|
||||||
return await ctx.send("Could not parse the date.", ephemeral=True)
|
return await ctx.send("Could not parse the date.", ephemeral=True)
|
||||||
@ -108,16 +114,19 @@ async def modal_response_edit(ctx: CommandContext, *response: str):
|
|||||||
if old_message is not None:
|
if old_message is not None:
|
||||||
channel_id = job.kwargs.get("channel_id")
|
channel_id = job.kwargs.get("channel_id")
|
||||||
job_author_id = job.kwargs.get("author_id")
|
job_author_id = job.kwargs.get("author_id")
|
||||||
|
try:
|
||||||
scheduler.modify_job(
|
scheduler.modify_job(
|
||||||
job.id,
|
job.id,
|
||||||
kwargs={
|
kwargs={
|
||||||
"channel_id": channel_id,
|
"channel_id": channel_id,
|
||||||
"message": f"{new_message}",
|
"message": f"{new_message}",
|
||||||
"author_id": job_author_id,
|
"author_id": job_author_id,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
except JobLookupError as e:
|
||||||
|
return await ctx.send(
|
||||||
|
f"Failed to modify the job.\nJob ID: {job_id}\nError: {e}"
|
||||||
|
)
|
||||||
msg += f"**Old message**: {old_message}\n**New message**: {new_message}\n"
|
msg += f"**Old message**: {old_message}\n**New message**: {new_message}\n"
|
||||||
|
|
||||||
return await ctx.send(msg)
|
return await ctx.send(msg)
|
||||||
@ -189,18 +198,21 @@ async def command_add(
|
|||||||
message_reason: The message the bot should write when the reminder is triggered.
|
message_reason: The message the bot should write when the reminder is triggered.
|
||||||
different_channel: The channel the reminder should be sent to.
|
different_channel: The channel the reminder should be sent to.
|
||||||
"""
|
"""
|
||||||
parsed_date = dateparser.parse(
|
try:
|
||||||
f"{message_date}",
|
parsed_date = dateparser.parse(
|
||||||
settings={
|
f"{message_date}",
|
||||||
"PREFER_DATES_FROM": "future",
|
settings={
|
||||||
"TIMEZONE": f"{config_timezone}",
|
"PREFER_DATES_FROM": "future",
|
||||||
"TO_TIMEZONE": f"{config_timezone}",
|
"TIMEZONE": f"{config_timezone}",
|
||||||
},
|
"TO_TIMEZONE": f"{config_timezone}",
|
||||||
)
|
},
|
||||||
|
)
|
||||||
|
except SettingValidationError as e:
|
||||||
|
return await ctx.send(f"Timezone is possible wrong?: {e}", ephemeral=True)
|
||||||
|
except ValueError as e:
|
||||||
|
return await ctx.send(f"Failed to parse date. Unknown language: {e}", ephemeral=True)
|
||||||
if not parsed_date:
|
if not parsed_date:
|
||||||
await ctx.send("Could not parse the date.")
|
return await ctx.send("Could not parse the date.")
|
||||||
return
|
|
||||||
|
|
||||||
channel_id = int(ctx.channel_id)
|
channel_id = int(ctx.channel_id)
|
||||||
|
|
||||||
@ -209,15 +221,19 @@ async def command_add(
|
|||||||
channel_id = int(different_channel.id)
|
channel_id = int(different_channel.id)
|
||||||
|
|
||||||
run_date = parsed_date.strftime("%Y-%m-%d %H:%M:%S")
|
run_date = parsed_date.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
reminder = scheduler.add_job(
|
try:
|
||||||
send_to_discord,
|
reminder = scheduler.add_job(
|
||||||
run_date=run_date,
|
send_to_discord,
|
||||||
kwargs={
|
run_date=run_date,
|
||||||
"channel_id": channel_id,
|
kwargs={
|
||||||
"message": message_reason,
|
"channel_id": channel_id,
|
||||||
"author_id": ctx.member.id,
|
"message": message_reason,
|
||||||
},
|
"author_id": ctx.member.id,
|
||||||
)
|
},
|
||||||
|
)
|
||||||
|
except ValueError as e:
|
||||||
|
await ctx.send(str(e))
|
||||||
|
return
|
||||||
|
|
||||||
message = (
|
message = (
|
||||||
f"Hello {ctx.member.name},"
|
f"Hello {ctx.member.name},"
|
||||||
@ -363,28 +379,31 @@ async def remind_cron(
|
|||||||
# If we should send the message to a different channel
|
# If we should send the message to a different channel
|
||||||
if different_channel:
|
if different_channel:
|
||||||
channel_id = int(different_channel.id)
|
channel_id = int(different_channel.id)
|
||||||
|
try:
|
||||||
job = scheduler.add_job(
|
job = scheduler.add_job(
|
||||||
send_to_discord,
|
send_to_discord,
|
||||||
"cron",
|
"cron",
|
||||||
year=year,
|
year=year,
|
||||||
month=month,
|
month=month,
|
||||||
day=day,
|
day=day,
|
||||||
week=week,
|
week=week,
|
||||||
day_of_week=day_of_week,
|
day_of_week=day_of_week,
|
||||||
hour=hour,
|
hour=hour,
|
||||||
minute=minute,
|
minute=minute,
|
||||||
second=second,
|
second=second,
|
||||||
start_date=start_date,
|
start_date=start_date,
|
||||||
end_date=end_date,
|
end_date=end_date,
|
||||||
timezone=timezone,
|
timezone=timezone,
|
||||||
jitter=jitter,
|
jitter=jitter,
|
||||||
kwargs={
|
kwargs={
|
||||||
"channel_id": channel_id,
|
"channel_id": channel_id,
|
||||||
"message": message_reason,
|
"message": message_reason,
|
||||||
"author_id": ctx.member.id,
|
"author_id": ctx.member.id,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
except ValueError as e:
|
||||||
|
await ctx.send(str(e))
|
||||||
|
return
|
||||||
|
|
||||||
# TODO: Add what arguments we used in the job to the message
|
# TODO: Add what arguments we used in the job to the message
|
||||||
message = (
|
message = (
|
||||||
@ -503,25 +522,28 @@ async def remind_interval(
|
|||||||
# If we should send the message to a different channel
|
# If we should send the message to a different channel
|
||||||
if different_channel:
|
if different_channel:
|
||||||
channel_id = int(different_channel.id)
|
channel_id = int(different_channel.id)
|
||||||
|
try:
|
||||||
job = scheduler.add_job(
|
job = scheduler.add_job(
|
||||||
send_to_discord,
|
send_to_discord,
|
||||||
"interval",
|
"interval",
|
||||||
weeks=weeks,
|
weeks=weeks,
|
||||||
days=days,
|
days=days,
|
||||||
hours=hours,
|
hours=hours,
|
||||||
minutes=minutes,
|
minutes=minutes,
|
||||||
seconds=seconds,
|
seconds=seconds,
|
||||||
start_date=start_date,
|
start_date=start_date,
|
||||||
end_date=end_date,
|
end_date=end_date,
|
||||||
timezone=timezone,
|
timezone=timezone,
|
||||||
jitter=jitter,
|
jitter=jitter,
|
||||||
kwargs={
|
kwargs={
|
||||||
"channel_id": channel_id,
|
"channel_id": channel_id,
|
||||||
"message": message_reason,
|
"message": message_reason,
|
||||||
"author_id": ctx.member.id,
|
"author_id": ctx.member.id,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
except ValueError as e:
|
||||||
|
await ctx.send(str(e))
|
||||||
|
return
|
||||||
|
|
||||||
# TODO: Add what arguments we used in the job to the message
|
# TODO: Add what arguments we used in the job to the message
|
||||||
message = (
|
message = (
|
||||||
|
Reference in New Issue
Block a user