Change line-length to 120

This commit is contained in:
2022-07-21 20:22:27 +02:00
parent bacd689356
commit 0376ae0214
3 changed files with 22 additions and 64 deletions

View File

@ -12,13 +12,7 @@ from discord_slash.error import IncorrectFormat, RequestFailure
from discord_slash.model import SlashCommandOptionType from discord_slash.model import SlashCommandOptionType
from discord_slash.utils.manage_commands import create_choice, create_option from discord_slash.utils.manage_commands import create_choice, create_option
from discord_reminder_bot.settings import ( from discord_reminder_bot.settings import bot_token, config_timezone, log_level, scheduler, sqlite_location
bot_token,
config_timezone,
log_level,
scheduler,
sqlite_location,
)
bot = commands.Bot( bot = commands.Bot(
command_prefix="!", command_prefix="!",
@ -81,8 +75,7 @@ def calc_countdown(job) -> str:
@bot.event @bot.event
async def on_slash_command_error(ctx: SlashContext, ex: Exception): async def on_slash_command_error(ctx: SlashContext, ex: Exception):
logging.error( logging.error(
"Error occurred during the execution of" "Error occurred during the execution of" f' "/{ctx.name} {ctx.subcommand_name}" by {ctx.author}: {ex}'
f' "/{ctx.name} {ctx.subcommand_name}" by {ctx.author}: {ex}'
) )
if ex == RequestFailure: if ex == RequestFailure:
message = f"Request to Discord API failed: {ex}" message = f"Request to Discord API failed: {ex}"
@ -179,10 +172,7 @@ async def command_modify(ctx: SlashContext, time_or_message: str):
) )
# TODO: Add timeout # TODO: Add timeout
response_new_message = await bot.wait_for( response_new_message = await bot.wait_for("message", check=check)
"message",
check=check,
)
if response_new_message.clean_content == "Exit": if response_new_message.clean_content == "Exit":
return await ctx.channel.send(exit_message) return await ctx.channel.send(exit_message)
@ -195,15 +185,10 @@ async def command_modify(ctx: SlashContext, time_or_message: str):
"author_id": job.kwargs.get("author_id"), "author_id": job.kwargs.get("author_id"),
}, },
) )
msg += ( msg += f"**Old message**: {message}\n" f"**New message**: {response_new_message.clean_content}\n"
f"**Old message**: {message}\n"
f"**New message**: {response_new_message.clean_content}\n"
)
else: else:
await ctx.channel.send( await ctx.channel.send("Type the new date. Type Exit to exit.")
"Type the new date. Type Exit to exit.",
)
# TODO: Add timeout # TODO: Add timeout
response_new_date = await bot.wait_for( response_new_date = await bot.wait_for(
@ -226,10 +211,7 @@ async def command_modify(ctx: SlashContext, time_or_message: str):
date_old = job.trigger.run_date.strftime("%Y-%m-%d %H:%M") date_old = job.trigger.run_date.strftime("%Y-%m-%d %H:%M")
new_time = calc_countdown(job_from_dict) new_time = calc_countdown(job_from_dict)
msg += ( msg += f"**Old date**: {date_old} (in {old_time})\n" f"**New date**: {date_new} (in {new_time})"
f"**Old date**: {date_old} (in {old_time})\n"
f"**New date**: {date_new} (in {new_time})"
)
await ctx.send(msg) await ctx.send(msg)
@ -245,10 +227,7 @@ async def remind_remove(ctx: SlashContext):
jobs_dict = await send_list(ctx) jobs_dict = await send_list(ctx)
await ctx.channel.send( await ctx.channel.send("Type the corresponding number to the reminder you wish to remove." " Type Exit to exit.")
"Type the corresponding number to the reminder you wish to remove."
" Type Exit to exit."
)
# Only check for response from the original user and in the # Only check for response from the original user and in the
# correct channel # correct channel
@ -284,10 +263,7 @@ async def remind_remove(ctx: SlashContext):
else: else:
trigger_value = f'{trigger_time.strftime("%Y-%m-%d %H:%M")} (in {calc_countdown(job)})' trigger_value = f'{trigger_time.strftime("%Y-%m-%d %H:%M")} (in {calc_countdown(job)})'
msg = ( msg = f"**Removed** {message} in #{channel_name}.\n" f"**Time**: {trigger_value}"
f"**Removed** {message} in #{channel_name}.\n"
f"**Time**: {trigger_value}"
)
scheduler.remove_job(job_from_dict) scheduler.remove_job(job_from_dict)
@ -362,9 +338,7 @@ async def send_list(ctx, skip_datetriggers=False, skip_cron_or_interval=False):
) )
if job_number == 24: if job_number == 24:
await ctx.send( await ctx.send("I haven't added support for showing more than 25 reminders yet 🙃")
"I haven't added support for showing more than 25 reminders yet 🙃"
)
break break
# The empty embed has 76 characters # The empty embed has 76 characters
@ -395,10 +369,7 @@ async def remind_pause(ctx: SlashContext):
"""Get a list of reminders that you can pause.""" """Get a list of reminders that you can pause."""
jobs_dict = await send_list(ctx, skip_datetriggers=True) jobs_dict = await send_list(ctx, skip_datetriggers=True)
await ctx.channel.send( await ctx.channel.send("Type the corresponding number to the reminder you wish to pause." " Type Exit to exit.")
"Type the corresponding number to the reminder you wish to pause."
" Type Exit to exit."
)
# Only check for response from the original user and in the correct channel # Only check for response from the original user and in the correct channel
def check(m): def check(m):
@ -427,18 +398,11 @@ async def remind_pause(ctx: SlashContext):
# Tell user if he tries to pause a paused reminder # Tell user if he tries to pause a paused reminder
if trigger_time is None: if trigger_time is None:
return await ctx.channel.send( return await ctx.channel.send(f"{message} in #{channel_name} is already paused.")
f"{message} in #{channel_name} is already paused."
)
trigger_value = ( trigger_value = f'{trigger_time.strftime("%Y-%m-%d %H:%M")} (in {calc_countdown(job)})'
f'{trigger_time.strftime("%Y-%m-%d %H:%M")} (in {calc_countdown(job)})'
)
msg = ( msg = f"**Paused** {message} in #{channel_name}.\n" f"**Time**: {trigger_value}"
f"**Paused** {message} in #{channel_name}.\n"
f"**Time**: {trigger_value}"
)
scheduler.pause_job(job_from_dict) scheduler.pause_job(job_from_dict)
print(f"Paused {job_from_dict} in #{channel_name}") print(f"Paused {job_from_dict} in #{channel_name}")
@ -455,10 +419,7 @@ async def remind_resume(ctx: SlashContext):
# TODO: Reduce the complexity of this function # TODO: Reduce the complexity of this function
jobs_dict = await send_list(ctx, skip_datetriggers=True) jobs_dict = await send_list(ctx, skip_datetriggers=True)
await ctx.channel.send( await ctx.channel.send("Type the corresponding number to the reminder you wish to pause." " Type Exit to exit.")
"Type the corresponding number to the reminder you wish to pause."
" Type Exit to exit."
)
# Only check for response from the original user and in the correct channel # Only check for response from the original user and in the correct channel
def check(m): def check(m):
@ -473,9 +434,7 @@ async def remind_resume(ctx: SlashContext):
if int(response_message.clean_content) == num: if int(response_message.clean_content) == num:
job = scheduler.get_job(job_from_dict) job = scheduler.get_job(job_from_dict)
if job is None: if job is None:
await ctx.send( await ctx.send(f"No reminder with that ID ({job_from_dict}).")
f"No reminder with that ID ({job_from_dict}).",
)
return return
channel_id = job.kwargs.get("channel_id") channel_id = job.kwargs.get("channel_id")
@ -500,10 +459,7 @@ async def remind_resume(ctx: SlashContext):
else: else:
trigger_value = f'{trigger_time.strftime("%Y-%m-%d %H:%M")} (in {calc_countdown(job)})' trigger_value = f'{trigger_time.strftime("%Y-%m-%d %H:%M")} (in {calc_countdown(job)})'
msg = ( msg = f"**Resumed** {message} in #{channel_name}.\n" f"**Time**: {trigger_value}\n"
f"**Resumed** {message} in #{channel_name}.\n"
f"**Time**: {trigger_value}\n"
)
await ctx.send(msg) await ctx.send(msg)

View File

@ -36,5 +36,9 @@ pytest = "^7.1.2"
requires = ["poetry-core>=1.0.0"] requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api" build-backend = "poetry.core.masonry.api"
[tool.black]
line-length = 120
[tool.isort] [tool.isort]
profile = "black" profile = "black"
line_length = 120

View File

@ -55,8 +55,6 @@ class TestClass:
def test_calc_countdown(self): def test_calc_countdown(self):
"""Check if calc_countdown returns days, hours and minutes.""" """Check if calc_countdown returns days, hours and minutes."""
# FIXME: This will break when there is 0 seconds/hours/days left # FIXME: This will break when there is 0 seconds/hours/days left
pattern = re.compile( pattern = re.compile(r"\d* (day|days), \d* (hour|hours). \d* (minute|minutes)")
r"\d* (day|days), \d* (hour|hours). \d* (minute|minutes)",
)
countdown = calc_countdown(self.job) countdown = calc_countdown(self.job)
assert pattern.match(countdown) assert pattern.match(countdown)