Skip to content

Commit 11345f3

Browse files
authored
Optimize pre-commit workflow (#215)
1 parent 79c3901 commit 11345f3

20 files changed

+1139
-870
lines changed

.github/dependabot.yml

-7
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ updates:
1313
prefix: "[pip]"
1414
include: "scope"
1515
target-branch: "main"
16-
ignore:
17-
# I've chose to ignroe pyright from Dependabot
18-
# As most of the time, it's pulled from upstream, which is Microsoft
19-
# Most of the time there isn't much changes that need to be addressed
20-
# Poetry should always install the latest version instead
21-
- dependency-name: "pyright"
22-
update-types: ["version-update:semver-patch"]
2316
groups:
2417
dev-deps:
2518
dependency-type: "development"

.github/workflows/docker.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111

1212
# We want to filter out dependabot and pre-commit
1313
# automated pushes to main
14-
if: ${{ github.actor != 'dependabot[bot]' && 'pre-commit-ci[bot]'}}
14+
if: ${{ github.actor != 'dependabot[bot]'}}
1515
steps:
1616
- name: Checkout
1717
uses: actions/checkout@v4

.pre-commit-config.yaml

-47
This file was deleted.

bot/cogs/config.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,9 @@ async def setup(self, ctx: GuildContext, *, flags: SetupFlags) -> None:
635635
name="rodhaj", overwrites=rodhaj_overwrites, position=0
636636
)
637637
logging_channel = await rodhaj_category.create_text_channel(
638-
name=flags.log_name or "rodhaj-logs", reason=lgc_reason, position=0
638+
name=flags.log_name or "rodhaj-logs",
639+
reason=lgc_reason,
640+
position=0,
639641
)
640642
lgc_webhook = await logging_channel.create_webhook(
641643
name="Rodhaj Ticket Logs", avatar=avatar_bytes
@@ -829,7 +831,8 @@ async def config_set_age(
829831
type: Literal["guild", "account"],
830832
*,
831833
duration: Annotated[
832-
FriendlyTimeResult, UserFriendlyTime(commands.clean_content, default="…")
834+
FriendlyTimeResult,
835+
UserFriendlyTime(commands.clean_content, default="…"),
833836
],
834837
) -> None:
835838
"""Sets an minimum duration for age-related options
@@ -890,7 +893,11 @@ async def config_set(
890893
value="Boolean option to set the configuration",
891894
)
892895
async def config_toggle(
893-
self, ctx: GuildContext, key: Annotated[str, ConfigKeyConverter], *, value: bool
896+
self,
897+
ctx: GuildContext,
898+
key: Annotated[str, ConfigKeyConverter],
899+
*,
900+
value: bool,
894901
) -> None:
895902
"""Toggles an boolean option for configuration
896903

bot/cogs/ext/prometheus.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from discord.ext import commands, tasks
88

99
try:
10-
1110
from prometheus_async.aio.web import start_http_server
1211
from prometheus_client import Counter, Enum, Gauge, Info, Summary
1312
except ImportError:
@@ -37,7 +36,8 @@ def __init__(self, bot: Rodhaj):
3736
f"{METRIC_PREFIX}active_tickets", "Amount of active tickets"
3837
)
3938
self.closed_tickets = Counter(
40-
f"{METRIC_PREFIX}closed_tickets", "Number of closed tickets in this session"
39+
f"{METRIC_PREFIX}closed_tickets",
40+
"Number of closed tickets in this session",
4141
)
4242
self.locked_tickets = Gauge(
4343
f"{METRIC_PREFIX}locked_tickets",
@@ -50,7 +50,14 @@ def __init__(self, bot: Rodhaj):
5050

5151
# Maybe load all of these from an json file next time
5252
class Metrics:
53-
__slots__ = ("bot", "connected", "latency", "commands", "version", "features")
53+
__slots__ = (
54+
"bot",
55+
"connected",
56+
"latency",
57+
"commands",
58+
"version",
59+
"features",
60+
)
5461

5562
def __init__(self, bot: Rodhaj):
5663
self.bot = bot

bot/cogs/tickets.py

+19-6
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,9 @@ async def create_ticket(self, ticket: TicketThread) -> Optional[TicketOutput]:
281281
reason=f"Failed to create ticket (User ID: {ticket.user.id})",
282282
)
283283
return TicketOutput(
284-
status=False, ticket=created_ticket, msg="Could not create ticket"
284+
status=False,
285+
ticket=created_ticket,
286+
msg="Could not create ticket",
285287
)
286288
else:
287289
self.bot.metrics.features.active_tickets.inc()
@@ -317,7 +319,8 @@ async def tick_post(self, ctx: RoboContext) -> None:
317319
await ctx.message.add_reaction(discord.PartialEmoji(name="\U00002705"))
318320

