Skip to content

Commit

Permalink
Fix some deepsource code quality issues
Browse files Browse the repository at this point in the history
  • Loading branch information
joinemm committed Jul 23, 2023
1 parent c4e3bfd commit de3e83e
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 35 deletions.
4 changes: 2 additions & 2 deletions cogs/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ async def get_autoembed_options(
print(options_data)
if options_data:
return options_data
else:
return None, None

return None, None

async def parse_media_auto_embed(self, message: discord.Message, media_settings: dict):
if media_settings["instagram"]:
Expand Down
8 changes: 3 additions & 5 deletions cogs/lastfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1955,7 +1955,7 @@ def check(message):
except ValueError:
return False
else:
return num <= len(results) and num > 0
return len(results) <= num > 0
else:
return False

Expand Down Expand Up @@ -2050,7 +2050,6 @@ async def get_userinfo_embed(self, username):
async def listening_report(self, ctx: commands.Context, timeframe):
current_day_floor = arrow.utcnow().floor("day")
week = []
# for i in range(7, 0, -1):
for i in range(1, 8):
dt = current_day_floor.shift(days=-i)
week.append(
Expand Down Expand Up @@ -2107,7 +2106,6 @@ async def listening_report(self, ctx: commands.Context, timeframe):
value=f"{scrobbles_average} Scrobbles",
inline=False,
)
# content.add_field(name="Listening time", value=listening_time)
await ctx.send(embed=content)

async def get_artist_image(self, artist):
Expand Down Expand Up @@ -2233,7 +2231,7 @@ async def custom_period(self, user, group_by, shift_hours=24, limit=None):
}
}

elif group_by in ["track", "user.gettoptracks"]:
if group_by in ["track", "user.gettoptracks"]:
for track in data["recenttracks"]["track"]:
track_name = track["name"]
artist_name = track["artist"]["#text"]
Expand All @@ -2260,7 +2258,7 @@ async def custom_period(self, user, group_by, shift_hours=24, limit=None):
}
}

elif group_by in ["artist", "user.gettopartists"]:
if group_by in ["artist", "user.gettopartists"]:
for track in data["recenttracks"]["track"]:
artist_name = track["artist"]["#text"]
if artist_name in formatted_data:
Expand Down
6 changes: 0 additions & 6 deletions cogs/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,6 @@ async def confirm(self, interaction: discord.Interaction, _button: discord.ui.Bu
await interaction.response.defer()
await self.remove_ui()

# @discord.ui.button(
# label="Powered by GIPHY", style=discord.ButtonStyle.secondary, disabled=True
# )
# async def giphy_label(self, _, __):
# pass

async def remove_ui(self):
for item in self.children:
item.disabled = True # type: ignore
Expand Down
21 changes: 11 additions & 10 deletions cogs/mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import discord
from discord.ext import commands, tasks
from loguru import logger
from modules.misobot import MisoBot

from modules import exceptions, util
from modules.misobot import MisoBot


class Mod(commands.Cog):
Expand Down Expand Up @@ -178,21 +178,22 @@ async def timeout(self, ctx: commands.Context, member: discord.Member, *, durati
if duration and duration.strip().lower() == "remove":
await member.timeout(None)
return await util.send_success(ctx, f"Removed timeout from {member.mention}")

seconds = member.timeout.timestamp() - arrow.now().int_timestamp
raise exceptions.CommandInfo(
f"{member.mention} is already timed out "
f"(**{util.stringfromtime(seconds)}** remaining)",
)
else:
seconds = util.timefromstring(duration)
if seconds is None:
raise exceptions.CommandWarning(f"Invalid duration `{duration}`")
until = arrow.now().shift(seconds=+seconds).datetime

await member.timeout(until)
await util.send_success(
ctx, f"Timed out {member.mention} for **{util.stringfromtime(seconds)}**"
)
seconds = util.timefromstring(duration)
if seconds is None:
raise exceptions.CommandWarning(f"Invalid duration `{duration}`")
until = arrow.now().shift(seconds=+seconds).datetime

await member.timeout(until)
await util.send_success(
ctx, f"Timed out {member.mention} for **{util.stringfromtime(seconds)}**"
)

@commands.command()
@commands.guild_only()
Expand Down
6 changes: 3 additions & 3 deletions cogs/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import regex
from discord.ext import commands
from loguru import logger
from modules.misobot import MisoBot

from modules import emojis, exceptions, queries, util
from modules.misobot import MisoBot


class Notifications(commands.Cog):
Expand Down Expand Up @@ -271,8 +271,8 @@ async def notification_list(self, ctx: commands.Context):
"""List your current notifications"""
words = await self.bot.db.fetch(
"""
SELECT guild_id, keyword, times_triggered
FROM notification WHERE user_id = %s
SELECT guild_id, keyword, times_triggered
FROM notification WHERE user_id = %s
ORDER BY keyword
""",
ctx.author.id,
Expand Down
4 changes: 2 additions & 2 deletions cogs/owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import discord
from discord.ext import commands
from loguru import logger
from modules.misobot import MisoBot

from modules import util
from modules.misobot import MisoBot


class Owner(commands.Cog):
Expand Down Expand Up @@ -137,7 +137,7 @@ async def donator_add(

await self.bot.db.execute(
"""
INSERT INTO donator (user_id, platform, external_username,
INSERT INTO donator (user_id, platform, external_username,
donation_tier, donating_since, amount)
VALUES (%s, %s, %s, %s, %s, %s)
""",
Expand Down
1 change: 0 additions & 1 deletion cogs/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ async def weather_now(self, ctx: commands.Context, *, location: Optional[str] =
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"]
# values_tomorrow = daily_data["intervals"][1]["values"]
temperature = values_current["temperature"]
temperature_apparent = values_current["temperatureApparent"]
sunrise = arrow.get(values_current["sunriseTime"]).to(local_time.tzinfo).format("HH:mm")
Expand Down
2 changes: 1 addition & 1 deletion modules/instagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def get_url_expiry(media_url: str):

@staticmethod
def calculate_post_lifetime(media: list) -> int:
return min([m.expires for m in media]) - arrow.utcnow().int_timestamp
return min(m.expires for m in media) - arrow.utcnow().int_timestamp

async def api_request_with_cache(self, endpoint: str, params: dict) -> tuple[dict, bool, str]:
cache_key = self.make_cache_key(endpoint, params)
Expand Down
9 changes: 4 additions & 5 deletions modules/media_embedders.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,12 @@ def remove_tco(text: str) -> str:

try:
pre_text, tco = text.rsplit(maxsplit=1)
if tco.startswith("https://t.co"):
return pre_text
except ValueError:
return text
pass

if tco.startswith("https://t.co"):
return pre_text
else:
return pre_text + " " + tco
return text

@staticmethod
def extract_links(text: str, include_id_only=True):
Expand Down

0 comments on commit de3e83e

Please sign in to comment.