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,6 +85,7 @@ 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:
|
||||||
|
try:
|
||||||
parsed_date = dateparser.parse(
|
parsed_date = dateparser.parse(
|
||||||
f"{new_date}",
|
f"{new_date}",
|
||||||
settings={
|
settings={
|
||||||
@ -92,6 +94,10 @@ async def modal_response_edit(ctx: CommandContext, *response: str):
|
|||||||
"TO_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,7 +114,7 @@ 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={
|
||||||
@ -117,7 +123,10 @@ async def modal_response_edit(ctx: CommandContext, *response: str):
|
|||||||
"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,6 +198,7 @@ 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.
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
parsed_date = dateparser.parse(
|
parsed_date = dateparser.parse(
|
||||||
f"{message_date}",
|
f"{message_date}",
|
||||||
settings={
|
settings={
|
||||||
@ -197,10 +207,12 @@ async def command_add(
|
|||||||
"TO_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,6 +221,7 @@ 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")
|
||||||
|
try:
|
||||||
reminder = scheduler.add_job(
|
reminder = scheduler.add_job(
|
||||||
send_to_discord,
|
send_to_discord,
|
||||||
run_date=run_date,
|
run_date=run_date,
|
||||||
@ -218,6 +231,9 @@ async def command_add(
|
|||||||
"author_id": ctx.member.id,
|
"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,7 +379,7 @@ 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",
|
||||||
@ -385,6 +401,9 @@ async def remind_cron(
|
|||||||
"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,7 +522,7 @@ 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",
|
||||||
@ -522,6 +541,9 @@ async def remind_interval(
|
|||||||
"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