Skip to content

Commit c9847d3

Browse files
committed
'Refactored by Sourcery'
1 parent 219e83d commit c9847d3

File tree

10 files changed

+82
-111
lines changed

10 files changed

+82
-111
lines changed

dbltools/dbltools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ async def on_member_join(self, member: discord.Member):
158158
await self.bot.wait_until_ready()
159159
await self._ready_event.wait()
160160
config = await self.config.all()
161-
if not member.guild.id == config["support_server_role"]["guild_id"]:
161+
if member.guild.id != config["support_server_role"]["guild_id"]:
162162
return
163163
if not config["support_server_role"]["role_id"]:
164164
return
@@ -445,7 +445,7 @@ async def listdblvotes(self, ctx: commands.Context):
445445
votes = []
446446
for user_id, value in votes_count.most_common():
447447
user = self.bot.get_user(int(user_id))
448-
votes.append((user if user else user_id, humanize_number(value)))
448+
votes.append((user or user_id, humanize_number(value)))
449449
msg = tabulate(votes, tablefmt="orgtbl")
450450
embeds = []
451451
pages = 1

dbltools/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727

2828
def check_weekend():
29-
return True if datetime.today().weekday() in [4, 5, 6] else False
29+
return datetime.today().weekday() in [4, 5, 6]
3030

3131

3232
async def download_widget(session: aiohttp.ClientSession, url: str):

dbltoolslite/dbltools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ async def listdblvotes(self, ctx: commands.Context):
223223
votes = []
224224
for user_id, value in votes_count.most_common():
225225
user = self.bot.get_user(int(user_id))
226-
votes.append((user if user else user_id, humanize_number(value)))
226+
votes.append((user or user_id, humanize_number(value)))
227227
msg = tabulate(votes, tablefmt="orgtbl")
228228
embeds = []
229229
pages = 1

fivem/fivem.py

