Skip to content

Commit

Permalink
Merge pull request #41 from evidencebp/main
Browse files Browse the repository at this point in the history
Pylint alerts corrections as part of an intervention experiment 40
  • Loading branch information
mralext20 authored Dec 10, 2024
2 parents 0fb79ff + 744ea1c commit f9a0868
Show file tree
Hide file tree
Showing 16 changed files with 312 additions and 275 deletions.
2 changes: 1 addition & 1 deletion alexBot/cogs/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ async def setConfig(
session.add(uc)
await session.commit()
await interaction.response.send_message(
f"Set {key} to {val}", ephemeral=False if config_type == 'guild' else True
f"Set {key} to {val}", ephemeral=config_type != 'guild'
)

@configGuildCommandGroup.command(name="show", description="shows the current config")
Expand Down
70 changes: 28 additions & 42 deletions alexBot/cogs/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ def cog_load(self):
self._old_tree_error = tree.on_error
tree.on_error = self.on_app_command_error

# -> Option 1 ---
# detaching the handler when the cog is unloaded
# this is optional for option 1
def cog_unload(self):
tree = self.bot.tree
tree.on_error = self._old_tree_error
Expand All @@ -41,7 +38,30 @@ async def on_app_command_error(self, interaction: Interaction, error: AppCommand
)

@Cog.listener()
async def on_command_error(self, ctx: commands.Context, error: commands.CommandError):
async def on_command_error(self, ctx: commands.Context, error: Exception):

error_messages = {
commands.DisabledCommand: lambda: (f'{ctx.command} has been disabled.', None),
commands.NotOwner: lambda: (f'{ctx.command} is a owner only command.', None),
commands.NoPrivateMessage: lambda: (f'{ctx.command} can not be used in Private Messages.', None),
commands.CheckFailure: lambda: ('A Check failed for this command.', None),
commands.MissingRequiredArgument: lambda: (
f'Parameter {error.param} is required but missing, See {ctx.prefix}help {ctx.command} for help!',
None,
),
commands.MissingPermissions: lambda: ('You do not have permission to run that command.', None),
commands.CommandOnCooldown: lambda: (f"{ctx.command} is being used too often, try again later", None),
commands.MaxConcurrencyReached: lambda: (
f"{ctx.command} is currently being ran. please wait for it to finish.",
None,
),
asyncio.TimeoutError: lambda: (f"timed out. you can start again with {ctx.prefix}{ctx.command}", None),
commands.BadArgument: lambda: (
f'Bad argument: {error} See {ctx.prefix}help {ctx.command} for help!',
ctx.command.reset_cooldown(ctx),
),
}

"""The event triggered when an error is raised while invoking a command."""
if isinstance(error, commands.CommandNotFound):
return
Expand All @@ -50,47 +70,13 @@ async def on_command_error(self, ctx: commands.Context, error: commands.CommandE
if isinstance(error, asyncio.TimeoutError):
msg = f"timed out. you can start again with {ctx.prefix}{ctx.command}"

if isinstance(error, commands.MaxConcurrencyReached):
if ctx.author.id == 335928292542513162 and random.random() < 0.2:
msg = "DAWN PLS"
else:
msg = f"{ctx.command} is currently being ran. please wait for it to finish."

if isinstance(error, commands.CommandOnCooldown):
if ctx.author.id == 335928292542513162 and random.random() < 0.2:
msg = "DAWN PLS"
else:
msg = f"{ctx.command} is being used too often, try again later"

if isinstance(error, commands.DisabledCommand):
msg = f'{ctx.command} has been disabled.'

elif isinstance(error, commands.NotOwner):
msg = f'{ctx.command} is a owner only command.'

elif isinstance(error, commands.NoPrivateMessage):
msg = f'{ctx.command} can not be used in Private Messages.'

elif isinstance(error, commands.BadArgument):
ctx.command.reset_cooldown(ctx)
msg = f'Bad argument: {error} See {ctx.prefix}help {ctx.command} for help!'
log.warning(f"bad argument on {ctx.command}: {error}")

elif isinstance(error, commands.CheckFailure):
msg = 'A Check failed for this command.'
if any(isinstance(error, e) for e in error_messages):
msg = error_messages[type(error)]()[0] # type: ignore # no fail because we just checked for existing keys

elif isinstance(error, commands.MissingRequiredArgument):
msg = f'Parameter {error.param} is required but missing, See {ctx.prefix}help {ctx.command} for help!'
elif isinstance(error, commands.MissingPermissions):
msg = 'You do not have permission to run that command.'
elif isinstance(error, commands.CommandInvokeError):
if isinstance(error, commands.CommandInvokeError) and isinstance(error.original, discord.Forbidden):
error = error.original

if isinstance(error, discord.Forbidden):
msg = (
'A permission error occurred while executing this command, '
'Make sure I have the required permissions and try again.'
)
msg = 'A permission error occurred while executing this command, Make sure I have the required permissions and try again.'

# post the error into the chat if no short error message could be generated
if not msg:
Expand Down
59 changes: 33 additions & 26 deletions alexBot/cogs/flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,7 @@ async def metar(self, interaction: discord.Interaction, station: str):
f"please only use this data for planning purposes."
)

magdec = None
if metar.data.wind_direction.value is not None:
declination = self.wmm.calc_mag_field(
location.latitude, location.longitude, location.elevation_ft
).declination

magdec = declination + int(metar.data.wind_direction.value) # add the magdec to the direction of the wind
if magdec > 360: # if the declaration ends up being more than 360, subtract the extra.
magdec = magdec - 360
elif magdec < 0: # same as above, but for less than 0 condition.
magdec = magdec + 360
magdec = self._compute_magdec(location, metar)

embed.title = f"{location.name}, {location.country} ({location.icao})"

Expand All @@ -74,6 +64,26 @@ async def metar(self, interaction: discord.Interaction, station: str):
if translations.clouds != "":
embed.add_field(name="Clouds", value=translations.clouds, inline=False)

self._handle_wind(metar, embed, magdec, translations)

if translations.altimeter != "":
embed.add_field(name="Altimeter", value=translations.altimeter, inline=False)

if translations.temperature != "":
embed.add_field(name="Temperature", value=translations.temperature, inline=False)

embed.add_field(name="Flight Rule", value=metar.data.flight_rules, inline=False)

if translations.visibility != "":
embed.add_field(name="Visibility", value=translations.visibility, inline=False)

embed.timestamp = metar.data.time.dt
if metar.data.flight_rules in ["LIFR", "IFR"]:
await interaction.followup.send('you might want to reconsider flying.', embed=embed)
else:
await interaction.followup.send(embed=embed)

def _handle_wind(self, metar, embed, magdec, translations):
if translations.wind is not None:
if magdec is not None:
if metar.data.wind_gust is not None:
Expand All @@ -96,22 +106,19 @@ async def metar(self, interaction: discord.Interaction, station: str):
else:
embed.add_field(name="Wind", value=translations.wind, inline=False)

if translations.altimeter != "":
embed.add_field(name="Altimeter", value=translations.altimeter, inline=False)

if translations.temperature != "":
embed.add_field(name="Temperature", value=translations.temperature, inline=False)

embed.add_field(name="Flight Rule", value=metar.data.flight_rules, inline=False)

if translations.visibility != "":
embed.add_field(name="Visibility", value=translations.visibility, inline=False)
def _compute_magdec(self, location, metar):
magdec = None
if metar.data.wind_direction.value is not None:
declination = self.wmm.calc_mag_field(
location.latitude, location.longitude, location.elevation_ft
).declination

embed.timestamp = metar.data.time.dt
if metar.data.flight_rules in ["LIFR", "IFR"]:
await interaction.followup.send('you might want to reconsider flying.', embed=embed)
else:
await interaction.followup.send(embed=embed)
magdec = declination + int(metar.data.wind_direction.value) # add the magdec to the direction of the wind
if magdec > 360: # if the declaration ends up being more than 360, subtract the extra.
magdec = magdec - 360
elif magdec < 0: # same as above, but for less than 0 condition.
magdec = magdec + 360
return magdec

@app_commands.command(name="taf")
async def taf(self, interaction: discord.Interaction, station: str):
Expand Down
1 change: 0 additions & 1 deletion alexBot/cogs/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ async def on_message(self, message: discord.Message):
)
await message.add_reaction(uploaded)
await uploaded.delete(reason="removed from temp addition")
pass

