Removes duplicate code and unnecessary imports

Cleans up codebase by removing redundant type casting, unused imports, and duplicate method definitions.

Eliminates duplicate embeds list comprehension that was accidentally duplicated.

Removes unnecessary typing imports and cast operation that were no longer needed.

Deletes duplicate history method implementation that was redundant.
This commit is contained in:
Slipstream 2025-06-10 18:06:50 -06:00
parent 92b0bc5804
commit 134506e6ba
Signed by: slipstream
GPG Key ID: 13E498CE010AC6FD
2 changed files with 2 additions and 33 deletions

View File

@ -395,8 +395,6 @@ class Interaction:
async def respond_modal(self, modal: "Modal") -> None: async def respond_modal(self, modal: "Modal") -> None:
"""|coro| Send a modal in response to this interaction.""" """|coro| Send a modal in response to this interaction."""
from typing import Any, cast
payload = InteractionResponsePayload( payload = InteractionResponsePayload(
type=InteractionCallbackType.MODAL, type=InteractionCallbackType.MODAL,
data=modal.to_dict(), data=modal.to_dict(),
@ -404,7 +402,7 @@ class Interaction:
await self._client._http.create_interaction_response( await self._client._http.create_interaction_response(
interaction_id=self.id, interaction_id=self.id,
interaction_token=self.token, interaction_token=self.token,
payload=cast(Any, payload.to_dict()), payload=payload,
) )
async def edit( async def edit(
@ -506,7 +504,6 @@ class InteractionCallbackData:
self.content: Optional[str] = data.get("content") self.content: Optional[str] = data.get("content")
self.embeds: Optional[List[Embed]] = ( self.embeds: Optional[List[Embed]] = (
[Embed(e) for e in data.get("embeds", [])] if data.get("embeds") else None [Embed(e) for e in data.get("embeds", [])] if data.get("embeds") else None
[Embed(e) for e in data.get("embeds", [])] if data.get("embeds") else None
) )
self.allowed_mentions: Optional[AllowedMentions] = ( self.allowed_mentions: Optional[AllowedMentions] = (
AllowedMentions(data["allowed_mentions"]) AllowedMentions(data["allowed_mentions"])

View File

@ -1087,6 +1087,7 @@ class TextChannel(Channel):
) )
self.last_pin_timestamp: Optional[str] = data.get("last_pin_timestamp") self.last_pin_timestamp: Optional[str] = data.get("last_pin_timestamp")
def history( def history(
self, self,
*, *,
@ -1142,35 +1143,6 @@ class TextChannel(Channel):
self._client._messages.pop(mid, None) self._client._messages.pop(mid, None)
return ids return ids
async def history(
self,
*,
limit: Optional[int] = 100,
before: "Snowflake | None" = None,
):
"""An async iterator over messages in the channel."""
params: Dict[str, Union[int, str]] = {}
if before is not None:
params["before"] = before
fetched = 0
while True:
to_fetch = 100 if limit is None else min(100, limit - fetched)
if to_fetch <= 0:
break
params["limit"] = to_fetch
messages = await self._client._http.request(
"GET", f"/channels/{self.id}/messages", params=params.copy()
)
if not messages:
break
params["before"] = messages[-1]["id"]
for msg in messages:
yield Message(msg, self._client)
fetched += 1
if limit is not None and fetched >= limit:
return
def __repr__(self) -> str: def __repr__(self) -> str:
return f"<TextChannel id='{self.id}' name='{self.name}' guild_id='{self.guild_id}'>" return f"<TextChannel id='{self.id}' name='{self.name}' guild_id='{self.guild_id}'>"