319321
def get_solved_tag(
320-
self, channel: Optional[Union[discord.ForumChannel, discord.TextChannel]]
322+
self,
323+
channel: Optional[Union[discord.ForumChannel, discord.TextChannel]],
321324
):
322325
if not isinstance(channel, discord.ForumChannel):
323326
return None
@@ -330,7 +333,8 @@ def get_solved_tag(
330333
return solved_tag
331334

332335
def get_locked_tag(
333-
self, channel: Optional[Union[discord.ForumChannel, discord.TextChannel]]
336+
self,
337+
channel: Optional[Union[discord.ForumChannel, discord.TextChannel]],
334338
):
335339
if not isinstance(channel, discord.ForumChannel):
336340
return None
@@ -396,7 +400,10 @@ async def close(self, ctx: RoboContext) -> None:
396400
@commands.cooldown(10, 12, commands.BucketType.member)
397401
@commands.command(name="reply", aliases=["r"])
398402
async def reply(
399-
self, ctx: GuildContext, *, message: Annotated[str, commands.clean_content]
403+
self,
404+
ctx: GuildContext,
405+
*,
406+
message: Annotated[str, commands.clean_content],
400407
) -> None:
401408
"""Replies back to the owner of the active ticket with a message"""
402409
ticket_owner = await self.get_ticket_owner_id(ctx.channel.id)
@@ -475,9 +482,15 @@ async def ticket_info(self, ctx: RoboContext) -> None:
475482
)
476483
embed.add_field(name="Ticket Owner", value=ticket_owner.mention, inline=False)
477484
embed.add_field(
478-
name="Associated Guild", value=ticket.source_guild.name, inline=False
485+
name="Associated Guild",
486+
value=ticket.source_guild.name,
487+
inline=False,
479488
)
480-
embed.add_field(name="Created At", value=format_dt(ticket.thread.created_at), inline=False) # type: ignore
489+
embed.add_field(
490+
name="Created At",
491+
value=format_dt(ticket.thread.created_at),
492+
inline=False,
493+
) # type: ignore
481494
await ctx.send(embed=embed)
482495

483496
# As the guild has an entry in the cache,

