Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dbltools/dbltools.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ async def on_member_join(self, member: discord.Member):
await self.bot.wait_until_ready()
await self._ready_event.wait()
config = await self.config.all()
if not member.guild.id == config["support_server_role"]["guild_id"]:
if member.guild.id != config["support_server_role"]["guild_id"]:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DblTools.on_member_join refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

return
if not config["support_server_role"]["role_id"]:
return
Expand Down Expand Up @@ -445,7 +445,7 @@ async def listdblvotes(self, ctx: commands.Context):
votes = []
for user_id, value in votes_count.most_common():
user = self.bot.get_user(int(user_id))
votes.append((user if user else user_id, humanize_number(value)))
votes.append((user or user_id, humanize_number(value)))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DblTools.listdblvotes refactored with the following changes:

msg = tabulate(votes, tablefmt="orgtbl")
embeds = []
pages = 1
Expand Down
2 changes: 1 addition & 1 deletion dbltools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


def check_weekend():
return True if datetime.today().weekday() in [4, 5, 6] else False
return datetime.today().weekday() in [4, 5, 6]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function check_weekend refactored with the following changes:



async def download_widget(session: aiohttp.ClientSession, url: str):
Expand Down
2 changes: 1 addition & 1 deletion dbltoolslite/dbltools.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ async def listdblvotes(self, ctx: commands.Context):
votes = []
for user_id, value in votes_count.most_common():
user = self.bot.get_user(int(user_id))
votes.append((user if user else user_id, humanize_number(value)))
votes.append((user or user_id, humanize_number(value)))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DblToolsLite.listdblvotes refactored with the following changes:

msg = tabulate(votes, tablefmt="orgtbl")
embeds = []
pages = 1
Expand Down
130 changes: 52 additions & 78 deletions fivem/fivem.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,86 +153,60 @@ async def _change_bot_status(self):
@commands.group()
async def fivemset(self, ctx: commands.Context):
"""Commands group for FiveM cog."""
if not ctx.invoked_subcommand:
# Logic from Trusty's welcome.py https://github.com/TrustyJAID/Trusty-cogs/blob/master/welcome/welcome.py#L71
# TODO This is just a first approach to show current settings.
settings = await self.config.get_raw()
settings_name = dict(
toggled="Custom status toggled:",
ip="FiveM IP address:",
text="Custom status text:",
status="Custom status:",
activity_type="Activity type:",
streamer="Streamer:",
stream_title="Stream title:",
if ctx.invoked_subcommand:
return
# Logic from Trusty's welcome.py https://github.com/TrustyJAID/Trusty-cogs/blob/master/welcome/welcome.py#L71
# TODO This is just a first approach to show current settings.
settings = await self.config.get_raw()
settings_name = dict(
toggled="Custom status toggled:",
ip="FiveM IP address:",
text="Custom status text:",
status="Custom status:",
activity_type="Activity type:",
streamer="Streamer:",
stream_title="Stream title:",
)
if ctx.channel.permissions_for(ctx.me).embed_links:
em = discord.Embed(
color=await ctx.embed_colour(), title=f"FiveM settings for {self.bot.user}"
)
if ctx.channel.permissions_for(ctx.me).embed_links:
em = discord.Embed(
color=await ctx.embed_colour(), title=f"FiveM settings for {self.bot.user}"
)
msg = ""
for attr, name in settings_name.items():
if attr == "toggled":
if settings[attr]:
msg += f"**{name}** Yes\n"
else:
msg += f"**{name}** No\n"
elif attr == "ip":
if settings[attr]:
msg += f"**{name}** {inline(settings[attr])}\n"
else:
msg += f"**{name}** Not set\n"
elif attr == "text":
if settings[attr]:
msg += f"**{name}**\n{inline(settings[attr])}\n"
else:
msg += f"**{name}** Not set\n"
elif attr == "streamer":
if settings[attr]:
msg += f"**{name}** {inline(settings[attr])}\n"
else:
msg += f"**{name}** Not set\n"
elif attr == "stream_title":
if settings[attr]:
msg += f"**{name}** {inline(settings[attr])}\n"
else:
msg += f"**{name}** Not set\n"
else:
msg = ""
for attr, name in settings_name.items():
if attr in ["ip", "streamer", "stream_title"]:
if settings[attr]:
msg += f"**{name}** {inline(settings[attr])}\n"
em.description = msg
await ctx.send(embed=em)
else:
msg = "```\n"
for attr, name in settings_name.items():
if attr == "toggled":
if settings[attr]:
msg += f"{name} Yes\n"
else:
msg += f"{name} No\n"
elif attr == "ip":
if settings[attr]:
msg += f"{name} {settings[attr]}\n"
else:
msg += f"{name} Not set\n"
elif attr == "text":
if settings[attr]:
msg += f"{name}\n{settings[attr]}\n"
else:
msg += f"{name} Not set\n"
elif attr == "streamer":
if settings[attr]:
msg += f"{name} {settings[attr]}\n"
else:
msg += f"**{name}** Not set\n"
elif attr == "stream_title":
if settings[attr]:
msg += f"{name} {settings[attr]}\n"
else:
msg += f"{name} Not set\n"
else:
msg += f"**{name}** Not set\n"
elif attr == "text":
if settings[attr]:
msg += f"**{name}**\n{inline(settings[attr])}\n"
else:
msg += f"**{name}** Not set\n"
elif attr == "toggled":
msg += f"**{name}** Yes\n" if settings[attr] else f"**{name}** No\n"
else:
msg += f"**{name}** {inline(settings[attr])}\n"
em.description = msg
await ctx.send(embed=em)
else:
msg = "```\n"
for attr, name in settings_name.items():
if attr in ["ip", "stream_title"]:
msg += f"{name} {settings[attr]}\n" if settings[attr] else f"{name} Not set\n"
elif attr == "streamer":
if settings[attr]:
msg += f"{name} {settings[attr]}\n"
msg += "```"
await ctx.send(msg)
else:
msg += f"**{name}** Not set\n"
elif attr == "text":
msg += f"{name}\n{settings[attr]}\n" if settings[attr] else f"{name} Not set\n"
elif attr == "toggled":
msg += f"{name} Yes\n" if settings[attr] else f"{name} No\n"
else:
msg += f"{name} {settings[attr]}\n"
msg += "```"
await ctx.send(msg)
Comment on lines -156 to +209
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FiveM.fivemset refactored with the following changes:


@fivemset.command()
async def ip(self, ctx: commands.Context, *, ip: str):
Expand Down Expand Up @@ -283,7 +257,7 @@ async def status(self, ctx: commands.Context, *, status: str):
- dnd
"""
statuses = ["online", "dnd", "idle"]
if not status.lower() in statuses:
if status.lower() not in statuses:
Comment on lines -286 to +260
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FiveM.status refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

await ctx.send_help()
return

Expand All @@ -301,7 +275,7 @@ async def activitytype(self, ctx: commands.Context, *, activity: str):
- listening
"""
activity_types = ["playing", "watching", "listening"]
if not activity.lower() in activity_types:
if activity.lower() not in activity_types:
Comment on lines -304 to +278
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FiveM.activitytype refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

await ctx.send_help()
return

Expand Down
2 changes: 1 addition & 1 deletion grafana/grafana.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async def graph(
f"panelId={params['panelId']}&fullscreen&orgId={params['orgId']}"
f"&from={params['from']}&to={params['to']}"
)
filename = "&".join([f"{k}={v}" for k, v in params.items()])
filename = "&".join(f"{k}={v}" for k, v in params.items())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Grafana.graph refactored with the following changes:

return await ctx.send(msg, file=discord.File(file, filename=f"graph-{filename}.png"))

@graph.command(name="list")
Expand Down
9 changes: 6 additions & 3 deletions martools/listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ async def on_command_error(self, ctx, error, unhandled_by_cog=False):
if hasattr(ctx.command, "on_error"):
return

if ctx.cog:
if commands.Cog._get_overridden_method(ctx.cog.cog_command_error) is not None:
return
if (
ctx.cog
and commands.Cog._get_overridden_method(ctx.cog.cog_command_error)
is not None
):
return
Comment on lines -24 to +29
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Listeners.on_command_error refactored with the following changes:

if isinstance(error, commands.CommandInvokeError):
self.upsert("command_error")

Expand Down
8 changes: 2 additions & 6 deletions martools/marttools.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,7 @@ async def bankstats(self, ctx: commands.Context):
member_account = await bank.get_account(ctx.author)
created_at = str(member_account.created_at)
no = "1970-01-01 00:00:00"
overall = 0
for key, value in accounts.items():
overall += value["balance"]

overall = sum(value["balance"] for key, value in accounts.items())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MartTools.bankstats refactored with the following changes:

em = discord.Embed(color=await ctx.embed_colour())
em.set_author(name=_("{} stats:").format(bank_name), icon_url=icon)
em.add_field(
Expand Down Expand Up @@ -560,12 +557,11 @@ async def serversregions(self, ctx: commands.Context, sort: str = "guilds"):
regions[region]["guilds"] += 1

def sort_keys(key: str):
keys = (
return (
(key[1]["guilds"], key[1]["users"])
if sort != "users"
else (key[1]["users"], key[1]["guilds"])
)
return keys
Comment on lines -563 to -568
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MartTools.serversregions.sort_keys refactored with the following changes:


regions_stats = dict(sorted(regions.items(), key=lambda x: sort_keys(x), reverse=True))

Expand Down
3 changes: 1 addition & 2 deletions nsfw/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ def emoji():
"\N{BANANA}",
"\N{KISS MARK}",
]
emoji = choice(EMOJIS)
return emoji
return choice(EMOJIS)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function emoji refactored with the following changes:



REDDIT_BASEURL = "https://api.reddit.com/r/{}/random"
Expand Down
3 changes: 1 addition & 2 deletions randimages/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ async def _get_others_imgs(
except json.decoder.JSONDecodeError as exception:
await self._api_errors_msg(ctx, error_code=exception)
return None
data = dict(img=img_data, fact=fact_data)
return data
return dict(img=img_data, fact=fact_data)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Core._get_others_imgs refactored with the following changes:

except aiohttp.client_exceptions.ClientConnectionError:
await self._api_errors_msg(ctx, error_code="JSON decode failed")
return None
Expand Down
30 changes: 15 additions & 15 deletions spacex/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,11 @@ async def _history_texts(data: dict):
if data["links"]["reddit"] is not None
else "",
}
description = (
"Date: **{date}**\n" "{flight_num}" "Links: **{article}{wikipedia}{reddit}**"
return (
"Date: **{date}**\n"
"{flight_num}"
"Links: **{article}{wikipedia}{reddit}**"
).format(**description_kwargs)
return description
Comment on lines -165 to -168
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Core._about_cog._history_texts refactored with the following changes:


@staticmethod
async def _launchpads_texts(data: dict):
Expand All @@ -183,7 +184,7 @@ async def _launchpads_texts(data: dict):
"vehicles": ", ".join(data["vehicles_launched"]),
"site_name_ext": data["site_name_long"],
}
description = (
return (
Comment on lines -186 to +187
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Core._about_cog._launchpads_texts refactored with the following changes:

"Status: **{status}**\n"
"Region: **{region}**\n"
"Location: **{location}**\n"
Expand All @@ -193,7 +194,6 @@ async def _launchpads_texts(data: dict):
"Vehicle{s} launched: **{vehicles}**\n"
"Site name long: **{site_name_ext}**"
).format(**description_kwargs)
return description

@staticmethod
async def _landpads_texts(data: dict):
Expand All @@ -209,14 +209,13 @@ async def _landpads_texts(data: dict):
long=data["location"]["longitude"],
),
}
description = (
return (
"Status: **{status}**\n"
"Landing type: **{landing_t}**\n"
"Attempted landings: **{att_lands}**\n"
"Success landings: **{succ_lands}**\n"
"Location: **{location}**"
).format(**description_kwargs)
return description
Comment on lines -212 to -219
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Core._about_cog._landpads_texts refactored with the following changes:


@staticmethod
async def _missions_texts(data: dict):
Expand All @@ -228,12 +227,11 @@ async def _missions_texts(data: dict):
if data["twitter"] is not None
else "",
}
description = (
return (
data["description"]
+ "\n**[Wikipedia page]({})**".format(data["wikipedia"])
+ "{website}{twitter}"
).format(**description_kwargs)
return description
Comment on lines -231 to -236
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Core._about_cog._missions_texts refactored with the following changes:


async def _roadster_texts(self, data: dict):
date, delta = await self._unix_convert(data["launch_date_unix"])
Expand All @@ -249,14 +247,13 @@ async def _roadster_texts(self, data: dict):
"m_distance_km": round(data["mars_distance_km"], 2),
"m_distance_mi": round(data["mars_distance_mi"], 2),
}
roadster_stats = (
return (
"Launch date: **{launch_date} {ago} ago**\n"
"Launch mass: **{mass_kg:,} kg / {mass_lbs:,} lbs**\n"
"Actual speed: **{speed_km:,} km/h / {speed_mph:,} mph**\n"
"Earth distance: **{e_distance_km:,} km / {e_distance_mi:,} mi**\n"
"Mars distance: **{m_distance_km:,} km / {m_distance_mi:,} mi**\n"
).format(**roadster_stats_kwargs)
return roadster_stats
Comment on lines -252 to -259
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Core._about_cog._roadster_texts refactored with the following changes:


@staticmethod
async def _rockets_texts(data: dict):
Expand Down Expand Up @@ -315,11 +312,14 @@ async def _rockets_texts(data: dict):
"Fuel amount: **{sec_fuel_amount} tons**\n"
"Burn time: **{sec_burn_time} secs**\n"
).format(**stages_stats_kwargs)
payload_weights_stats = ""
for p in data["payload_weights"]:
payload_weights_stats += (
"Name: **{p_name}**\n" "Weight: **{kg_mass:,} kg / {lb_mass:,} lbs**\n"
payload_weights_stats = "".join(
(
"Name: **{p_name}**\n"
"Weight: **{kg_mass:,} kg / {lb_mass:,} lbs**\n"
).format(p_name=p["name"], kg_mass=p["kg"], lb_mass=p["lb"])
for p in data["payload_weights"]
)

Comment on lines -318 to +322
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Core._about_cog._rockets_texts refactored with the following changes:

  • Use str.join() instead of for loop (use-join)

engines_stats_kwargs = {
"number": data["engines"]["number"],
"type": data["engines"]["type"],
Expand Down