-
-
Notifications
You must be signed in to change notification settings - Fork 25
Sourcery Starbot ⭐ refactored PredaaA/predacogs #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
msg = tabulate(votes, tablefmt="orgtbl") | ||
embeds = [] | ||
pages = 1 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
async def download_widget(session: aiohttp.ClientSession, url: str): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
msg = tabulate(votes, tablefmt="orgtbl") | ||
embeds = [] | ||
pages = 1 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
@fivemset.command() | ||
async def ip(self, ctx: commands.Context, *, ip: str): | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
await ctx.send_help() | ||
return | ||
|
||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
await ctx.send_help() | ||
return | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return await ctx.send(msg, file=discord.File(file, filename=f"graph-{filename}.png")) | ||
|
||
@graph.command(name="list") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
if isinstance(error, commands.CommandInvokeError): | ||
self.upsert("command_error") | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
em = discord.Embed(color=await ctx.embed_colour()) | ||
em.set_author(name=_("{} stats:").format(bank_name), icon_url=icon) | ||
em.add_field( | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
regions_stats = dict(sorted(regions.items(), key=lambda x: sort_keys(x), reverse=True)) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,7 @@ def emoji(): | |
"\N{BANANA}", | ||
"\N{KISS MARK}", | ||
] | ||
emoji = choice(EMOJIS) | ||
return emoji | ||
return choice(EMOJIS) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
REDDIT_BASEURL = "https://api.reddit.com/r/{}/random" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
except aiohttp.client_exceptions.ClientConnectionError: | ||
await self._api_errors_msg(ctx, error_code="JSON decode failed") | ||
return None | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
@staticmethod | ||
async def _launchpads_texts(data: dict): | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
"Status: **{status}**\n" | ||
"Region: **{region}**\n" | ||
"Location: **{location}**\n" | ||
|
@@ -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): | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
@staticmethod | ||
async def _missions_texts(data: dict): | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
async def _roadster_texts(self, data: dict): | ||
date, delta = await self._unix_convert(data["launch_date_unix"]) | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
@staticmethod | ||
async def _rockets_texts(data: dict): | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
engines_stats_kwargs = { | ||
"number": data["engines"]["number"], | ||
"type": data["engines"]["type"], | ||
|
There was a problem hiding this comment.
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:de-morgan
)