bot/cogs/utilities.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ async def about(self, ctx: RoboContext) -> None:
9696
f"Made with discord.py v{discord.__version__} | Running Python {platform.python_version()}"
9797
)
9898
embed = Embed()
99-
embed.set_author(name=self.bot.user.name, icon_url=self.bot.user.display_avatar.url) # type: ignore
99+
embed.set_author(
100+
name=self.bot.user.name, icon_url=self.bot.user.display_avatar.url
101+
) # type: ignore
100102
embed.title = "Rodhaj"
101103
embed.description = (
102104
"Rodhaj is a modern, improved ModMail bot designed exclusively for "
@@ -114,7 +116,8 @@ async def about(self, ctx: RoboContext) -> None:
114116
name="User", value=f"{total_members} total\n{total_unique} unique"
115117
)
116118
embed.add_field(
117-
name="Process", value=f"{memory_usage:.2f} MiB\n{cpu_usage:.2f}% CPU"
119+
name="Process",
120+
value=f"{memory_usage:.2f} MiB\n{cpu_usage:.2f}% CPU",
118121
)
119122
embed.add_field(
120123
name="Active Tickets", value=await self.fetch_num_active_tickets()
@@ -133,7 +136,9 @@ async def ping(self, ctx: RoboContext) -> None:
133136

134137
embed = Embed()
135138
embed.add_field(
136-
name="DB Latency", value=f"```{db_ping * 1000:.2f}ms```", inline=False
139+
name="DB Latency",
140+
value=f"```{db_ping * 1000:.2f}ms```",
141+
inline=False,
137142
)
138143
embed.add_field(
139144
name="Websocket Latency",

bot/launcher.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727

2828
async def main() -> None:
2929
async with ClientSession() as session, asyncpg.create_pool(
30-
dsn=POSTGRES_URI, min_size=25, max_size=25, init=init, command_timeout=30
30+
dsn=POSTGRES_URI,
31+
min_size=25,
32+
max_size=25,
33+
init=init,
34+
command_timeout=30,
3135
) as pool:
3236
async with Rodhaj(
3337
config=config, intents=intents, session=session, pool=pool

bot/libs/tickets/views.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ async def confirm(
237237
status = self.cog.in_progress_tickets.get(interaction.user.id)
238238
if tags is None or status is None:
239239
await interaction.response.send_message(
240-
"Unable to obtain reserved tags and in progress tags", ephemeral=True
240+
"Unable to obtain reserved tags and in progress tags",
241+
ephemeral=True,
241242
)
242243
return
243244

@@ -254,12 +255,11 @@ async def confirm(
254255

255256
if (self.guild.created_at - interaction.created_at) < guild_settings.guild_age:
256257
await interaction.response.send_message(
257-
"The guild is too young in order to utilize Rodhaj.", ephemeral=True
258+
"The guild is too young in order to utilize Rodhaj.",
259+
ephemeral=True,
258260
)
259261
return
260-
elif (
261-
potential_member
262-
): # Since we are checking join times, if we don't have the proper member, we can only skip it.
262+
elif potential_member: # Since we are checking join times, if we don't have the proper member, we can only skip it.
263263
joined_at = potential_member.joined_at or discord.utils.utcnow()
264264
if (joined_at - interaction.created_at) < guild_settings.account_age:
265265
await interaction.response.send_message(

bot/libs/utils/checks.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ def is_manager():
8888

8989
def is_mod():
9090
return check_permissions(
91-
ban_members=True, manage_messages=True, kick_members=True, moderate_members=True
91+
ban_members=True,
92+
manage_messages=True,
93+
kick_members=True,
94+
moderate_members=True,
9295
)
9396

9497

bot/libs/utils/help.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
def process_perms_name(
17-
command: Union[commands.Group, commands.Command]
17+
command: Union[commands.Group, commands.Command],
1818
) -> Optional[str]:
1919
merge_list = []
2020
if (

bot/libs/utils/pages/paginator.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ async def interaction_check(self, interaction: discord.Interaction) -> bool:
125125
):
126126
return True
127127
await interaction.response.send_message(
128-
"This pagination menu cannot be controlled by you, sorry!", ephemeral=True
128+
"This pagination menu cannot be controlled by you, sorry!",
129+
ephemeral=True,
129130
)
130131
return False
131132

@@ -134,7 +135,10 @@ async def on_timeout(self) -> None:
134135
await self.message.edit(view=None)
135136

136137
async def on_error(
137-
self, interaction: discord.Interaction, error: Exception, item: discord.ui.Item
138+
self,
139+
interaction: discord.Interaction,
140+
error: Exception,
141+
item: discord.ui.Item,
138142
) -> None:
139143
if interaction.response.is_done():
140144
await interaction.followup.send(
@@ -148,7 +152,10 @@ async def on_error(
148152
async def start(
149153
self, *, content: Optional[str] = None, ephemeral: bool = False
150154
) -> None:
151-
if self.check_embeds and not self.ctx.channel.permissions_for(self.ctx.me).embed_links: # type: ignore
155+
if (
156+
self.check_embeds
157+
and not self.ctx.channel.permissions_for(self.ctx.me).embed_links
158+
): # type: ignore
152159
await self.ctx.send(
153160
"Bot does not have embed links permission in this channel.",
154161
ephemeral=True,

bot/libs/utils/tree.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ async def interaction_check(self, interaction: discord.Interaction, /) -> bool:
2323
return True
2424

2525
async def on_error(
26-
self, interaction: discord.Interaction, error: app_commands.AppCommandError
26+
self,
27+
interaction: discord.Interaction,
28+
error: app_commands.AppCommandError,
2729
) -> None:
2830
await interaction.response.send_message(embed=FullErrorEmbed(error))

bot/migrations.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ async def init():
187187
except Exception:
188188
traceback.print_exc()
189189
click.secho(
190-
"failed to initialize and apply migrations due to error", fg="red"
190+
"failed to initialize and apply migrations due to error",
191+
fg="red",
191192
)
192193

193194

@@ -202,7 +203,8 @@ async def migrate(reason: str):
202203
"an unapplied migration already exists for the next version, exiting"
203204
)
204205
click.secho(
205-
"hint: apply pending migrations with the `upgrade` command", bold=True
206+
"hint: apply pending migrations with the `upgrade` command",
207+
bold=True,
206208
)
207209
return
208210
revision = mg.create_revision(reason)
@@ -230,7 +232,8 @@ async def upgrade(sql):
230232
try:
231233
applied = await mg.upgrade()
232234
click.secho(
233-
f"Applied {applied} revisions(s) (Current: V{mg.version})", fg="green"
235+
f"Applied {applied} revisions(s) (Current: V{mg.version})",
236+
fg="green",
234237
)
235238
except Exception:
236239
traceback.print_exc()

bot/rodhaj.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ async def fetch_partial_config(self) -> Optional[PartialConfig]:
9999
### Bot-related overrides
100100

101101
async def get_context(
102-
self, origin: Union[discord.Interaction, discord.Message], /, *, cls=RoboContext
102+
self,
103+
origin: Union[discord.Interaction, discord.Message],
104+
/,
105+
*,
106+
cls=RoboContext,
103107
) -> RoboContext:
104108
return await super().get_context(origin, cls=cls)
105109

@@ -119,7 +123,9 @@ async def on_command_error(
119123
elif isinstance(error, commands.CommandInvokeError):
120124
original = error.original
121125
if not isinstance(original, discord.HTTPException):
122-
self.logger.exception("In %s:", ctx.command.qualified_name, exc_info=original) # type: ignore
126+
self.logger.exception(
127+
"In %s:", ctx.command.qualified_name, exc_info=original # type: ignore
128+
)
123129
elif isinstance(error, commands.BadArgument):
124130
await ctx.send(str(error))
125131

docs/dev-guide/intro.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Setup
6767
.. code-block:: bash
6868
6969
pip install -r requirements-dev.txt \
70-
&& pre-commit install
70+
&& lefthook install
7171
7272
5. Copy over the ``config-example.yml`` template over to the ``bot`` directory. Modify the values as appropriate.
7373

0 commit comments

Comments
 (0)