Skip to content

Commit

Permalink
Update linting rules
Browse files Browse the repository at this point in the history
  • Loading branch information
joinemm committed Jun 1, 2023
1 parent 96190e8 commit a1dcaa8
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 53 deletions.
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ repos:
rev: 23.3.0
hooks:
- id: black
args: [--line-length=99]
args: [--line-length=100]
language_version: python3

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.270
hooks:
- id: ruff
args: [--line-length=100, --ignore=E501]

- repo: https://github.com/pycqa/isort
rev: 5.12.0
Expand Down
8 changes: 2 additions & 6 deletions cogs/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,7 @@ async def deleted_ignore(self, ctx: commands.Context, *, channel: discord.TextCh
ctx.guild.id,
channel.id,
)
await util.send_success(
ctx, f"No longer logging any messages deleted in {channel.mention}"
)
await util.send_success(ctx, f"No longer logging any messages deleted in {channel.mention}")

@logger_deleted.command(name="unignore")
async def deleted_unignore(self, ctx: commands.Context, *, channel: discord.TextChannel):
Expand Down Expand Up @@ -716,9 +714,7 @@ async def blacklist_command(self, ctx: commands.Context, *, command):
@commands.is_owner()
async def blacklist_global(self, ctx: commands.Context, user: discord.User, *, reason):
"""Blacklist someone globally from Miso Bot"""
await self.bot.db.execute(
"INSERT IGNORE blacklisted_user VALUES (%s, %s)", user.id, reason
)
await self.bot.db.execute("INSERT IGNORE blacklisted_user VALUES (%s, %s)", user.id, reason)
self.bot.cache.blacklist["global"]["user"].add(user.id)
await util.send_success(ctx, f"**{user}** can no longer use Miso Bot!")

Expand Down
12 changes: 5 additions & 7 deletions cogs/errorhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ def __init__(self, bot):
self.bot: MisoBot = bot

@staticmethod
def log_format(
ctx: commands.Context, error: Exception | None, message: str | None = None
):
def log_format(ctx: commands.Context, error: Exception | None, message: str | None = None):
return f"{ctx.guild} @ {ctx.author} : {ctx.message.content} => {type(error).__name__}: {message or str(error)}"