return
else:
Expand Down
28 changes: 15 additions & 13 deletions alexBot/cogs/mudae.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,19 +237,7 @@ async def extract_series(self, interaction: discord.Interaction, message: discor
# ^ captures first page
await interaction.response.send_message("tab through your liked series, i'll save them!", ephemeral=True)

while current_page < total_pages:

# get the next page
payload = await self.bot.wait_for(
"raw_message_edit",
check=lambda payload: payload.message_id == message.id,
timeout=60,
)
serieses.extend(SERIES_REGEX.findall(payload.data['embeds'][0]['description'])) # type: ignore ; checked above if embed exists
# captures pages 2 thru n
current_page += 1
if current_page == total_pages:
break
await self._scan_pages(message, serieses, current_page, total_pages)
else:
serieses.extend(SERIES_REGEX.findall(message.embeds[0].description)) # type: ignore
# captures single page
Expand All @@ -275,6 +263,20 @@ async def extract_series(self, interaction: discord.Interaction, message: discor
else:
await interaction.response.send_message(reply_text, ephemeral=True)

async def _scan_pages(self, message, serieses, current_page, total_pages):
while current_page < total_pages:
# get the next page
payload = await self.bot.wait_for(
"raw_message_edit",
check=lambda payload: payload.message_id == message.id,
timeout=60,
)
serieses.extend(SERIES_REGEX.findall(payload.data['embeds'][0]['description'])) # type: ignore ; checked above if embed exists
# captures pages 2 thru n
current_page += 1
if current_page == total_pages:
break


async def setup(bot: "Bot"):
await bot.add_cog(Mudae(bot))
Loading

0 comments on commit f9a0868

Please sign in to comment.