loopbot-discord-sdk 1.0.5__py3-none-any.whl → 1.0.6__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.
loopbot/__init__.py CHANGED
@@ -5,6 +5,7 @@ Build Discord bots without websockets using HTTP Interactions
5
5
 
6
6
  from .bot import Bot
7
7
  from .client import Client
8
+ from .database import Database
8
9
  from .builders import (
9
10
  EmbedBuilder,
10
11
  ButtonBuilder,
@@ -35,6 +36,7 @@ __all__ = [
35
36
  # Core
36
37
  "Bot",
37
38
  "Client",
39
+ "Database",
38
40
  # Builders
39
41
  "EmbedBuilder",
40
42
  "ButtonBuilder",
loopbot/bot.py CHANGED
@@ -7,6 +7,7 @@ import signal
7
7
  from typing import Any, Callable, Dict, List, Optional, Union
8
8
 
9
9
  from .client import Client
10
+ from .database import Database
10
11
  from .context.command import CommandContext
11
12
  from .context.button import ButtonContext
12
13
  from .context.modal import ModalContext
@@ -60,6 +61,7 @@ class Bot:
60
61
  self._select_handlers: Dict[str, SelectHandler] = {}
61
62
  self._application_id: str = ""
62
63
  self._running = False
64
+ self.db = Database(self._client)
63
65
 
64
66
  def command(
65
67
  self,
loopbot/context/base.py CHANGED
@@ -5,6 +5,7 @@ Base Context for all interaction types
5
5
  from typing import Any, Dict, List, Optional, Union
6
6
 
7
7
  from ..types import Interaction, InteractionResponseType, DiscordUser, DiscordMember
8
+ from ..database import Database
8
9
  from ..builders.embed import EmbedBuilder
9
10
  from ..builders.action_row import ActionRowBuilder
10
11
  from ..builders.modal import ModalBuilder
@@ -24,6 +25,7 @@ class BaseContext:
24
25
  self._application_id = application_id
25
26
  self._response: Optional[Dict[str, Any]] = None
26
27
  self._deferred = False
28
+ self.db = Database(client)
27
29
 
28
30
  @property
29
31
  def interaction_id(self) -> str:
loopbot/database.py ADDED
@@ -0,0 +1,70 @@
1
+ """
2
+ Database class for persistent storage
3
+ Makes HTTP calls to the Loop API to store/retrieve data
4
+ """
5
+
6
+ from typing import Any, Dict, Optional
7
+ import aiohttp
8
+
9
+
10
+ class Database:
11
+ """Database for persistent storage via Loop API"""
12
+
13
+ def __init__(self, client: Any):
14
+ self._client = client
15
+
16
+ async def get(self, key: str) -> Optional[Any]:
17
+ """Get a value by key"""
18
+ try:
19
+ response = await self._client.request(
20
+ "GET",
21
+ f"/sdk/db/{key}",
22
+ )
23
+ return response.get("value")
24
+ except Exception:
25
+ return None
26
+
27
+ async def set(self, key: str, value: Any) -> bool:
28
+ """Set a value for a key"""
29
+ try:
30
+ response = await self._client.request(
31
+ "POST",
32
+ f"/sdk/db/{key}",
33
+ {"value": value},
34
+ )
35
+ return response.get("success", False)
36
+ except Exception:
37
+ return False
38
+
39
+ async def delete(self, key: str) -> bool:
40
+ """Delete a key"""
41
+ try:
42
+ response = await self._client.request(
43
+ "DELETE",
44
+ f"/sdk/db/{key}",
45
+ )
46
+ return response.get("success", False)
47
+ except Exception:
48
+ return False
49
+
50
+ async def get_all(self) -> Dict[str, Any]:
51
+ """Get all data"""
52
+ try:
53
+ response = await self._client.request(
54
+ "GET",
55
+ "/sdk/db",
56
+ )
57
+ return response.get("data", {})
58
+ except Exception:
59
+ return {}
60
+
61
+ async def clear(self) -> bool:
62
+ """Clear all data"""
63
+ try:
64
+ response = await self._client.request(
65
+ "DELETE",
66
+ "/sdk/db",
67
+ )
68
+ return response.get("success", False)
69
+ except Exception:
70
+ return False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: loopbot-discord-sdk
3
- Version: 1.0.5
3
+ Version: 1.0.6
4
4
  Summary: Official Loop Discord SDK for Python - Build Discord bots without websockets
5
5
  Author-email: Loop <contact@loopbot.app>
6
6
  License: MIT
@@ -1,6 +1,7 @@
1
- loopbot/__init__.py,sha256=oIkHZq8f8ygeHGLMiYgTd8cB_PmrNFDcNZnkccES7ws,1197
2
- loopbot/bot.py,sha256=ne_dgvYqIq7jW1cNS8-jjbX7IKXIDtTHzxvReh7JZDM,20625
1
+ loopbot/__init__.py,sha256=GiSEnH3mfcy7-ez01TXQnpiOOc_vPIbdN3mMqVo37Og,1246
2
+ loopbot/bot.py,sha256=oVknClm_tOmocrsWBGP8P7VTBIeWHx8dsB9iJPI2dNY,20699
3
3
  loopbot/client.py,sha256=s7UG3Fd_GUA6qpil5fbH3d3VFXJMDPjUX513_1Og4Fs,30124
4
+ loopbot/database.py,sha256=LxNMDQO0wi4YxJbLEdOpHSwOs7tibvSAA-BFcN15SFA,1948
4
5
  loopbot/types.py,sha256=MZcQgVvVDSs60UqAF5lWkHNM3yo9KLKDxZaU6tKndZQ,1645
5
6
  loopbot/builders/__init__.py,sha256=STrS9XOMPsVDzx9VAvbOZW2f8fp6mITbZWzdkgmqNe4,790
6
7
  loopbot/builders/action_row.py,sha256=ouQKGpcb9KIWwUWJzUT6kH7Ov60UCZi5FjWlXC6sRVw,1225
@@ -15,12 +16,12 @@ loopbot/builders/select_menu.py,sha256=Ay5-7mCnyt4Q9Diyd50T79nZrcWoWD6BITgaWCldt
15
16
  loopbot/builders/separator.py,sha256=RWy04jS6k67wWULoSI_wlTNbV0D8L0P4XFSQgjwWe_U,882
16
17
  loopbot/builders/text_display.py,sha256=vtU9NJ_QL0Kilp-nkub6mwREXcTaEzl-OFiWWlfwmEE,653
17
18
  loopbot/context/__init__.py,sha256=Z3-t2n-LcL4FT-rrmPPB131JBL3t6kbC2RSXopvOqKU,352
18
- loopbot/context/base.py,sha256=7GUiEBuo12KoJ1e2K0xR_u8idZr-mnO5OSxXTmAWgzI,8104
19
+ loopbot/context/base.py,sha256=XDH8PbtymzjEEO66_4LvdIX-ixATu3QoDOOYwM7m6SI,8173
19
20
  loopbot/context/button.py,sha256=5-XO6mYNMx2FPHhv8ijiUrsALOkxzSal-NKvVvXvMnM,756
20
21
  loopbot/context/command.py,sha256=i7Z8o3F5mLvQDDSVdio8LMB5-zPzMKtSiPsK1WgNg4c,3076
21
22
  loopbot/context/modal.py,sha256=QTgKDRZP7g43S3ScR5dMGKzZolUDWMtVmYqEip4GJXI,1476
22
23
  loopbot/context/select.py,sha256=8ozLkBNdlZBdQdeCbJ2545j3YkwsCBUnFpHWQPW5VIw,954
23
- loopbot_discord_sdk-1.0.5.dist-info/METADATA,sha256=6pv-i-_TC8C0h0rCqNOxdtPOGOf_MVWSyCRsAcPD2rk,12462
24
- loopbot_discord_sdk-1.0.5.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
25
- loopbot_discord_sdk-1.0.5.dist-info/top_level.txt,sha256=4sZzEMpMwz6lUz7RJzVFFh7LY-vr5W1-RAfn_bF6tks,8
26
- loopbot_discord_sdk-1.0.5.dist-info/RECORD,,
24
+ loopbot_discord_sdk-1.0.6.dist-info/METADATA,sha256=7Dp39kOpthgVKx30H0OeoznNrJsIHtvh-moxhXDXUYM,12462
25
+ loopbot_discord_sdk-1.0.6.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
26
+ loopbot_discord_sdk-1.0.6.dist-info/top_level.txt,sha256=4sZzEMpMwz6lUz7RJzVFFh7LY-vr5W1-RAfn_bF6tks,8
27
+ loopbot_discord_sdk-1.0.6.dist-info/RECORD,,