Skip to content

Commit f9f9377

Browse files
committed
refactor: Use tux.bot.Tux directly in most files instead of its subclass
1 parent 854c956 commit f9f9377

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+306
-254
lines changed

tux/cogs/admin/dev.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
from discord.ext import commands
33
from loguru import logger
44

5-
from tux import bot
5+
from tux.bot import Tux
66
from tux.utils import checks
77

88

99
class Dev(commands.Cog):
10-
def __init__(self, bot: bot.Tux) -> None:
10+
def __init__(self, bot: Tux) -> None:
1111
self.bot = bot
1212

1313
@commands.hybrid_group(
@@ -17,13 +17,13 @@ def __init__(self, bot: bot.Tux) -> None:
1717
)
1818
@commands.guild_only()
1919
@checks.has_pl(8)
20-
async def dev(self, ctx: commands.Context[commands.Bot]) -> None:
20+
async def dev(self, ctx: commands.Context[Tux]) -> None:
2121
"""
2222
Dev related commands.
2323
2424
Parameters
2525
----------
26-
ctx : commands.Context[commands.Bot]
26+
ctx : commands.Context[Tux]
2727
The context object for the command.
2828
2929
Raises
@@ -43,7 +43,7 @@ async def dev(self, ctx: commands.Context[commands.Bot]) -> None:
4343
)
4444
@commands.guild_only()
4545
@checks.has_pl(8)
46-
async def sync_tree(self, ctx: commands.Context[commands.Bot], guild: discord.Guild) -> None:
46+
async def sync_tree(self, ctx: commands.Context[Tux], guild: discord.Guild) -> None:
4747
"""
4848
Syncs the app command tree.
4949
@@ -77,7 +77,7 @@ async def sync_tree(self, ctx: commands.Context[commands.Bot], guild: discord.Gu
7777
)
7878
@commands.guild_only()
7979
@checks.has_pl(8)
80-
async def clear_tree(self, ctx: commands.Context[commands.Bot]) -> None:
80+
async def clear_tree(self, ctx: commands.Context[Tux]) -> None:
8181
"""
8282
Clears the app command tree.
8383
@@ -112,7 +112,7 @@ async def clear_tree(self, ctx: commands.Context[commands.Bot]) -> None:
112112
)
113113
@commands.guild_only()
114114
@checks.has_pl(8)
115-
async def load_cog(self, ctx: commands.Context[commands.Bot], *, cog: str) -> None:
115+
async def load_cog(self, ctx: commands.Context[Tux], *, cog: str) -> None:
116116
"""
117117
Loads a cog into the bot.
118118
@@ -153,7 +153,7 @@ async def load_cog(self, ctx: commands.Context[commands.Bot], *, cog: str) -> No
153153
)
154154
@commands.guild_only()
155155
@checks.has_pl(8)
156-
async def unload_cog(self, ctx: commands.Context[commands.Bot], *, cog: str) -> None:
156+
async def unload_cog(self, ctx: commands.Context[Tux], *, cog: str) -> None:
157157
"""
158158
Unloads a cog from the bot.
159159
@@ -188,7 +188,7 @@ async def unload_cog(self, ctx: commands.Context[commands.Bot], *, cog: str) ->
188188
)
189189
@commands.guild_only()
190190
@checks.has_pl(8)
191-
async def reload_cog(self, ctx: commands.Context[commands.Bot], *, cog: str) -> None:
191+
async def reload_cog(self, ctx: commands.Context[Tux], *, cog: str) -> None:
192192
"""
193193
Reloads a cog in the bot.
194194
@@ -223,7 +223,7 @@ async def reload_cog(self, ctx: commands.Context[commands.Bot], *, cog: str) ->
223223
)
224224
@commands.guild_only()
225225
@checks.has_pl(8)
226-
async def stop(self, ctx: commands.Context[commands.Bot]) -> None:
226+
async def stop(self, ctx: commands.Context[Tux]) -> None:
227227
"""
228228
Stops the bot. If Tux is running with Docker Compose, this will restart the container.
229229
@@ -239,5 +239,5 @@ async def stop(self, ctx: commands.Context[commands.Bot]) -> None:
239239
await self.bot.shutdown()
240240

241241

242-
async def setup(bot: bot.Tux) -> None:
242+
async def setup(bot: Tux) -> None:
243243
await bot.add_cog(Dev(bot))

tux/cogs/admin/eval.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from discord.ext import commands
55
from loguru import logger
66

7+
from tux.bot import Tux
78
from tux.utils import checks
89
from tux.utils.embeds import EmbedCreator
910

@@ -38,7 +39,7 @@ def insert_returns(body: list[ast.stmt]) -> None:
3839

3940

4041
class Eval(commands.Cog):
41-
def __init__(self, bot: commands.Bot) -> None:
42+
def __init__(self, bot: Tux) -> None:
4243
self.bot = bot
4344

4445
@commands.command(
@@ -48,13 +49,13 @@ def __init__(self, bot: commands.Bot) -> None:
4849
)
4950
@commands.guild_only()
5051
@checks.has_pl(8) # sysadmin or higher
51-
async def eval(self, ctx: commands.Context[commands.Bot], *, cmd: str) -> None:
52+
async def eval(self, ctx: commands.Context[Tux], *, cmd: str) -> None:
5253
"""
5354
Evaluate a Python expression. (Owner only)
5455
5556
Parameters
5657
----------
57-
ctx : commands.Context[commands.Bot]
58+
ctx : commands.Context[Tux]
5859
The context in which the command is being invoked.
5960
cmd : str
6061
The Python expression to evaluate.
@@ -128,5 +129,5 @@ async def eval(self, ctx: commands.Context[commands.Bot], *, cmd: str) -> None:
128129
await ctx.send(embed=embed, ephemeral=True, delete_after=30)
129130