Lines changed: 52 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -153,86 +153,60 @@ async def _change_bot_status(self):
153153
@commands.group()
154154
async def fivemset(self, ctx: commands.Context):
155155
"""Commands group for FiveM cog."""
156-
if not ctx.invoked_subcommand:
157-
# Logic from Trusty's welcome.py https://github.com/TrustyJAID/Trusty-cogs/blob/master/welcome/welcome.py#L71
158-
# TODO This is just a first approach to show current settings.
159-
settings = await self.config.get_raw()
160-
settings_name = dict(
161-
toggled="Custom status toggled:",
162-
ip="FiveM IP address:",
163-
text="Custom status text:",
164-
status="Custom status:",
165-
activity_type="Activity type:",
166-
streamer="Streamer:",
167-
stream_title="Stream title:",
156+
if ctx.invoked_subcommand:
157+
return
158+
# Logic from Trusty's welcome.py https://github.com/TrustyJAID/Trusty-cogs/blob/master/welcome/welcome.py#L71
159+
# TODO This is just a first approach to show current settings.
160+
settings = await self.config.get_raw()
161+
settings_name = dict(
162+
toggled="Custom status toggled:",
163+
ip="FiveM IP address:",
164+
text="Custom status text:",
165+
status="Custom status:",
166+
activity_type="Activity type:",
167+
streamer="Streamer:",
168+
stream_title="Stream title:",
169+
)
170+
if ctx.channel.permissions_for(ctx.me).embed_links:
171+
em = discord.Embed(
172+
color=await ctx.embed_colour(), title=f"FiveM settings for {self.bot.user}"
168173
)
169-
if ctx.channel.permissions_for(ctx.me).embed_links:
170-
em = discord.Embed(
171-
color=await ctx.embed_colour(), title=f"FiveM settings for {self.bot.user}"
172-
)
173-
msg = ""
174-
for attr, name in settings_name.items():
175-
if attr == "toggled":
176-
if settings[attr]:
177-
msg += f"**{name}** Yes\n"
178-
else:
179-
msg += f"**{name}** No\n"
180-
elif attr == "ip":
181-
if settings[attr]:
182-
msg += f"**{name}** {inline(settings[attr])}\n"
183-
else:
184-
msg += f"**{name}** Not set\n"
185-
elif attr == "text":
186-
if settings[attr]:
187-
msg += f"**{name}**\n{inline(settings[attr])}\n"
188-
else:
189-
msg += f"**{name}** Not set\n"
190-
elif attr == "streamer":
191-
if settings[attr]:
192-
msg += f"**{name}** {inline(settings[attr])}\n"
193-
else:
194-
msg += f"**{name}** Not set\n"
195-
elif attr == "stream_title":
196-
if settings[attr]:
197-
msg += f"**{name}** {inline(settings[attr])}\n"
198-
else:
199-
msg += f"**{name}** Not set\n"
200-
else:
174+
msg = ""
175+
for attr, name in settings_name.items():
176+
if attr in ["ip", "streamer", "stream_title"]:
177+
if settings[attr]:
201178
msg += f"**{name}** {inline(settings[attr])}\n"
202-
em.description = msg
203-
await ctx.send(embed=em)
204-
else:
205-
msg = "```\n"
206-
for attr, name in settings_name.items():
207-
if attr == "toggled":
208-
if settings[attr]:
209-
msg += f"{name} Yes\n"
210-
else:
211-
msg += f"{name} No\n"
212-
elif attr == "ip":
213-
if settings[attr]:
214-
msg += f"{name} {settings[attr]}\n"
215-
else:
216-
msg += f"{name} Not set\n"
217-
elif attr == "text":
218-
if settings[attr]:
219-
msg += f"{name}\n{settings[attr]}\n"
220-
else:
221-
msg += f"{name} Not set\n"
222-
elif attr == "streamer":
223-
if settings[attr]:
224-
msg += f"{name} {settings[attr]}\n"
225-
else:
226-
msg += f"**{name}** Not set\n"
227-
elif attr == "stream_title":
228-
if settings[attr]:
229-
msg += f"{name} {settings[attr]}\n"
230-
else:
231-
msg += f"{name} Not set\n"
232179
else:
180+
msg += f"**{name}** Not set\n"
181+
elif attr == "text":
182+
if settings[attr]:
183+
msg += f"**{name}**\n{inline(settings[attr])}\n"
184+
else:
185+
msg += f"**{name}** Not set\n"
186+
elif attr == "toggled":
187+
msg += f"**{name}** Yes\n" if settings[attr] else f"**{name}** No\n"
188+
else:
189+
msg += f"**{name}** {inline(settings[attr])}\n"
190+
em.description = msg
191+
await ctx.send(embed=em)
192+
else:
193+
msg = "```\n"
194+
for attr, name in settings_name.items():
195+
if attr in ["ip", "stream_title"]:
196+
msg += f"{name} {settings[attr]}\n" if settings[attr] else f"{name} Not set\n"
197+
elif attr == "streamer":
198+
if settings[attr]:
233199
msg += f"{name} {settings[attr]}\n"
234-
msg += "```"
235-
await ctx.send(msg)
200+
else:
201+
msg += f"**{name}** Not set\n"
202+
elif attr == "text":
203+
msg += f"{name}\n{settings[attr]}\n" if settings[attr] else f"{name} Not set\n"
204+
elif attr == "toggled":
205+
msg += f"{name} Yes\n" if settings[attr] else f"{name} No\n"
206+
else:
207+
msg += f"{name} {settings[attr]}\n"
208+
msg += "```"
209+
await ctx.send(msg)
236210

237211
@fivemset.command()
238212
async def ip(self, ctx: commands.Context, *, ip: str):
@@ -283,7 +257,7 @@ async def status(self, ctx: commands.Context, *, status: str):
283257
- dnd
284258
"""
285259
statuses = ["online", "dnd", "idle"]
286-
if not status.lower() in statuses:
260+
if status.lower() not in statuses:
287261
await ctx.send_help()
288262
return
289263

@@ -301,7 +275,7 @@ async def activitytype(self, ctx: commands.Context, *, activity: str):
301275
- listening
302276
"""
303277
activity_types = ["playing", "watching", "listening"]
304-
if not activity.lower() in activity_types:
278+
if activity.lower() not in activity_types:
305279
await ctx.send_help()
306280
return
307281

grafana/grafana.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ async def graph(
8080
f"panelId={params['panelId']}&fullscreen&orgId={params['orgId']}"
8181
f"&from={params['from']}&to={params['to']}"
8282
)
83-
filename = "&".join([f"{k}={v}" for k, v in params.items()])
83+
filename = "&".join(f"{k}={v}" for k, v in params.items())
8484
return await ctx.send(msg, file=discord.File(file, filename=f"graph-{filename}.png"))
8585

8686
@graph.command(name="list")

martools/listeners.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ async def on_command_error(self, ctx, error, unhandled_by_cog=False):
2121
if hasattr(ctx.command, "on_error"):
2222
return
2323

24-
if ctx.cog:
25-
if commands.Cog._get_overridden_method(ctx.cog.cog_command_error) is not None:
26-
return
24+
if (
25+
ctx.cog
26+
and commands.Cog._get_overridden_method(ctx.cog.cog_command_error)
27+
is not None
28+
):
29+
return
2730
if isinstance(error, commands.CommandInvokeError):
2831
self.upsert("command_error")
2932

martools/marttools.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,7 @@ async def bankstats(self, ctx: commands.Context):
174174
member_account = await bank.get_account(ctx.author)
175175
created_at = str(member_account.created_at)
176176
no = "1970-01-01 00:00:00"
177-
overall = 0
178-
for key, value in accounts.items():
179-
overall += value["balance"]
180-
177+
overall = sum(value["balance"] for key, value in accounts.items())
181178
em = discord.Embed(color=await ctx.embed_colour())
182179
em.set_author(name=_("{} stats:").format(bank_name), icon_url=icon)
183180
em.add_field(
@@ -560,12 +557,11 @@ async def serversregions(self, ctx: commands.Context, sort: str = "guilds"):
560557
regions[region]["guilds"] += 1
561558

562559
def sort_keys(key: str):
563-
keys = (
560+
return (
564561
(key[1]["guilds"], key[1]["users"])
565562
if sort != "users"
566563
else (key[1]["users"], key[1]["guilds"])
567564
)
568-
return keys
569565

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

nsfw/constants.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ def emoji():
1111
"\N{BANANA}",
1212
"\N{KISS MARK}",
1313
]
14-
emoji = choice(EMOJIS)
15-
return emoji
14+
return choice(EMOJIS)
1615

1716

1817
REDDIT_BASEURL = "https://api.reddit.com/r/{}/random"

randimages/core.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ async def _get_others_imgs(
153153
except json.decoder.JSONDecodeError as exception:
154154
await self._api_errors_msg(ctx, error_code=exception)
155155
return None
156-
data = dict(img=img_data, fact=fact_data)
157-
return data
156+
return dict(img=img_data, fact=fact_data)
158157
except aiohttp.client_exceptions.ClientConnectionError:
159158
await self._api_errors_msg(ctx, error_code="JSON decode failed")
160159
return None

spacex/core.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,11 @@ async def _history_texts(data: dict):
162162
if data["links"]["reddit"] is not None
163163
else "",
164164
}
165-
description = (
166-
"Date: **{date}**\n" "{flight_num}" "Links: **{article}{wikipedia}{reddit}**"
165+
return (
166+
"Date: **{date}**\n"
167+
"{flight_num}"
168+
"Links: **{article}{wikipedia}{reddit}**"
167169
).format(**description_kwargs)
168-
return description
169170

170171
@staticmethod
171172
async def _launchpads_texts(data: dict):
@@ -183,7 +184,7 @@ async def _launchpads_texts(data: dict):
183184
"vehicles": ", ".join(data["vehicles_launched"]),
184185
"site_name_ext": data["site_name_long"],
185186
}
186-
description = (
187+
return (
187188
"Status: **{status}**\n"
188189
"Region: **{region}**\n"
189190
"Location: **{location}**\n"
@@ -193,7 +194,6 @@ async def _launchpads_texts(data: dict):
193194
"Vehicle{s} launched: **{vehicles}**\n"
194195
"Site name long: **{site_name_ext}**"
195196
).format(**description_kwargs)
196-
return description
197197

198198
@staticmethod
199199
async def _landpads_texts(data: dict):
@@ -209,14 +209,13 @@ async def _landpads_texts(data: dict):
209209
long=data["location"]["longitude"],
210210
),
211211
}
212-
description = (
212+
return (
213213
"Status: **{status}**\n"
214214
"Landing type: **{landing_t}**\n"
215215
"Attempted landings: **{att_lands}**\n"
216216
"Success landings: **{succ_lands}**\n"
217217
"Location: **{location}**"
218218
).format(**description_kwargs)
219-
return description
220219

221220
@staticmethod
222221
async def _missions_texts(data: dict):
@@ -228,12 +227,11 @@ async def _missions_texts(data: dict):
228227
if data["twitter"] is not None
229228
else "",
230229
}
231-
description = (
230+
return (
232231
data["description"]
233232
+ "\n**[Wikipedia page]({})**".format(data["wikipedia"])
234233
+ "{website}{twitter}"
235234
).format(**description_kwargs)
236-
return description
237235

238236
async def _roadster_texts(self, data: dict):
239237
date, delta = await self._unix_convert(data["launch_date_unix"])
@@ -249,14 +247,13 @@ async def _roadster_texts(self, data: dict):
249247
"m_distance_km": round(data["mars_distance_km"], 2),
250248
"m_distance_mi": round(data["mars_distance_mi"], 2),
251249
}
252-
roadster_stats = (
250+
return (
253251
"Launch date: **{launch_date} {ago} ago**\n"
254252
"Launch mass: **{mass_kg:,} kg / {mass_lbs:,} lbs**\n"
255253
"Actual speed: **{speed_km:,} km/h / {speed_mph:,} mph**\n"
256254
"Earth distance: **{e_distance_km:,} km / {e_distance_mi:,} mi**\n"
257255
"Mars distance: **{m_distance_km:,} km / {m_distance_mi:,} mi**\n"
258256
).format(**roadster_stats_kwargs)
259-
return roadster_stats
260257

261258
@staticmethod
262259
async def _rockets_texts(data: dict):
@@ -315,11 +312,14 @@ async def _rockets_texts(data: dict):
315312
"Fuel amount: **{sec_fuel_amount} tons**\n"
316313
"Burn time: **{sec_burn_time} secs**\n"
317314
).format(**stages_stats_kwargs)
318-
payload_weights_stats = ""
319-
for p in data["payload_weights"]:
320-
payload_weights_stats += (
321-
"Name: **{p_name}**\n" "Weight: **{kg_mass:,} kg / {lb_mass:,} lbs**\n"
315+
payload_weights_stats = "".join(
316+
(
317+
"Name: **{p_name}**\n"
318+
"Weight: **{kg_mass:,} kg / {lb_mass:,} lbs**\n"
322319
).format(p_name=p["name"], kg_mass=p["kg"], lb_mass=p["lb"])
320+
for p in data["payload_weights"]
321+
)
322+
323323
engines_stats_kwargs = {
324324
"number": data["engines"]["number"],
325325
"type": data["engines"]["type"],

0 commit comments

Comments
 (0)