Skip to content
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

[meta] update pre-commit #242

Merged
merged 3 commits into from
Feb 11, 2024
Merged
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ default_language_version:
python: python3.11
repos:
- repo: https://github.com/psf/black
rev: 23.12.1
rev: 24.1.1
hooks:
- id: black
- repo: https://github.com/pycqa/isort
Expand Down
24 changes: 15 additions & 9 deletions adminutils/adminutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,11 @@ async def emoji_add(self, ctx, name: str, url: str, *roles: discord.Role):
roles=roles,
reason=get_audit_reason(
ctx.author,
_("Restricted to roles: {}").format(", ".join(role.name for role in roles))
if roles
else None,
(
_("Restricted to roles: {}").format(", ".join(role.name for role in roles))
if roles
else None
),
),
)
except discord.InvalidArgument:
Expand Down Expand Up @@ -245,9 +247,11 @@ async def emote_steal(
roles=roles,
reason=get_audit_reason(
ctx.author,
_("Restricted to roles: {}").format(", ".join(role.name for role in roles))
if roles
else None,
(
_("Restricted to roles: {}").format(", ".join(role.name for role in roles))
if roles
else None
),
),
)
await ctx.tick()
Expand Down Expand Up @@ -283,9 +287,11 @@ async def emoji_rename(
roles=roles,
reason=get_audit_reason(
ctx.author,
_("Restricted to roles: ").format(", ".join(role.name for role in roles))
if roles
else None,
(
_("Restricted to roles: ").format(", ".join(role.name for role in roles))
if roles
else None
),
),
)
except discord.Forbidden:
Expand Down
18 changes: 9 additions & 9 deletions captcha/commands/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,14 @@ async def add_roles(self, ctx: commands.Context, *roles: discord.Role):
for role in roles:
async with self.data.guild(ctx.guild).autoroles() as roles_list:
if role.position >= ctx.me.top_role.position:
error[
role.name
] = "This role is higher than my highest role in the role hierarchy."
error[role.name] = (
"This role is higher than my highest role in the role hierarchy."
)
continue
if role.position >= ctx.author.top_role.position:
error[
role.name
] = "This role is higher than your own in the discord hierarchy."
error[role.name] = (
"This role is higher than your own in the discord hierarchy."
)
continue
if role.id not in roles_list:
roles_list.append(role.id)
Expand Down Expand Up @@ -356,9 +356,9 @@ async def remove_roles(self, ctx: commands.Context, *roles: discord.Role):
async with self.data.guild(ctx.guild).autoroles() as roles_list:
for role in roles:
if role.position >= ctx.author.top_role.position:
error[
role.name
] = "This role is higher than your own in the discord hierarchy."
error[role.name] = (
"This role is higher than your own in the discord hierarchy."
)
continue
if role.id in roles_list:
roles_list.remove(role.id)
Expand Down
96 changes: 62 additions & 34 deletions datautils/datautils.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,12 @@
em.add_field(
name=_("Features"),
value="\n".join(_(GUILD_FEATURES.get(f, f)) for f in guild.features).format(
banner=guild.banner and f" [🔗]({guild.banner_url_as(format='png')})" or "",
splash=guild.splash and f" [🔗]({guild.splash_url_as(format='png')})" or "",
banner=guild.banner
and f" [🔗]({guild.banner_url_as(format='png')})"
or "",
splash=guild.splash
and f" [🔗]({guild.splash_url_as(format='png')})"
or "",
discovery=getattr(guild, "discovery_splash", None)
and f" [🔗]({guild.discovery_splash_url_as(format='png')})"
or "",
Expand Down Expand Up @@ -263,35 +267,55 @@
)
em.add_field(
name=_("Verification level"),
value=_("None")
if server.verification_level == discord.VerificationLevel.none
else _("Low")
if server.verification_level == discord.VerificationLevel.low
else _("Medium")
if server.verification_level == discord.VerificationLevel.medium
else _("High")
if server.verification_level == discord.VerificationLevel.high
else _("Highest")
if server.verification_level == discord.VerificationLevel.extreme
else _("Unknown"),
value=(
_("None")
if server.verification_level == discord.VerificationLevel.none
else (
_("Low")
if server.verification_level == discord.VerificationLevel.low
else (
_("Medium")
if server.verification_level == discord.VerificationLevel.medium
else (
_("High")
if server.verification_level == discord.VerificationLevel.high
else (
_("Highest")
if server.verification_level == discord.VerificationLevel.extreme
else _("Unknown")
)
)
)
)
),
)
em.add_field(
name=_("Explicit content filter"),
value=_("Don't scan any messages.")
if server.explicit_content_filter == discord.ContentFilter.disabled
else _("Scan messages from members without a role.")
if server.explicit_content_filter == discord.ContentFilter.no_role
else _("Scan messages sent by all members.")
if server.explicit_content_filter == discord.ContentFilter.all_members
else _("Unknown"),
value=(
_("Don't scan any messages.")
if server.explicit_content_filter == discord.ContentFilter.disabled
else (
_("Scan messages from members without a role.")
if server.explicit_content_filter == discord.ContentFilter.no_role
else (
_("Scan messages sent by all members.")
if server.explicit_content_filter == discord.ContentFilter.all_members
else _("Unknown")
)
)
),
)
em.add_field(
name=_("Default notifications"),
value=_("All messages")
if server.default_notifications == discord.NotificationLevel.all_messages
else _("Only @mentions")
if server.default_notifications == discord.NotificationLevel.only_mentions
else _("Unknown"),
value=(
_("All messages")
if server.default_notifications == discord.NotificationLevel.all_messages
else (
_("Only @mentions")
if server.default_notifications == discord.NotificationLevel.only_mentions
else _("Unknown")
)
),
)
em.add_field(name=_("2FA admins"), value=bool_emojify(server.mfa_level))
if server.rules_channel:
Expand Down Expand Up @@ -432,15 +456,19 @@
changed_roles = sorted(channel.changed_roles, key=lambda r: r.position, reverse=True)
em = discord.Embed(
title=chat.escape(str(channel.name), formatting=True),
description=topic
if (topic := getattr(channel, "topic", None))
else "\N{SPEECH BALLOON}: {} | \N{SPEAKER}: {} | \N{SATELLITE ANTENNA}: {}".format(
len(channel.text_channels),
len(channel.voice_channels),
len(channel.stage_channels),
)
if isinstance(channel, discord.CategoryChannel)
else discord.Embed.Empty,
description=(
topic
if (topic := getattr(channel, "topic", None))
else (
"\N{SPEECH BALLOON}: {} | \N{SPEAKER}: {} | \N{SATELLITE ANTENNA}: {}".format(
len(channel.text_channels),
len(channel.voice_channels),
len(channel.stage_channels),
)
if isinstance(channel, discord.CategoryChannel)
else discord.Embed.Empty
)
),
color=await ctx.embed_color(),
)
em.add_field(name=_("ID"), value=channel.id)
Expand Down Expand Up @@ -507,7 +535,7 @@
@commands.bot_has_permissions(embed_links=True)
async def channels(self, ctx, *, server: commands.GuildConverter = None):
"""Get all channels on server"""
# TODO: Use dpy menus for that

Check notice on line 538 in datautils/datautils.py

View check run for this annotation

codefactor.io / CodeFactor

datautils/datautils.py#L538

unresolved comment '# TODO: Use dpy menus for that' (C100)
if server is None or not await self.bot.is_owner(ctx.author):
server = ctx.guild
channels = {
Expand Down
6 changes: 3 additions & 3 deletions datautils/menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ def __init__(self, entries):
async def format_page(self, menu: ChannelsMenu, entries):
e = discord.Embed(
title="{}:".format(_(KNOWN_CHANNEL_TYPES[menu.channel_type][1])),
description=chat.box("\n".join(c.name for c in entries))
if entries
else _("No channels"),
description=(
chat.box("\n".join(c.name for c in entries)) if entries else _("No channels")
),
)
e.set_footer(
text=_("Page {}/{} • {}: {} • Total channels: {}").format(
Expand Down
16 changes: 10 additions & 6 deletions godvilledata/godvilledata.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ async def godville(self, ctx, *, god: GodConverter):
text_header = "{} и его {}\n{}\n".format(
chat.bold(profile.god),
chat.bold(profile.name),
chat.italics(chat.escape(profile.motto.strip(), formatting=True))
if profile.motto
else chat.inline("Здесь ничего нет"),
(
chat.italics(chat.escape(profile.motto.strip(), formatting=True))
if profile.motto
else chat.inline("Здесь ничего нет")
),
)
if profile.arena_is_in_fight:
text_header += "В сражении: {}\n".format(profile.fight_type_rus)
Expand Down Expand Up @@ -212,9 +214,11 @@ async def godvillegame(self, ctx, *, godname: str):
text_header = "{} and his {}\n{}\n".format(
chat.bold(profile.god),
chat.bold(profile.name),
chat.italics(chat.escape(profile.motto.strip(), formatting=True))
if profile.motto
else chat.inline("Nothing here"),
(
chat.italics(chat.escape(profile.motto.strip(), formatting=True))
if profile.motto
else chat.inline("Nothing here")
),
)
if profile.arena_is_in_fight:
text_header += "In fight: {}\n".format(profile.fight_type_rus)
Expand Down
6 changes: 3 additions & 3 deletions leveler/commands/lvladmin/badge.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@
badge_name = "{}_{}".format(name, serverid)
if badge_name in userbadges.keys():
user_priority_num = userbadges[badge_name]["priority_num"]
new_badge[
"priority_num"
] = user_priority_num # maintain old priority number set by user
new_badge["priority_num"] = (
user_priority_num # maintain old priority number set by user
)
userbadges[badge_name] = new_badge
await self.db.users.update_one(
{"user_id": user["user_id"]},
Expand Down Expand Up @@ -352,7 +352,7 @@

pages = list(chat.pagify(msg, page_length=2048))
embeds = []
# TODO: Use dpy menus

Check notice on line 355 in leveler/commands/lvladmin/badge.py

View check run for this annotation

codefactor.io / CodeFactor

leveler/commands/lvladmin/badge.py#L355

unresolved comment '# TODO: Use dpy menus' (C100)
for i, page in enumerate(pages, start=1):
em = discord.Embed(description=page, colour=await ctx.embed_color())
em.set_author(
Expand Down
8 changes: 5 additions & 3 deletions leveler/commands/lvladmin/debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ async def debug_info(self, ctx):
("DB lock locked", self._db_lock.locked()),
(
"DB lock queue",
"N/A"
if self._db_lock._waiters is None
else len(self._db_lock._waiters),
(
"N/A"
if self._db_lock._waiters is None
else len(self._db_lock._waiters)
),
),
("pymongo version", pymongoversion),
("motor version", motorversion),
Expand Down
6 changes: 3 additions & 3 deletions leveler/commands/lvlset/badge.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ async def buy_badge(self, ctx, is_global: Optional[bool], *, name: str):
return
if badge_info["price"] <= await bank.get_balance(user):
await bank.withdraw_credits(user, badge_info["price"])
userinfo["badges"][
"{}_{}".format(name, str(serverid))
] = server_badges[name]
userinfo["badges"]["{}_{}".format(name, str(serverid))] = (
server_badges[name]
)
await self.db.users.update_one(
{"user_id": userinfo["user_id"]},
{"$set": {"badges": userinfo["badges"]}},
Expand Down
25 changes: 16 additions & 9 deletions leveler/commands/top.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ async def top(
elif options.global_top and owner:
is_level = True if await self.config.global_levels() else False
title = "Global Exp Leaderboard for {}\n".format(self.bot.user.name)
async for userinfo in self.db.users.find({}).allow_disk_use(True).sort(
"total_exp", -1
async for userinfo in (
self.db.users.find({}).allow_disk_use(True).sort("total_exp", -1)
):
pos += 1
if is_level:
Expand Down Expand Up @@ -109,9 +109,11 @@ async def top(
icon_url = self.bot.user.avatar_url
elif options.rep:
title = "Rep Leaderboard for {}\n".format(server.name)
async for userinfo in self.db.users.find(
{f"servers.{server.id}": {"$exists": True}}
).allow_disk_use(True).sort("rep", -1):
async for userinfo in (
self.db.users.find({f"servers.{server.id}": {"$exists": True}})
.allow_disk_use(True)
.sort("rep", -1)
):
pos += 1
users.append(
(
Expand All @@ -137,10 +139,15 @@ async def top(
else:
is_level = True
title = "Exp Leaderboard for {}\n".format(server.name)
async for userinfo in self.db.users.find(
{f"servers.{server.id}": {"$exists": True}}
).allow_disk_use(True).sort(
[(f"servers.{server.id}.level", -1), (f"servers.{server.id}.current_exp", -1)]
async for userinfo in (
self.db.users.find({f"servers.{server.id}": {"$exists": True}})
.allow_disk_use(True)
.sort(
[
(f"servers.{server.id}.level", -1),
(f"servers.{server.id}.current_exp", -1),
]
)
):
pos += 1
if str(user.id) == userinfo["user_id"]:
Expand Down
16 changes: 9 additions & 7 deletions leveler/exp.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,20 +206,22 @@ async def _handle_levelup(self, user, userinfo, server, channel):

async def _find_server_rank(self, user, server):
rank = 1
async for userinfo in self.db.users.find(
{f"servers.{server.id}": {"$exists": True}}
).allow_disk_use(True).sort(
[(f"servers.{server.id}.level", -1), (f"servers.{server.id}.current_exp", -1)]
async for userinfo in (
self.db.users.find({f"servers.{server.id}": {"$exists": True}})
.allow_disk_use(True)
.sort([(f"servers.{server.id}.level", -1), (f"servers.{server.id}.current_exp", -1)])
):
if userinfo["user_id"] == str(user.id):
return rank
rank += 1

async def _find_server_rep_rank(self, user, server):
rank = 1
async for userinfo in self.db.users.find(
{f"servers.{server.id}": {"$exists": True}}
).allow_disk_use(True).sort("rep", -1):
async for userinfo in (
self.db.users.find({f"servers.{server.id}": {"$exists": True}})
.allow_disk_use(True)
.sort("rep", -1)
):
if userinfo.get("user_id") == str(user.id):
return rank
rank += 1
Expand Down
8 changes: 5 additions & 3 deletions leveler/menus/top.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@ def __init__(
async def format_page(self, menu: TopMenu, entries):
table = tabulate(
entries,
headers=["#", self.board_type, "Level", "Username"]
if self.is_level
else ["#", self.board_type, "Username"],
headers=(
["#", self.board_type, "Level", "Username"]
if self.is_level
else ["#", self.board_type, "Username"]
),
tablefmt="rst",
)
table_width = len(table.splitlines()[0])
Expand Down
Loading
Loading