Skip to content

Commit 002b5b1

Browse files
author
Kile
committed
🐛 Some bugfixes again
1 parent 07cc503 commit 002b5b1

File tree

5 files changed

+9
-35
lines changed

5 files changed

+9
-35
lines changed

algorithms/parser.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ This would
152152
1) Check all arguments were provided correctly
153153
2) Handle all check failures inside of the code of the card
154154

155-
## THIS SYSTEM IS OUTDATED. I improved it but too lazy to update the classes below rn.
156155

157156
As for the actual class, all individual class subclass two classes.
158157
### 1) Card
@@ -177,19 +176,10 @@ class IndividualCard(ABC):
177176
"""A class purely for type purposes to require subclasses to implement the exect method"""
178177
ctx: commands.Context
179178

180-
@classmethod
181-
async def _new(cls, name_or_id: str, ctx: commands.Context) -> Card:
182-
base = await Card.new(name_or_id=name_or_id)
183-
setattr(base, "ctx", ctx)
184-
setattr(base, "exec", partial(cls.exec, self=base))
185-
return base
186-
187179
@abstractmethod
188180
async def exec(self, *args, **kwargs) -> None: ...
189181
```
190-
Before the async rewrite, this class was much cleaner and merely served the purpose of type hinting that individual card classes had to implement the `exec` method. However, after the async rewrite, `Card.new` always returned an instance of `Card`, not implementing the `exec` method. So I had to come up with a way to dynamically add the `exec` method to the instance of `Card` that was returned by `Card.new`. This was done by using a class method `_new` which would return an instance of `Card` with the `exec` method added to it. This was done by using the `partial` function from the `functools` module to bind the `exec` method of the subclass to the instance of `Card` that was returned by `Card.new`.
191-
192-
This code is not clean, it doesn't follow the idea of an abstract class and I much preffered the old version. However, it was the only way I could find to make it work.
182+
This class merely serves the purpose of type hinting that individual card classes had to implement the `exec` method.
193183

194184
### The subclass
195185
```py

killua/cogs/cards.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ async def hunt(
532532
): # I don't think timedelta has an hours or minutes property :c
533533
return await ctx.send("You must be at least hunting for twelve hours!")
534534

535-
if not ctx.interaction.response.is_done():
535+
if ctx.interaction and not ctx.interaction.response.is_done():
536536
await ctx.defer() # The following part may take longer than 3 secons
537537

538538
minutes = int(difference.seconds / 60 + difference.days * 24 * 60)

killua/cogs/help.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,14 @@ def get_command_help(
8383

8484
premium_guild, premium_user, cooldown = False, False, False
8585

86-
if [c for c in checks if hasattr(c, "premium_guild_only")]:
86+
if any(c for c in checks if hasattr(c, "premium_guild_only")):
8787
premium_guild = True
8888

89-
if [c for c in checks if hasattr(c, "premium_user_only")]:
89+
if any(c for c in checks if hasattr(c, "premium_user_only")):
9090
premium_user = True
9191

92-
if res := [c for c in checks if hasattr(c, "cooldown")]:
93-
check = res[0]
94-
cooldown = getattr(check, "cooldown", False)
92+
if res := next((c for c in checks if hasattr(c, "cooldown")), None):
93+
cooldown = getattr(res, "cooldown", False)
9594

9695
if premium_guild or premium_user:
9796
embed.description += f"\n{'<:premium_guild_badge:883473807292121149>' if premium_guild else '<:tier_one_badge:879390548857880597>'} `[Premium {'servers' if premium_guild else 'users'} only]`"
@@ -303,7 +302,7 @@ async def help(
303302
)
304303

305304
await view.wait()
306-
if view.timed_out:
305+
if view.timed_out or view.value is None:
307306
view.children[0].disabled = (
308307
True # Instead of looping through all the children, we just disable the select menu since we want the links to remain clickable
309308
)

killua/utils/classes/card.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
)
2222
from killua.bot import BaseBot
2323

24-
if TYPE_CHECKING:
24+
if TYPE_CHECKING: # Circular import my beloved
2525
from killua.utils.classes import User
2626

2727
from killua.utils.interactions import Select, View, Button
@@ -38,21 +38,6 @@ class SuccessfulDefense(CheckFailure):
3838
class CardNotFound(Exception):
3939
pass
4040

41-
# TODO this below is not true I am too lazy to rephrase need to do later.
42-
#
43-
# Unfortunately, for the Card class that provides useful methods for spell cards
44-
# needs to import the User class which in turn needs to import the Card class.
45-
# The actual methods of that spell card base class are not needed in the User class,
46-
# so I created a partial class that only contains the necessary methods and properties
47-
# to prevent a circular import. This is only used in this module.
48-
#
49-
# Circular import:
50-
# ⏤⏤⏤⏤⏤⏤
51-
# / ↘︎
52-
# User Card
53-
# ↖︎ /
54-
# ⏤⏤⏤⏤⏤⏤
55-
5641

5742
@dataclass
5843
class Card:

killua/utils/paginator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ async def backwards(self, interaction: discord.Interaction, _: discord.ui.Button
162162
async def delete(self, interaction: discord.Interaction, _: discord.ui.Button):
163163
try:
164164
await interaction.message.delete()
165-
except discord.Forbidden:
165+
except discord.HTTPException:
166166
await self.disable(interaction.message)
167167
self.ignore = True
168168
self.stop()

0 commit comments

Comments
 (0)