async def reinvoke_command(self, ctx: commands.Context):
Expand Down Expand Up @@ -97,7 +95,9 @@ async def send_lastfm_error(self, ctx: commands.Context, error: exceptions.LastF
case 8:
message = "There was a problem connecting to LastFM servers. LastFM might be down. Try again later."
case 17:
message = "Unable to get listening information. Please check you LastFM privacy settings."
message = (
"Unable to get listening information. Please check you LastFM privacy settings."
)
case 29:
message = "LastFM rate limit exceeded. Please try again later."
case _:
Expand Down Expand Up @@ -248,9 +248,7 @@ async def on_command_error(self, ctx: commands.Context, error_wrapper: commands.
await self.send_warning(ctx, error.message)

case _:
await self.send_error(
ctx, f"{type(error).__name__}: {error}", error, language="ex"
)
await self.send_error(ctx, f"{type(error).__name__}: {error}", error, language="ex")
logger.opt(exception=error).error("Unhandled exception traceback:")


Expand Down
16 changes: 4 additions & 12 deletions cogs/lastfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1439,9 +1439,7 @@ async def server_topartists(self, ctx: commands.Context, *args):
if member is None:
continue

tasks.append(
self.get_server_top(lastfm_username, "artist", period=arguments["period"])
)
tasks.append(self.get_server_top(lastfm_username, "artist", period=arguments["period"]))

if tasks:
data = await asyncio.gather(*tasks)
Expand Down Expand Up @@ -2214,9 +2212,7 @@ async def custom_period(self, user, group_by, shift_hours=24):
"image": track["image"],
}

albumsdata = sorted(
formatted_data.values(), key=lambda x: x["playcount"], reverse=True
)
albumsdata = sorted(formatted_data.values(), key=lambda x: x["playcount"], reverse=True)
return {
"topalbums": {
"album": albumsdata,
Expand All @@ -2241,9 +2237,7 @@ async def custom_period(self, user, group_by, shift_hours=24):
"image": track["image"],
}

tracksdata = sorted(
formatted_data.values(), key=lambda x: x["playcount"], reverse=True
)
tracksdata = sorted(formatted_data.values(), key=lambda x: x["playcount"], reverse=True)
return {
"toptracks": {
"track": tracksdata,
Expand All @@ -2266,9 +2260,7 @@ async def custom_period(self, user, group_by, shift_hours=24):
"image": track["image"],
}

artistdata = sorted(
formatted_data.values(), key=lambda x: x["playcount"], reverse=True
)
artistdata = sorted(formatted_data.values(), key=lambda x: x["playcount"], reverse=True)
return {
"topartists": {
"artist": artistdata,
Expand Down
4 changes: 1 addition & 3 deletions cogs/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,7 @@ async def notification_list(self, ctx: commands.Context):
rows.append(f"**{guild}** : `{keyword}` - Triggered **{times_triggered}** times")

try:
await util.send_as_pages(
ctx, content, rows, maxpages=1, maxrows=50, send_to=ctx.author
)
await util.send_as_pages(ctx, content, rows, maxpages=1, maxrows=50, send_to=ctx.author)
except discord.errors.Forbidden:
raise exceptions.CommandWarning(
"I was unable to send you a DM! Please change your settings."
Expand Down
9 changes: 2 additions & 7 deletions cogs/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,7 @@ async def colorme(self, ctx: commands.Context, hex_color: str):
existing_role_id: int | None = dict(existing_roles).get(str(color))
color_role = ctx.guild.get_role(existing_role_id) if existing_role_id else None

if old_roles := list(
filter(lambda r: r.id in existing_roles_ids, ctx.author.roles)
):
if old_roles := list(filter(lambda r: r.id in existing_roles_ids, ctx.author.roles)):
await ctx.author.remove_roles(*old_roles, atomic=True, reason="Changed color")

# remove manually deleted roles
Expand All @@ -216,7 +214,6 @@ async def colorme(self, ctx: commands.Context, hex_color: str):
)

if color_role is None:

# create a new role
color_role = await ctx.guild.create_role(
name=str(color),
Expand Down Expand Up @@ -364,9 +361,7 @@ async def rolepicker_list(self, ctx: commands.Context):
title=f":scroll: Available roles in {ctx.guild.name}",
color=int("ffd983", 16),
)
if rows := [
f"`{role_name}` : <@&{role_id}>" for role_name, role_id in sorted(data)
]:
if rows := [f"`{role_name}` : <@&{role_id}>" for role_name, role_id in sorted(data)]:
await util.send_as_pages(ctx, content, rows)
else:
content.description = "Nothing yet!"
Expand Down
8 changes: 2 additions & 6 deletions cogs/typings.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ def obfuscate(self, text):
return "".join(letter_dict.get(letter, letter) for letter in text)

def anticheat(self, message):
remainder = "".join(
set(message.content).intersection(self.font + "".join(self.separators))
)
remainder = "".join(set(message.content).intersection(self.font + "".join(self.separators)))
return remainder != ""

@commands.group()
Expand Down Expand Up @@ -261,9 +259,7 @@ def progress_check(_message):
)
return player, 0, 0
await message.add_reaction("✅")
await self.save_wpm(
message.author, ctx.guild, wpm, accuracy, wordcount, language, True
)
await self.save_wpm(message.author, ctx.guild, wpm, accuracy, wordcount, language, True)
return player, wpm, accuracy

@typing.command(name="history")
Expand Down
13 changes: 5 additions & 8 deletions cogs/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,7 @@ async def weather_now(self, ctx: commands.Context, *, location: Optional[str] =

data = await response.json(loads=orjson.loads)

current_data = next(
filter(lambda t: t["timestep"] == "current", data["data"]["timelines"])
)
current_data = next(filter(lambda t: t["timestep"] == "current", data["data"]["timelines"]))
daily_data = next(filter(lambda t: t["timestep"] == "1d", data["data"]["timelines"]))
values_current = current_data["intervals"][0]["values"]
values_today = daily_data["intervals"][0]["values"]
Expand All @@ -412,14 +410,13 @@ async def weather_now(self, ctx: commands.Context, *, location: Optional[str] =
icon = self.weather_constants["id_to_icon"][str(values_current["weatherCode"])]
summary = self.weather_constants["id_to_description"][str(values_current["weatherCode"])]

if (
values_today["precipitationType"] != 0
and values_today["precipitationProbability"] != 0
):
if values_today["precipitationType"] != 0 and values_today["precipitationProbability"] != 0:
precipitation_type = self.weather_constants["precipitation"][
str(values_today["precipitationType"])
]
summary += f", with {values_today['precipitationProbability']}% chance of {precipitation_type}"
summary += (
f", with {values_today['precipitationProbability']}% chance of {precipitation_type}"
)

content = discord.Embed(color=int("e1e8ed", 16))
content.title = f":flag_{country_code.lower()}: {address}"
Expand Down
4 changes: 1 addition & 3 deletions modules/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,9 +553,7 @@ async def get_textchannel(ctx, argument, fallback=None, guildfilter=None):
except commands.errors.BadArgument:
return fallback
else:
result = discord.utils.find(
lambda m: argument in (m.name, m.id), guildfilter.text_channels
)
result = discord.utils.find(lambda m: argument in (m.name, m.id), guildfilter.text_channels)
return result or fallback


Expand Down

0 comments on commit a1dcaa8

Please sign in to comment.