pyyapper 1.6.0__tar.gz → 1.8.0__tar.gz
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.
- {pyyapper-1.6.0/src/pyyapper.egg-info → pyyapper-1.8.0}/PKG-INFO +1 -1
- {pyyapper-1.6.0 → pyyapper-1.8.0}/pyproject.toml +1 -1
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper/__init__.py +3 -2
- pyyapper-1.8.0/src/pyyapper/_version.py +1 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper/bot.py +119 -10
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper/errors.py +12 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper/http.py +25 -3
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper/models.py +35 -1
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper/oauth.py +2 -2
- pyyapper-1.8.0/src/pyyapper/voice.py +44 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper/webhooks.py +2 -2
- {pyyapper-1.6.0 → pyyapper-1.8.0/src/pyyapper.egg-info}/PKG-INFO +1 -1
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper.egg-info/SOURCES.txt +1 -0
- pyyapper-1.6.0/src/pyyapper/_version.py +0 -1
- {pyyapper-1.6.0 → pyyapper-1.8.0}/LICENSE +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/README.md +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/setup.cfg +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper/buttons.py +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper/cache.py +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper/commands.py +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper/components_v2.py +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper/config.py +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper/embeds.py +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper/ext/__init__.py +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper/ext/commands/__init__.py +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper/ext/commands/checks.py +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper/ext/commands/converters.py +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper/ext/commands/core.py +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper/ext/commands/errors.py +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper/ext/tasks.py +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper/i18n.py +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper/metrics.py +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper/pagination.py +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper/presence.py +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper/py.typed +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper/wait_for.py +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper.egg-info/dependency_links.txt +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper.egg-info/requires.txt +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/src/pyyapper.egg-info/top_level.txt +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/tests/test_ext_commands.py +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/tests/test_oauth.py +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/tests/test_smoke.py +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/tests/test_tasks.py +0 -0
- {pyyapper-1.6.0 → pyyapper-1.8.0}/tests/test_webhooks.py +0 -0
|
@@ -17,8 +17,9 @@ from .errors import (
|
|
|
17
17
|
ServiceUnavailable,
|
|
18
18
|
)
|
|
19
19
|
from .models import (
|
|
20
|
-
User, Server, Channel, Category, Member, Message, Role, VoiceChannel, picture_url,
|
|
20
|
+
User, Server, Channel, Category, Member, Message, Role, VoiceChannel, Thread, picture_url,
|
|
21
21
|
)
|
|
22
|
+
from .voice import VoiceCall
|
|
22
23
|
from .presence import Activity, Presence
|
|
23
24
|
from .pagination import Paginator
|
|
24
25
|
from .webhooks import Webhook
|
|
@@ -43,7 +44,7 @@ __all__ = [
|
|
|
43
44
|
"Embed", "Button", "Row",
|
|
44
45
|
"YapperError", "ConfigurationError", "HTTPException",
|
|
45
46
|
"BadRequest", "Unauthorized", "Forbidden", "NotFound", "RateLimited", "ServerError", "ServiceUnavailable",
|
|
46
|
-
"User", "Server", "Channel", "Category", "Member", "Message", "Role", "VoiceChannel", "picture_url",
|
|
47
|
+
"User", "Server", "Channel", "Category", "Member", "Message", "Role", "VoiceChannel", "Thread", "picture_url", "VoiceCall",
|
|
47
48
|
"Activity", "Presence",
|
|
48
49
|
"Paginator", "Webhook", "WaiterRegistry", "wait_for",
|
|
49
50
|
"OAuth2Client", "OAuthError", "generate_state", "generate_pkce",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.8.0"
|
|
@@ -27,7 +27,8 @@ from .buttons import Button, Row
|
|
|
27
27
|
|
|
28
28
|
# Event names that are valid.
|
|
29
29
|
EVENTS = {
|
|
30
|
-
"message", "
|
|
30
|
+
"message", "message_update", "message_delete", "command", "command_error",
|
|
31
|
+
"member_join", "member_leave", "server_add", "server_remove",
|
|
31
32
|
"reaction_add", "reaction_remove", "voice_join", "voice_leave",
|
|
32
33
|
"interaction", "test", "ready", "error",
|
|
33
34
|
}
|
|
@@ -183,7 +184,7 @@ class Bot:
|
|
|
183
184
|
self,
|
|
184
185
|
token: Optional[str] = None,
|
|
185
186
|
*,
|
|
186
|
-
base_url: str = "https://www.
|
|
187
|
+
base_url: str = "https://www.yapin.gg/api/bot/v1",
|
|
187
188
|
prefixes: Optional[list[str]] = None,
|
|
188
189
|
log: Any = True,
|
|
189
190
|
ignore_bots: bool = True,
|
|
@@ -541,6 +542,7 @@ class Bot:
|
|
|
541
542
|
reply_to: Optional[str] = None,
|
|
542
543
|
embeds: Any = None,
|
|
543
544
|
components: Any = None,
|
|
545
|
+
nonce: Any = None,
|
|
544
546
|
**opts: Any,
|
|
545
547
|
) -> Any:
|
|
546
548
|
body: dict[str, Any] = {"content": "" if content is None else str(content)}
|
|
@@ -550,6 +552,8 @@ class Bot:
|
|
|
550
552
|
body["embeds"] = _list(embeds)
|
|
551
553
|
if components is not None:
|
|
552
554
|
body["components"] = _list(components)
|
|
555
|
+
if nonce is not None:
|
|
556
|
+
body["nonce"] = nonce
|
|
553
557
|
# merge opts
|
|
554
558
|
for k, v in opts.items():
|
|
555
559
|
if k in ("embeds", "components"):
|
|
@@ -564,11 +568,13 @@ class Bot:
|
|
|
564
568
|
return self.send(channel_id, content, embeds=[embed])
|
|
565
569
|
|
|
566
570
|
async def send_layout(self, channel_id: Any, components: Any, *, reply_to: Any = None,
|
|
567
|
-
flags: int = 32768) -> Any:
|
|
571
|
+
flags: int = 32768, nonce: Any = None) -> Any:
|
|
568
572
|
from .components_v2 import normalize_components
|
|
569
573
|
body: dict[str, Any] = {"flags": flags, "components": normalize_components(components)}
|
|
570
574
|
if reply_to is not None:
|
|
571
575
|
body["reply_to"] = reply_to
|
|
576
|
+
if nonce is not None:
|
|
577
|
+
body["nonce"] = nonce
|
|
572
578
|
out = await self.api("POST", f"/channels/{channel_id}/messages", body)
|
|
573
579
|
msg = out.get("message") if isinstance(out, dict) else None
|
|
574
580
|
return msg if msg is not None else out
|
|
@@ -757,14 +763,26 @@ class Bot:
|
|
|
757
763
|
from urllib.parse import quote
|
|
758
764
|
return await self.api("PUT", f"/channels/{channel_id}/messages/{message_id}/reactions/{quote(emoji, safe='')}")
|
|
759
765
|
|
|
760
|
-
async def unreact(self, channel_id: Any, message_id: Any, emoji: str
|
|
761
|
-
|
|
762
|
-
|
|
766
|
+
async def unreact(self, channel_id: Any, message_id: Any, emoji: str, *,
|
|
767
|
+
user_id: Any = None, all: bool = False) -> Any:
|
|
768
|
+
from urllib.parse import quote, urlencode
|
|
769
|
+
path = f"/channels/{channel_id}/messages/{message_id}/reactions/{quote(emoji, safe='')}"
|
|
770
|
+
params = {}
|
|
771
|
+
if user_id is not None:
|
|
772
|
+
params["user_id"] = user_id
|
|
773
|
+
if all:
|
|
774
|
+
params["all"] = "true"
|
|
775
|
+
if params:
|
|
776
|
+
path += "?" + urlencode(params)
|
|
777
|
+
return await self.api("DELETE", path)
|
|
763
778
|
|
|
764
779
|
async def reactions(self, channel_id: Any, message_id: Any) -> Any:
|
|
765
780
|
out = await self.api("GET", f"/channels/{channel_id}/messages/{message_id}/reactions")
|
|
766
781
|
return out.get("reactions") if isinstance(out, dict) else out
|
|
767
782
|
|
|
783
|
+
async def clear_reactions(self, channel_id: Any, message_id: Any) -> Any:
|
|
784
|
+
return await self.api("DELETE", f"/channels/{channel_id}/messages/{message_id}/reactions")
|
|
785
|
+
|
|
768
786
|
# ------------------------------------------------------------------ #
|
|
769
787
|
# Moderation
|
|
770
788
|
# ------------------------------------------------------------------ #
|
|
@@ -848,13 +866,57 @@ class Bot:
|
|
|
848
866
|
"user_id": user_id,
|
|
849
867
|
})
|
|
850
868
|
|
|
869
|
+
# Voice (music): bot joins a voice channel and plays audio
|
|
870
|
+
async def join_voice(self, server_id: Any, channel_id: Any) -> Any:
|
|
871
|
+
"""Join a voice channel. Returns a LiveKit ticket dict."""
|
|
872
|
+
return await self.api("POST", f"/servers/{server_id}/voice/join", {
|
|
873
|
+
"channel_id": channel_id,
|
|
874
|
+
})
|
|
875
|
+
|
|
876
|
+
async def leave_voice(self, server_id: Any) -> Any:
|
|
877
|
+
"""Leave voice in a server."""
|
|
878
|
+
return await self.api("POST", f"/servers/{server_id}/voice/leave", {})
|
|
879
|
+
|
|
880
|
+
async def connect_voice(self, server_id: Any, channel_id: Any, livekit_module: Any = None) -> Any:
|
|
881
|
+
"""Join voice and return a ticket.
|
|
882
|
+
|
|
883
|
+
If ``livekit_module`` (e.g. ``livekit.rtc``) is provided and installed,
|
|
884
|
+
returns a small helper object exposing ``.source`` (an audio source) and
|
|
885
|
+
``.leave()``. Otherwise returns the raw ticket dict from the API.
|
|
886
|
+
"""
|
|
887
|
+
ticket = await self.join_voice(server_id, channel_id)
|
|
888
|
+
if livekit_module is None:
|
|
889
|
+
return ticket
|
|
890
|
+
# Best-effort LiveKit connection. E2EE key exchange is handled by the
|
|
891
|
+
# caller per the docs; here we just open the room and expose a source.
|
|
892
|
+
try:
|
|
893
|
+
from .voice import VoiceCall
|
|
894
|
+
room = livekit_module.Room()
|
|
895
|
+
source = livekit_module.AudioSource(48000, 2)
|
|
896
|
+
track = livekit_module.LocalAudioTrack.create_audio_track("bot-audio", source)
|
|
897
|
+
await room.connect(ticket["url"], ticket["token"])
|
|
898
|
+
await room.local_participant.publish_track(track)
|
|
899
|
+
obj = VoiceCall(room, source, self, server_id, ticket=ticket)
|
|
900
|
+
return obj
|
|
901
|
+
except Exception as e:
|
|
902
|
+
# Fall back to raw ticket if LiveKit isn't available/compatible.
|
|
903
|
+
if hasattr(self, "logger"):
|
|
904
|
+
self.logger.warning("connect_voice LiveKit setup failed: %s", e)
|
|
905
|
+
return ticket
|
|
906
|
+
|
|
851
907
|
# ------------------------------------------------------------------ #
|
|
852
908
|
# Channels management
|
|
853
909
|
# ------------------------------------------------------------------ #
|
|
854
|
-
async def create_channel(self, server_id: Any, name: str, *, kind: str = "text", category_id: Any = None
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
910
|
+
async def create_channel(self, server_id: Any, name: str, *, kind: str = "text", category_id: Any = None,
|
|
911
|
+
private: bool = False, role_ids: Any = None, user_ids: Any = None) -> Any:
|
|
912
|
+
body: dict[str, Any] = {"name": name, "kind": kind, "category_id": category_id}
|
|
913
|
+
if private:
|
|
914
|
+
body["private"] = True
|
|
915
|
+
if role_ids is not None:
|
|
916
|
+
body["role_ids"] = list(role_ids)
|
|
917
|
+
if user_ids is not None:
|
|
918
|
+
body["user_ids"] = list(user_ids)
|
|
919
|
+
out = await self.api("POST", f"/servers/{server_id}/channels", body)
|
|
858
920
|
return out.get("channel") if isinstance(out, dict) else out
|
|
859
921
|
|
|
860
922
|
async def edit_channel(self, channel_id: Any, **changes: Any) -> Any:
|
|
@@ -888,6 +950,49 @@ class Bot:
|
|
|
888
950
|
async def delete_category(self, server_id: Any, category_id: Any) -> Any:
|
|
889
951
|
return await self.api("DELETE", f"/servers/{server_id}/categories/{category_id}")
|
|
890
952
|
|
|
953
|
+
# ------------------------------------------------------------------ #
|
|
954
|
+
# Threads
|
|
955
|
+
# ------------------------------------------------------------------ #
|
|
956
|
+
async def threads(self, channel_id: Any, limit: int = 25) -> list:
|
|
957
|
+
from .models import Thread
|
|
958
|
+
out = await self.api("GET", f"/channels/{channel_id}/threads?limit={limit}")
|
|
959
|
+
ts = out.get("threads", []) if isinstance(out, dict) else []
|
|
960
|
+
return [Thread.from_dict(t) for t in (ts or [])]
|
|
961
|
+
|
|
962
|
+
async def create_thread(self, channel_id: Any, *, name: Optional[str] = None,
|
|
963
|
+
message_id: Any = None, content: str = "",
|
|
964
|
+
embeds: Any = None, components: Any = None) -> Any:
|
|
965
|
+
from .models import Thread
|
|
966
|
+
body: dict[str, Any] = {}
|
|
967
|
+
if name is not None:
|
|
968
|
+
body["name"] = name
|
|
969
|
+
if message_id is not None:
|
|
970
|
+
body["message_id"] = message_id
|
|
971
|
+
if content:
|
|
972
|
+
body["content"] = content
|
|
973
|
+
if embeds is not None:
|
|
974
|
+
body["embeds"] = _list(embeds)
|
|
975
|
+
if components is not None:
|
|
976
|
+
body["components"] = _list(components)
|
|
977
|
+
out = await self.api("POST", f"/channels/{channel_id}/threads", body)
|
|
978
|
+
thread = out.get("thread") if isinstance(out, dict) else None
|
|
979
|
+
message = out.get("message") if isinstance(out, dict) else None
|
|
980
|
+
return {"thread": Thread.from_dict(thread) if thread else None, "message": message}
|
|
981
|
+
|
|
982
|
+
async def edit_thread(self, thread_id: Any, *, name: Optional[str] = None,
|
|
983
|
+
locked: Optional[bool] = None, archived: Optional[bool] = None) -> Any:
|
|
984
|
+
body: dict[str, Any] = {}
|
|
985
|
+
if name is not None:
|
|
986
|
+
body["name"] = name
|
|
987
|
+
if locked is not None:
|
|
988
|
+
body["locked"] = bool(locked)
|
|
989
|
+
if archived is not None:
|
|
990
|
+
body["archived"] = bool(archived)
|
|
991
|
+
return await self.api("PATCH", f"/threads/{thread_id}", body)
|
|
992
|
+
|
|
993
|
+
async def delete_thread(self, thread_id: Any) -> Any:
|
|
994
|
+
return await self.api("DELETE", f"/threads/{thread_id}")
|
|
995
|
+
|
|
891
996
|
# ------------------------------------------------------------------ #
|
|
892
997
|
# DMs
|
|
893
998
|
# ------------------------------------------------------------------ #
|
|
@@ -1111,6 +1216,10 @@ class Bot:
|
|
|
1111
1216
|
if m and m.group(1) in self.prefixes and m.group(2).lower() in self.commands:
|
|
1112
1217
|
name = m.group(2).lower()
|
|
1113
1218
|
args = (m.group(3) or "").strip()
|
|
1219
|
+
# If command_for is set and points at another bot, don't handle.
|
|
1220
|
+
command_for = data.get("command_for")
|
|
1221
|
+
if command_for and self.me is not None and command_for != getattr(self.me, "id", None):
|
|
1222
|
+
name = None
|
|
1114
1223
|
if name and name in self.commands:
|
|
1115
1224
|
ctx.command = name
|
|
1116
1225
|
ctx.args = args or ""
|
|
@@ -22,8 +22,12 @@ class HTTPException(YapperError):
|
|
|
22
22
|
|
|
23
23
|
Attributes:
|
|
24
24
|
status: HTTP status code returned by the server.
|
|
25
|
+
code: Stable error code from the server (e.g. ``missing_permission``).
|
|
25
26
|
error: Human readable error message from the server (or a fallback).
|
|
26
27
|
retry_after: Seconds to wait before retrying, when the server sent one.
|
|
28
|
+
permission: The permission needed (when ``code == missing_permission``).
|
|
29
|
+
permissions: List of acceptable permissions.
|
|
30
|
+
allow: Allowed HTTP methods (when ``code == method_not_allowed``).
|
|
27
31
|
method: HTTP method of the failed request.
|
|
28
32
|
path: API path of the failed request.
|
|
29
33
|
"""
|
|
@@ -36,12 +40,20 @@ class HTTPException(YapperError):
|
|
|
36
40
|
method: str = "",
|
|
37
41
|
path: str = "",
|
|
38
42
|
retry_after: float | None = None,
|
|
43
|
+
code: str = "",
|
|
44
|
+
permission: str | None = None,
|
|
45
|
+
permissions: list[str] | None = None,
|
|
46
|
+
allow: list[str] | None = None,
|
|
39
47
|
) -> None:
|
|
40
48
|
self.status = status
|
|
49
|
+
self.code = code or ""
|
|
41
50
|
self.error = error or f"HTTP {status}"
|
|
42
51
|
self.method = method
|
|
43
52
|
self.path = path
|
|
44
53
|
self.retry_after = retry_after
|
|
54
|
+
self.permission = permission
|
|
55
|
+
self.permissions = permissions or []
|
|
56
|
+
self.allow = allow or []
|
|
45
57
|
super().__init__(f"{method} {path} failed ({status}): {self.error}".strip())
|
|
46
58
|
|
|
47
59
|
def __repr__(self) -> str: # pragma: no cover - cosmetic
|
|
@@ -43,7 +43,7 @@ from .errors import (
|
|
|
43
43
|
exception_for_status,
|
|
44
44
|
)
|
|
45
45
|
|
|
46
|
-
DEFAULT_BASE = "https://www.
|
|
46
|
+
DEFAULT_BASE = "https://www.yapin.gg/api/bot/v1"
|
|
47
47
|
USER_AGENT = "pyyapper/1.0"
|
|
48
48
|
|
|
49
49
|
|
|
@@ -138,8 +138,21 @@ class HTTPClient:
|
|
|
138
138
|
return payload
|
|
139
139
|
# error path
|
|
140
140
|
err_msg = ""
|
|
141
|
+
err_code = ""
|
|
142
|
+
permission = None
|
|
143
|
+
permissions = None
|
|
144
|
+
allow = None
|
|
141
145
|
if isinstance(payload, dict):
|
|
142
146
|
err_msg = payload.get("error") or payload.get("message") or ""
|
|
147
|
+
err_code = payload.get("code") or ""
|
|
148
|
+
permission = payload.get("permission")
|
|
149
|
+
permissions = payload.get("permissions")
|
|
150
|
+
allow = payload.get("allow")
|
|
151
|
+
if retry_after is None and payload.get("retry_after") is not None:
|
|
152
|
+
try:
|
|
153
|
+
retry_after = float(payload.get("retry_after"))
|
|
154
|
+
except (TypeError, ValueError):
|
|
155
|
+
pass
|
|
143
156
|
retry_after = None
|
|
144
157
|
ra = res.headers.get("Retry-After")
|
|
145
158
|
if ra is not None:
|
|
@@ -147,8 +160,13 @@ class HTTPClient:
|
|
|
147
160
|
retry_after = float(ra)
|
|
148
161
|
except ValueError:
|
|
149
162
|
retry_after = None
|
|
150
|
-
|
|
151
|
-
|
|
163
|
+
if retry_after is None and isinstance(payload, dict) and payload.get("retry_after") is not None:
|
|
164
|
+
try:
|
|
165
|
+
retry_after = float(payload.get("retry_after"))
|
|
166
|
+
except (TypeError, ValueError):
|
|
167
|
+
retry_after = None
|
|
168
|
+
# retry on 429 / 503 / 502 with Retry-After
|
|
169
|
+
if res.status in (429, 503, 502) and retry_after and retry_after > 0 and attempt < retries:
|
|
152
170
|
cap = 60 if res.status == 429 else 30
|
|
153
171
|
if retry_after <= cap:
|
|
154
172
|
if self.log:
|
|
@@ -162,6 +180,10 @@ class HTTPClient:
|
|
|
162
180
|
method=method,
|
|
163
181
|
path=path,
|
|
164
182
|
retry_after=retry_after,
|
|
183
|
+
code=err_code,
|
|
184
|
+
permission=permission,
|
|
185
|
+
permissions=permissions,
|
|
186
|
+
allow=allow,
|
|
165
187
|
)
|
|
166
188
|
except (aiohttp.ClientError, asyncio.TimeoutError) as e:
|
|
167
189
|
if attempt < retries:
|
|
@@ -49,7 +49,7 @@ def picture_url(bucket: str, path: Any) -> Optional[str]:
|
|
|
49
49
|
return None
|
|
50
50
|
p = str(path)
|
|
51
51
|
if p.startswith("/"):
|
|
52
|
-
return "https://www.
|
|
52
|
+
return "https://www.yapin.gg" + p
|
|
53
53
|
return f"https://files.yapper.website/{bucket}/{p}"
|
|
54
54
|
|
|
55
55
|
|
|
@@ -275,4 +275,38 @@ class VoiceChannel(_Model):
|
|
|
275
275
|
channel_id=data.get("channel_id", "") or "",
|
|
276
276
|
user_ids=list(data.get("user_ids") or []),
|
|
277
277
|
raw=dict(data),
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
@dataclass
|
|
282
|
+
class Thread(_Model):
|
|
283
|
+
id: str = ""
|
|
284
|
+
name: str = ""
|
|
285
|
+
kind: str = "thread"
|
|
286
|
+
parent_id: Optional[str] = None
|
|
287
|
+
server_id: Optional[str] = None
|
|
288
|
+
created_by: Optional[str] = None
|
|
289
|
+
created_at: Optional[str] = None
|
|
290
|
+
last_message_at: Optional[str] = None
|
|
291
|
+
archived: bool = False
|
|
292
|
+
locked: bool = False
|
|
293
|
+
starter_message_id: Optional[str] = None
|
|
294
|
+
raw: dict[str, Any] = field(default_factory=dict, repr=False)
|
|
295
|
+
|
|
296
|
+
@classmethod
|
|
297
|
+
def from_dict(cls, data: dict[str, Any] | None) -> "Thread":
|
|
298
|
+
data = data or {}
|
|
299
|
+
return cls(
|
|
300
|
+
id=data.get("id", "") or "",
|
|
301
|
+
name=data.get("name", "") or "",
|
|
302
|
+
kind=data.get("kind", "thread") or "thread",
|
|
303
|
+
parent_id=data.get("parent_id"),
|
|
304
|
+
server_id=data.get("server_id"),
|
|
305
|
+
created_by=data.get("created_by"),
|
|
306
|
+
created_at=data.get("created_at"),
|
|
307
|
+
last_message_at=data.get("last_message_at"),
|
|
308
|
+
archived=bool(data.get("archived", False)),
|
|
309
|
+
locked=bool(data.get("locked", False)),
|
|
310
|
+
starter_message_id=data.get("starter_message_id"),
|
|
311
|
+
raw=dict(data),
|
|
278
312
|
)
|
|
@@ -36,7 +36,7 @@ class OAuthError(YapperError):
|
|
|
36
36
|
super().__init__(f"{error}: {description}".strip(": "))
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
DEFAULT_BASE = "https://www.
|
|
39
|
+
DEFAULT_BASE = "https://www.yapin.gg"
|
|
40
40
|
AUTHORIZE_PATH = "/oauth/authorize"
|
|
41
41
|
TOKEN_PATH = "/api/oauth/token"
|
|
42
42
|
ME_PATH = "/api/oauth/me"
|
|
@@ -72,7 +72,7 @@ class OAuth2Client:
|
|
|
72
72
|
redirect_uri:
|
|
73
73
|
Default redirect URI (must match one registered for the app).
|
|
74
74
|
base_url:
|
|
75
|
-
Yapper base URL. Defaults to ``https://www.
|
|
75
|
+
Yapper base URL. Defaults to ``https://www.yapin.gg``.
|
|
76
76
|
session:
|
|
77
77
|
Optional shared :class:`aiohttp.ClientSession`.
|
|
78
78
|
"""
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Voice connection helpers for PyYapper (music bots)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class VoiceCall:
|
|
9
|
+
"""A handle to an active voice connection.
|
|
10
|
+
|
|
11
|
+
Attributes:
|
|
12
|
+
room: the LiveKit room (if connected).
|
|
13
|
+
source: the audio source to capture frames into.
|
|
14
|
+
ticket: the raw ticket returned by the API.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def __init__(self, room: Any, source: Any, bot: Any, server_id: Any, ticket: Any = None) -> None:
|
|
18
|
+
self.room = room
|
|
19
|
+
self.source = source
|
|
20
|
+
self.bot = bot
|
|
21
|
+
self.server_id = server_id
|
|
22
|
+
self.ticket = ticket
|
|
23
|
+
|
|
24
|
+
async def leave(self) -> Any:
|
|
25
|
+
try:
|
|
26
|
+
if self.room is not None:
|
|
27
|
+
await self.room.disconnect()
|
|
28
|
+
except Exception:
|
|
29
|
+
pass
|
|
30
|
+
try:
|
|
31
|
+
await self.bot.leave_voice(self.server_id)
|
|
32
|
+
except Exception:
|
|
33
|
+
pass
|
|
34
|
+
return None
|
|
35
|
+
|
|
36
|
+
async def capture_frame(self, frame: Any) -> Any:
|
|
37
|
+
if self.source is not None and hasattr(self.source, "capture_frame"):
|
|
38
|
+
return await self.source.capture_frame(frame)
|
|
39
|
+
return None
|
|
40
|
+
|
|
41
|
+
async def wait_for_playout(self) -> Any:
|
|
42
|
+
if self.source is not None and hasattr(self.source, "wait_for_playout"):
|
|
43
|
+
return await self.source.wait_for_playout()
|
|
44
|
+
return None
|
|
@@ -35,7 +35,7 @@ import aiohttp
|
|
|
35
35
|
|
|
36
36
|
from .errors import HTTPException, RateLimited, exception_for_status
|
|
37
37
|
|
|
38
|
-
WEBHOOK_BASE = "https://www.
|
|
38
|
+
WEBHOOK_BASE = "https://www.yapin.gg/api/webhooks"
|
|
39
39
|
USER_AGENT = "pyyapper/1.0"
|
|
40
40
|
|
|
41
41
|
|
|
@@ -191,7 +191,7 @@ class Webhook:
|
|
|
191
191
|
except (TypeError, ValueError):
|
|
192
192
|
retry_after = None
|
|
193
193
|
if (
|
|
194
|
-
res.status in (429, 503)
|
|
194
|
+
res.status in (429, 503, 502)
|
|
195
195
|
and retry_after is not None
|
|
196
196
|
and retry_after > 0
|
|
197
197
|
and attempt < retries
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "1.6.0"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|