diff --git a/disagreement/__init__.py b/disagreement/__init__.py index 9e92c87..1913bc7 100644 --- a/disagreement/__init__.py +++ b/disagreement/__init__.py @@ -1,5 +1,3 @@ -# disagreement/__init__.py - """ Disagreement ~~~~~~~~~~~~ @@ -31,7 +29,7 @@ from .errors import ( ) from .color import Color from .utils import utcnow, message_pager -from .enums import GatewayIntent, GatewayOpcode # Export enums +from .enums import GatewayIntent, GatewayOpcode from .error_handler import setup_global_error_handler from .hybrid_context import HybridContext from .ext import tasks diff --git a/disagreement/client.py b/disagreement/client.py index e2ff88f..173e0fb 100644 --- a/disagreement/client.py +++ b/disagreement/client.py @@ -1,5 +1,3 @@ -# disagreement/client.py - """ The main Client class for interacting with the Discord API. """ @@ -264,17 +262,16 @@ class Client: raise except DisagreementException as e: # Includes GatewayException print(f"Failed to connect (Attempt {attempt + 1}/{max_retries}): {e}") - if attempt < max_retries - 1: - print(f"Retrying in {retry_delay} seconds...") - await asyncio.sleep(retry_delay) - retry_delay = min( - retry_delay * 2, 60 - ) # Exponential backoff up to 60s - else: - print("Max connection retries reached. Giving up.") - await self.close() # Ensure cleanup - raise - # Should not be reached if max_retries is > 0 + if attempt < max_retries - 1: + print(f"Retrying in {retry_delay} seconds...") + await asyncio.sleep(retry_delay) + retry_delay = min( + retry_delay * 2, 60 + ) # Exponential backoff up to 60s + else: + print("Max connection retries reached. Giving up.") + await self.close() # Ensure cleanup + raise if max_retries == 0: # If max_retries was 0, means no retries attempted raise DisagreementException("Connection failed with 0 retries allowed.") diff --git a/disagreement/enums.py b/disagreement/enums.py index 7b01c72..99418c3 100644 --- a/disagreement/enums.py +++ b/disagreement/enums.py @@ -1,10 +1,8 @@ -# disagreement/enums.py - """ Enums for Discord constants. """ -from enum import IntEnum, Enum # Import Enum +from enum import IntEnum, Enum class GatewayOpcode(IntEnum): diff --git a/disagreement/errors.py b/disagreement/errors.py index b09b59c..9f6566c 100644 --- a/disagreement/errors.py +++ b/disagreement/errors.py @@ -1,10 +1,8 @@ -# disagreement/errors.py - """ Custom exceptions for the Disagreement library. """ -from typing import Optional, Any # Add Optional and Any here +from typing import Optional, Any class DisagreementException(Exception): diff --git a/disagreement/event_dispatcher.py b/disagreement/event_dispatcher.py index 5f4ebd2..d64e6dc 100644 --- a/disagreement/event_dispatcher.py +++ b/disagreement/event_dispatcher.py @@ -1,5 +1,3 @@ -# disagreement/event_dispatcher.py - """ Event dispatcher for handling Discord Gateway events. """ @@ -198,7 +196,7 @@ class EventDispatcher: try: self._listeners[event_name_upper].remove(coro) except ValueError: - pass # Listener not in list + pass def add_waiter( self, diff --git a/disagreement/ext/app_commands/__init__.py b/disagreement/ext/app_commands/__init__.py index 2b84f34..13bdaf3 100644 --- a/disagreement/ext/app_commands/__init__.py +++ b/disagreement/ext/app_commands/__init__.py @@ -1,5 +1,3 @@ -# disagreement/ext/app_commands/__init__.py - """ Application Commands Extension for Disagreement. diff --git a/disagreement/ext/app_commands/commands.py b/disagreement/ext/app_commands/commands.py index ec4b9ce..21f9938 100644 --- a/disagreement/ext/app_commands/commands.py +++ b/disagreement/ext/app_commands/commands.py @@ -1,5 +1,3 @@ -# disagreement/ext/app_commands/commands.py - import inspect from typing import Any, Callable, Dict, List, Optional, Union, TYPE_CHECKING diff --git a/disagreement/ext/app_commands/context.py b/disagreement/ext/app_commands/context.py index d2c5507..b761ca6 100644 --- a/disagreement/ext/app_commands/context.py +++ b/disagreement/ext/app_commands/context.py @@ -1,5 +1,3 @@ -# disagreement/ext/app_commands/context.py - from __future__ import annotations from typing import TYPE_CHECKING, Optional, List, Union, Any, Dict diff --git a/disagreement/ext/app_commands/converters.py b/disagreement/ext/app_commands/converters.py index 23d3e64..7303c4d 100644 --- a/disagreement/ext/app_commands/converters.py +++ b/disagreement/ext/app_commands/converters.py @@ -1,5 +1,3 @@ -# disagreement/ext/app_commands/converters.py - """ Converters for transforming application command option values. """ @@ -466,8 +464,8 @@ async def run_converters( # If no specific converter, and it's not a basic type match, raise error or return raw # For now, let's raise if no converter found for a specific option type - if option_type in DEFAULT_CONVERTERS: # Should have been handled - pass # This path implies a logic error above or missing converter in DEFAULT_CONVERTERS + if option_type in DEFAULT_CONVERTERS: + pass # If it's a model type but no converter yet, this will need to be handled # e.g. if param_type is User and option_type is ApplicationCommandOptionType.USER diff --git a/disagreement/ext/app_commands/decorators.py b/disagreement/ext/app_commands/decorators.py index 16d0dce..8708817 100644 --- a/disagreement/ext/app_commands/decorators.py +++ b/disagreement/ext/app_commands/decorators.py @@ -1,5 +1,3 @@ -# disagreement/ext/app_commands/decorators.py - import inspect import asyncio from dataclasses import dataclass @@ -134,7 +132,7 @@ def _extract_options_from_signature( first_param = next(param_iter, None) # Consume 'self', get next if first_param and first_param.name == "ctx": # Consume 'ctx' - pass # ctx is handled, now iterate over actual command options + pass elif ( first_param ): # If first_param was not 'self' and not 'ctx', it's a command option @@ -147,7 +145,7 @@ def _extract_options_from_signature( if param.kind == param.VAR_POSITIONAL or param.kind == param.VAR_KEYWORD: # *args and **kwargs are not directly supported by slash command options structure. # Could raise an error or ignore. For now, ignore. - # print(f"Warning: *args/**kwargs ({param.name}) are not supported for slash command options.") + continue option_name = param.name @@ -190,7 +188,7 @@ def _extract_options_from_signature( # More complex Unions are not directly supported by a single option type. # Could default to STRING or raise. # For now, let's assume simple Optional[T] or direct types. - # print(f"Warning: Complex Union type for '{option_name}' not fully supported, defaulting to STRING.") + actual_type_for_mapping = str elif origin is list and len(args) == 1: @@ -198,7 +196,7 @@ def _extract_options_from_signature( # via repeated options or specific component interactions, not directly in slash command options. # This might indicate a need for a different interaction pattern or custom parsing. # For now, treat List[str] as a string, others might error or default. - # print(f"Warning: List type for '{option_name}' not directly supported as a single option. Consider type {args[0]}.") + actual_type_for_mapping = args[ 0 ] # Use the inner type for mapping, but this is a simplification. @@ -247,7 +245,7 @@ def _extract_options_from_signature( if not option_type: # Fallback or error if type couldn't be mapped - # print(f"Warning: Could not map type '{actual_type_for_mapping}' for option '{option_name}'. Defaulting to STRING.") + option_type = ApplicationCommandOptionType.STRING # Default fallback required = (param.default == inspect.Parameter.empty) and not is_optional diff --git a/disagreement/ext/app_commands/handler.py b/disagreement/ext/app_commands/handler.py index 7c5e4fa..5e67c61 100644 --- a/disagreement/ext/app_commands/handler.py +++ b/disagreement/ext/app_commands/handler.py @@ -1,5 +1,3 @@ -# disagreement/ext/app_commands/handler.py - import inspect import json import logging @@ -341,7 +339,7 @@ class AppCommandHandler: return value.lower() == "true" return bool(value) except (ValueError, TypeError): - pass # Conversion failed + pass return value # Return as is if no specific resolution or conversion applied async def _resolve_value( diff --git a/disagreement/ext/app_commands/hybrid.py b/disagreement/ext/app_commands/hybrid.py index 48542b2..2843f97 100644 --- a/disagreement/ext/app_commands/hybrid.py +++ b/disagreement/ext/app_commands/hybrid.py @@ -1,5 +1,3 @@ -# disagreement/ext/app_commands/hybrid.py - from typing import Any, Callable, List, Optional from .commands import SlashCommand diff --git a/disagreement/ext/commands/__init__.py b/disagreement/ext/commands/__init__.py index 5e2462c..ef92e0d 100644 --- a/disagreement/ext/commands/__init__.py +++ b/disagreement/ext/commands/__init__.py @@ -1,5 +1,3 @@ -# disagreement/ext/commands/__init__.py - """ disagreement.ext.commands - A command framework extension for the Disagreement library. """ diff --git a/disagreement/ext/commands/cog.py b/disagreement/ext/commands/cog.py index f6f4680..c090605 100644 --- a/disagreement/ext/commands/cog.py +++ b/disagreement/ext/commands/cog.py @@ -1,5 +1,3 @@ -# disagreement/ext/commands/cog.py - import inspect import logging from typing import TYPE_CHECKING, List, Tuple, Callable, Awaitable, Any, Dict, Union diff --git a/disagreement/ext/commands/converters.py b/disagreement/ext/commands/converters.py index e9357f5..05158a7 100644 --- a/disagreement/ext/commands/converters.py +++ b/disagreement/ext/commands/converters.py @@ -1,4 +1,3 @@ -# disagreement/ext/commands/converters.py # pyright: reportIncompatibleMethodOverride=false from typing import TYPE_CHECKING, Any, Awaitable, Callable, TypeVar, Generic diff --git a/disagreement/ext/commands/core.py b/disagreement/ext/commands/core.py index 97ce12e..3a31e3b 100644 --- a/disagreement/ext/commands/core.py +++ b/disagreement/ext/commands/core.py @@ -1,5 +1,3 @@ -# disagreement/ext/commands/core.py - from __future__ import annotations import asyncio @@ -567,9 +565,7 @@ class CommandHandler: # If final_value_for_param was not set by greedy logic, try conversion if final_value_for_param is inspect.Parameter.empty: - if ( - arg_str_value is None - ): # Should not happen if view.get_word/get_quoted_string is robust + if arg_str_value is None: if param.default is not inspect.Parameter.empty: final_value_for_param = param.default else: @@ -609,7 +605,7 @@ class CommandHandler: final_value_for_param = None elif last_err_union: raise last_err_union - else: # Should not be reached if logic is correct + else: raise BadArgument( f"Could not convert '{arg_str_value}' to any of {union_args} for param '{param.name}'." ) diff --git a/disagreement/ext/commands/decorators.py b/disagreement/ext/commands/decorators.py index b2d6680..15ab249 100644 --- a/disagreement/ext/commands/decorators.py +++ b/disagreement/ext/commands/decorators.py @@ -1,4 +1,3 @@ -# disagreement/ext/commands/decorators.py from __future__ import annotations import asyncio diff --git a/disagreement/ext/commands/errors.py b/disagreement/ext/commands/errors.py index 0600ad7..f91799f 100644 --- a/disagreement/ext/commands/errors.py +++ b/disagreement/ext/commands/errors.py @@ -1,5 +1,3 @@ -# disagreement/ext/commands/errors.py - """ Custom exceptions for the command extension. """ diff --git a/disagreement/ext/commands/help.py b/disagreement/ext/commands/help.py index f81c961..61c69d1 100644 --- a/disagreement/ext/commands/help.py +++ b/disagreement/ext/commands/help.py @@ -1,5 +1,3 @@ -# disagreement/ext/commands/help.py - from typing import List, Optional from .core import Command, CommandContext, CommandHandler diff --git a/disagreement/ext/commands/view.py b/disagreement/ext/commands/view.py index d691266..5a6540c 100644 --- a/disagreement/ext/commands/view.py +++ b/disagreement/ext/commands/view.py @@ -1,5 +1,3 @@ -# disagreement/ext/commands/view.py - import re @@ -47,7 +45,7 @@ class StringView: word = match.group(0) self.index += len(word) return word - return "" # Should not happen if not eof and skip_whitespace was called + return "" def get_quoted_string(self) -> str: """ diff --git a/disagreement/gateway.py b/disagreement/gateway.py index 2cc8a81..4559e6f 100644 --- a/disagreement/gateway.py +++ b/disagreement/gateway.py @@ -1,5 +1,3 @@ -# disagreement/gateway.py - """ Manages the WebSocket connection to the Discord Gateway. """ @@ -152,12 +150,11 @@ class GatewayClient: self._last_heartbeat_sent = time.monotonic() payload = {"op": GatewayOpcode.HEARTBEAT, "d": self._last_sequence} await self._send_json(payload) - # print("Sent heartbeat.") async def _keep_alive(self): """Manages the heartbeating loop.""" if self._heartbeat_interval is None: - # This should not happen if HELLO was processed correctly + logger.error("Heartbeat interval not set. Cannot start keep_alive.") return @@ -358,7 +355,7 @@ class GatewayClient: del self._member_chunk_requests[nonce] elif event_name == "INTERACTION_CREATE": - # print(f"GATEWAY RECV INTERACTION_CREATE: {raw_event_d_payload}") + if isinstance(raw_event_d_payload, dict): interaction = Interaction( data=raw_event_d_payload, client_instance=self._client_instance @@ -397,7 +394,7 @@ class GatewayClient: event_data_to_dispatch = ( raw_event_d_payload if isinstance(raw_event_d_payload, dict) else {} ) - # print(f"GATEWAY RECV EVENT: {event_name} | DATA: {event_data_to_dispatch}") + await self._dispatcher.dispatch(event_name, event_data_to_dispatch) else: logger.warning("Received dispatch with no event name: %s", data) @@ -496,8 +493,6 @@ class GatewayClient: await self._identify() elif op == GatewayOpcode.HEARTBEAT_ACK: self._last_heartbeat_ack = time.monotonic() - # print("Received heartbeat ACK.") - pass # Good, connection is alive else: logger.warning( "Received unhandled Gateway Opcode: %s with data: %s", op, data @@ -584,7 +579,7 @@ class GatewayClient: try: await self._keep_alive_task except asyncio.CancelledError: - pass # Expected + pass if self._receive_task and not self._receive_task.done(): current = asyncio.current_task(loop=self._loop) @@ -593,7 +588,7 @@ class GatewayClient: try: await self._receive_task except asyncio.CancelledError: - pass # Expected + pass if self._ws and not self._ws.closed: await self._ws.close(code=code) diff --git a/disagreement/http.py b/disagreement/http.py index 78157a3..75e845c 100644 --- a/disagreement/http.py +++ b/disagreement/http.py @@ -1,5 +1,3 @@ -# disagreement/http.py - """ HTTP client for interacting with the Discord REST API. """ @@ -447,8 +445,6 @@ class HTTPClient: text=error_text, error_code=discord_error_code, ) - - # Should not be reached if retries are exhausted by RateLimitError raise DisagreementException( f"Failed request to {method} {endpoint} after multiple retries." ) diff --git a/disagreement/interactions.py b/disagreement/interactions.py index 8bca1eb..d891a2b 100644 --- a/disagreement/interactions.py +++ b/disagreement/interactions.py @@ -1,5 +1,3 @@ -# disagreement/interactions.py - """ Data models for Discord Interaction objects. """ diff --git a/disagreement/models.py b/disagreement/models.py index 79329a7..f10731b 100644 --- a/disagreement/models.py +++ b/disagreement/models.py @@ -1,5 +1,3 @@ -# disagreement/models.py - """ Data models for Discord objects. """ @@ -714,7 +712,7 @@ class Member(User): # Member inherits from User # We'd need to construct a partial user from top-level member fields if 'user' is missing. # For now, assume 'user' object is present for full Member hydration. # If 'user' is missing, the User part might be incomplete. - pass # User fields will be missing or default if 'user' not in data. + pass super().__init__( user_data if user_data else data diff --git a/disagreement/shard_manager.py b/disagreement/shard_manager.py index 2a57d20..5ded89d 100644 --- a/disagreement/shard_manager.py +++ b/disagreement/shard_manager.py @@ -1,5 +1,3 @@ -# disagreement/shard_manager.py - """Sharding utilities for managing multiple gateway connections.""" from __future__ import annotations diff --git a/disagreement/ui/view.py b/disagreement/ui/view.py index 3e17b28..09b9fc0 100644 --- a/disagreement/ui/view.py +++ b/disagreement/ui/view.py @@ -147,7 +147,7 @@ class View: async def on_timeout(self): """Called when the view times out.""" - pass # User can override this + pass async def _start(self, client: Client): """Starts the view's internal listener.""" diff --git a/disagreement/voice_client.py b/disagreement/voice_client.py index 8696665..bd3cd62 100644 --- a/disagreement/voice_client.py +++ b/disagreement/voice_client.py @@ -1,4 +1,3 @@ -# disagreement/voice_client.py """Voice gateway and UDP audio client.""" from __future__ import annotations