130131

131-
async def setup(bot: commands.Bot) -> None:
132+
async def setup(bot: Tux) -> None:
132133
await bot.add_cog(Eval(bot))

tux/cogs/admin/git.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# from githubkit.versions.latest.models import Issue
55
# from loguru import logger
66

7+
78
# from tux.wrappers.github import GitHubService
89
# from tux.utils.constants import Constants as CONST
910
# from tux.utils.embeds import EmbedCreator
@@ -18,7 +19,7 @@
1819

1920

2021
# class Git(commands.Cog):
21-
# def __init__(self, bot: commands.Bot) -> None:
22+
# def __init__(self, bot: Tux) -> None:
2223
# self.bot = bot
2324
# self.github = GitHubService()
2425
# self.repo_url = CONST.GITHUB_REPO_URL
@@ -379,14 +380,15 @@
379380
# logger.info(f"{interaction.user} fetched a pull request.")
380381

381382

382-
# async def setup(bot: commands.Bot) -> None:
383+
# async def setup(bot: Tux) -> None:
383384
# await bot.add_cog(Git(bot))
384385

385386
# TODO: Rewrite this cog to use the new hybrid command system.
386387

387388
from discord.ext import commands
388389
from loguru import logger
389390

391+
from tux.bot import Tux
390392
from tux.ui.buttons import GithubButton
391393
from tux.utils import checks
392394
from tux.utils.constants import Constants as CONST
@@ -395,7 +397,7 @@
395397

396398

397399
class Git(commands.Cog):
398-
def __init__(self, bot: commands.Bot) -> None:
400+
def __init__(self, bot: Tux) -> None:
399401
self.bot = bot
400402
self.github = GithubService()
401403
self.repo_url = CONST.GITHUB_REPO_URL
@@ -407,13 +409,13 @@ def __init__(self, bot: commands.Bot) -> None:
407409
)
408410
@commands.guild_only()
409411
@checks.has_pl(8)
410-
async def git(self, ctx: commands.Context[commands.Bot]) -> None:
412+
async def git(self, ctx: commands.Context[Tux]) -> None:
411413
"""
412414
Github related commands.
413415
414416
Parameters
415417
----------
416-
ctx : commands.Context[commands.Bot]
418+
ctx : commands.Context[Tux]
417419
The context object for the command.
418420
"""
419421

@@ -427,13 +429,13 @@ async def git(self, ctx: commands.Context[commands.Bot]) -> None:
427429
)
428430
@commands.guild_only()
429431
@checks.has_pl(8)
430-
async def get_repo(self, ctx: commands.Context[commands.Bot]) -> None:
432+
async def get_repo(self, ctx: commands.Context[Tux]) -> None:
431433
"""
432434
Get repository information.
433435
434436
Parameters
435437
----------
436-
ctx : commands.Context[commands.Bot]
438+
ctx : commands.Context[Tux]
437439
The context object for the command.
438440
"""
439441

