disagreement 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,36 @@
1
+ # disagreement/__init__.py
2
+
3
+ """
4
+ Disagreement
5
+ ~~~~~~~~~~~~
6
+
7
+ A Python library for interacting with the Discord API.
8
+
9
+ :copyright: (c) 2025 Slipstream
10
+ :license: BSD 3-Clause License, see LICENSE for more details.
11
+ """
12
+
13
+ __title__ = "disagreement"
14
+ __author__ = "Slipstream"
15
+ __license__ = "BSD 3-Clause License"
16
+ __copyright__ = "Copyright 2025 Slipstream"
17
+ __version__ = "0.0.1"
18
+
19
+ from .client import Client
20
+ from .models import Message, User
21
+ from .voice_client import VoiceClient
22
+ from .typing import Typing
23
+ from .errors import (
24
+ DisagreementException,
25
+ HTTPException,
26
+ GatewayException,
27
+ AuthenticationError,
28
+ )
29
+ from .enums import GatewayIntent, GatewayOpcode # Export enums
30
+ from .error_handler import setup_global_error_handler
31
+ from .hybrid_context import HybridContext
32
+ from .ext import tasks
33
+
34
+ # Set up logging if desired
35
+ # import logging
36
+ # logging.getLogger(__name__).addHandler(logging.NullHandler())
disagreement/cache.py ADDED
@@ -0,0 +1,55 @@
1
+ from __future__ import annotations
2
+
3
+ import time
4
+ from typing import TYPE_CHECKING, Dict, Generic, Optional, TypeVar
5
+
6
+ if TYPE_CHECKING:
7
+ from .models import Channel, Guild
8
+
9
+ T = TypeVar("T")
10
+
11
+
12
+ class Cache(Generic[T]):
13
+ """Simple in-memory cache with optional TTL support."""
14
+
15
+ def __init__(self, ttl: Optional[float] = None) -> None:
16
+ self.ttl = ttl
17
+ self._data: Dict[str, tuple[T, Optional[float]]] = {}
18
+
19
+ def set(self, key: str, value: T) -> None:
20
+ expiry = time.monotonic() + self.ttl if self.ttl is not None else None
21
+ self._data[key] = (value, expiry)
22
+
23
+ def get(self, key: str) -> Optional[T]:
24
+ item = self._data.get(key)
25
+ if not item:
26
+ return None
27
+ value, expiry = item
28
+ if expiry is not None and expiry < time.monotonic():
29
+ self.invalidate(key)
30
+ return None
31
+ return value
32
+
33
+ def invalidate(self, key: str) -> None:
34
+ self._data.pop(key, None)
35
+
36
+ def clear(self) -> None:
37
+ self._data.clear()
38
+
39
+ def values(self) -> list[T]:
40
+ now = time.monotonic()
41
+ items = []
42
+ for key, (value, expiry) in list(self._data.items()):
43
+ if expiry is not None and expiry < now:
44
+ self.invalidate(key)
45
+ else:
46
+ items.append(value)
47
+ return items
48
+
49
+
50
+ class GuildCache(Cache["Guild"]):
51
+ """Cache specifically for :class:`Guild` objects."""
52
+
53
+
54
+ class ChannelCache(Cache["Channel"]):
55
+ """Cache specifically for :class:`Channel` objects."""