Skip to content

Commit

Permalink
'Refactored by Sourcery'
Browse files Browse the repository at this point in the history
  • Loading branch information
SourceryAI committed Mar 17, 2021
1 parent 275ad8c commit ddacb20
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 111 deletions.
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"]:
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)))
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]


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)))
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)

@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:
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:
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())
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
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())
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

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)


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)
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

@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 (
"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

@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

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

@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"]
)

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

0 comments on commit ddacb20

Please sign in to comment.