@@ -466,13 +468,13 @@ async def get_repo(self, ctx: commands.Context[commands.Bot]) -> None:
466468
@commands.guild_only()
467469
# @checks.has_pl(8)
468470
@commands.has_any_role("Root", "Admin", "Contributor", "Tux Contributor", "Tux Beta Tester", "%wheel")
469-
async def create_issue(self, ctx: commands.Context[commands.Bot], title: str, body: str) -> None:
471+
async def create_issue(self, ctx: commands.Context[Tux], title: str, body: str) -> None:
470472
"""
471473
Create an issue.
472474
473475
Parameters
474476
----------
475-
ctx : commands.Context[commands.Bot]
477+
ctx : commands.Context[Tux]
476478
The context object for the command.
477479
title : str
478480
The title of the issue.
@@ -507,13 +509,13 @@ async def create_issue(self, ctx: commands.Context[commands.Bot], title: str, bo
507509
)
508510
@commands.guild_only()
509511
@checks.has_pl(8)
510-
async def get_issue(self, ctx: commands.Context[commands.Bot], issue_number: int) -> None:
512+
async def get_issue(self, ctx: commands.Context[Tux], issue_number: int) -> None:
511513
"""
512514
Get an issue by issue number.
513515
514516
Parameters
515517
----------
516-
ctx : commands.Context[commands.Bot]
518+
ctx : commands.Context[Tux]
517519
The context object for the command.
518520
issue_number : int
519521
The number of the issue to retrieve.
@@ -542,5 +544,5 @@ async def get_issue(self, ctx: commands.Context[commands.Bot], issue_number: int
542544
logger.info(f"{ctx.author} fetched an issue.")
543545

544546

545-
async def setup(bot: commands.Bot) -> None:
547+
async def setup(bot: Tux) -> None:
546548
await bot.add_cog(Git(bot))

tux/cogs/admin/mail.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
from discord.ext import commands
77
from loguru import logger
88

9+
from tux.bot import Tux
910
from tux.utils import checks
1011
from tux.utils.constants import Constants as CONST
1112

1213
MailboxData = dict[str, str | list[str]]
1314

1415

1516
class Mail(commands.Cog):
16-
def __init__(self, bot: commands.Bot) -> None:
17+
def __init__(self, bot: Tux) -> None:
1718
self.bot = bot
1819
self.api_url = CONST.MAILCOW_API_URL
1920
self.headers = {
@@ -203,5 +204,5 @@ async def _send_dm(
203204
)
204205

205206

206-
async def setup(bot: commands.Bot) -> None:
207+
async def setup(bot: Tux) -> None:
207208
await bot.add_cog(Mail(bot))

tux/cogs/fun/fact.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
from discord.ext import commands
44

5+
from tux.bot import Tux
56
from tux.utils.embeds import EmbedCreator
67

78

89
class Fact(commands.Cog):
9-
def __init__(self, bot: commands.Bot) -> None:
10+
def __init__(self, bot: Tux) -> None:
1011
self.bot = bot
1112
self.facts = [
1213
"The Linux kernel has over 36 million lines of code in its Git repository.",
@@ -36,13 +37,13 @@ def __init__(self, bot: commands.Bot) -> None:
3637
name="fact",
3738
aliases=["funfact"],
3839
)
39-
async def fact(self, ctx: commands.Context[commands.Bot]) -> None:
40+
async def fact(self, ctx: commands.Context[Tux]) -> None:
4041
"""
4142
Get a random fun fact.
4243
4344
Parameters
4445
----------
45-
ctx : commands.Context[commands.Bot]
46+
ctx : commands.Context[Tux]
4647
The context object for the command.
4748
"""
4849
embed = EmbedCreator.create_info_embed(
@@ -61,5 +62,5 @@ async def fact(self, ctx: commands.Context[commands.Bot]) -> None:
6162
await ctx.send(embed=embed)
6263

6364

64-
async def setup(bot: commands.Bot) -> None:
65+
async def setup(bot: Tux) -> None:
6566
await bot.add_cog(Fact(bot))

tux/cogs/fun/imgeffect.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
from loguru import logger
88
from PIL import Image, ImageEnhance, ImageOps
99

10+
from tux.bot import Tux
1011
from tux.utils.embeds import EmbedCreator
1112

1213

1314
class ImgEffect(commands.Cog):
14-
def __init__(self, bot: commands.Bot) -> None:
15+
def __init__(self, bot: Tux) -> None:
1516
self.bot = bot
1617
self.allowed_mimetypes = [
1718
"image/jpeg",
@@ -93,5 +94,5 @@ async def deepfry(self, interaction: discord.Interaction, image: discord.Attachm
9394
await interaction.followup.send(file=file, ephemeral=True)
9495

9596

96-
async def setup(bot: commands.Bot) -> None:
97+
async def setup(bot: Tux) -> None:
9798
await bot.add_cog(ImgEffect(bot))

0 commit comments

Comments
 (0)