scurrypy 0.3.0__py3-none-any.whl → 0.3.2__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.

Potentially problematic release.


This version of scurrypy might be problematic. Click here for more details.

discord/client.py CHANGED
@@ -100,13 +100,13 @@ class Client(ClientLike):
100
100
  def decorator(func):
101
101
  # hash out command type
102
102
  if isinstance(command, MessageCommand):
103
- self.command_dispatcher.message_command(func)
103
+ self.command_dispatcher.message_command(command.name, func)
104
104
  elif isinstance(command, UserCommand):
105
- self.command_dispatcher.user_command(func)
105
+ self.command_dispatcher.user_command(command.name, func)
106
106
  elif isinstance(command, SlashCommand):
107
- self.command_dispatcher.command(func)
107
+ self.command_dispatcher.command(command.name, func)
108
108
  else:
109
- raise ValueError(f'Command {func.__name__} expected to be of type SlashCommand, UserCommand, MessageCommand; \
109
+ raise ValueError(f'Command {command.name} expected to be of type SlashCommand, UserCommand, MessageCommand; \
110
110
  got {type(command).__name__}.')
111
111
 
112
112
  # then hash out if this command should be guild or global level
@@ -78,39 +78,42 @@ class CommandDispatcher:
78
78
 
79
79
  await self._http.request('PUT', f"applications/{self.application_id}/commands", global_commands)
80
80
 
81
- def command(self, handler):
81
+ def command(self, name: str, handler):
82
82
  """Decorator to register slash commands.
83
83
 
84
84
  Args:
85
+ name (str): name of the command to register
85
86
  handler (callable): callback handle for command response
86
87
  """
87
- self._handlers[handler.__name__] = handler
88
-
89
- def component(self, func, custom_id: str):
90
- """Decorator to register component interactions.
91
-
92
- Args:
93
- custom_id (str): Identifier of the component
94
- !!! warning "Important"
95
- Must match the `custom_id` set where the component was created.
96
- """
97
- self._component_handlers[custom_id] = func
88
+ self._handlers[name] = handler
98
89
 
99
- def user_command(self, handler):
90
+ def user_command(self, name: str, handler):
100
91
  """Decorator to register user commands.
101
92
 
102
93
  Args:
94
+ name (str): name of the command to register
103
95
  handler (callable): callback handle for user command response
104
96
  """
105
- self._user_handlers[handler.__name__] = handler
97
+ self._user_handlers[name] = handler
106
98
 
107
- def message_command(self, handler):
99
+ def message_command(self, name: str, handler):
108
100
  """Decorator to register message commands.
109
101
 
110
102
  Args:
103
+ name (str): name of the command to register
111
104
  handler (callable): callback handle for message command response
112
105
  """
113
- self._message_handlers[handler.__name__] = handler
106
+ self._message_handlers[name] = handler
107
+
108
+ def component(self, func, custom_id: str):
109
+ """Decorator to register component interactions.
110
+
111
+ Args:
112
+ custom_id (str): Identifier of the component
113
+ !!! warning "Important"
114
+ Must match the `custom_id` set where the component was created.
115
+ """
116
+ self._component_handlers[custom_id] = func
114
117
 
115
118
  async def dispatch(self, data: dict):
116
119
  """Dispatch a response to an `INTERACTION_CREATE` event
@@ -0,0 +1,26 @@
1
+ from dataclasses import dataclass
2
+ from ..model import DataModel
3
+
4
+ @dataclass
5
+ class InteractionCallbackDataModel(DataModel):
6
+ id: int
7
+ """ID of the interaction."""
8
+
9
+ type: int
10
+ """Type of interaction."""
11
+
12
+ activity_instance_id: str
13
+ """Instance ID of activity if an activity was launched or joined."""
14
+
15
+ response_message_id: int
16
+ """ID of the message created by the interaction."""
17
+
18
+ response_message_loading: bool
19
+ """If the interaction is in a loading state."""
20
+
21
+ response_message_ephemeral: bool
22
+ """If the interaction is ephemeral."""
23
+
24
+ @dataclass
25
+ class InteractionCallbackModel(DataModel):
26
+ interaction: InteractionCallbackDataModel
@@ -1,5 +1,5 @@
1
1
  from dataclasses import dataclass
2
- from typing import TypedDict, Unpack, Optional
2
+ from typing import TypedDict, Unpack, Optional, Literal
3
3
 
4
4
  from ..http import HTTPClient
5
5
  from ..model import DataModel
@@ -32,6 +32,15 @@ class PinsFetchParams(TypedDict, total=False):
32
32
  limit: int
33
33
  """Max number of pinned messages to return. Range 1 - 50. Default 50."""
34
34
 
35
+ class ThreadFromMessageParams(TypedDict, total=False):
36
+ """Params when attaching a thread to a message."""
37
+
38
+ rate_limit_per_user: Literal[60, 1440, 4320, 10080]
39
+ """time (minutes) of inactivity before thread is archived."""
40
+
41
+ rate_limit_per_user: int
42
+ """time (seconds) user waits before sending another message."""
43
+
35
44
  @dataclass
36
45
  class PinnedMessage(DataModel):
37
46
  """Pinned message data."""
@@ -160,6 +169,26 @@ class Channel(DataModel):
160
169
 
161
170
  return self
162
171
 
172
+ async def create_thread_from_message(self, message_id: int, name: str, **kwargs: Unpack[ThreadFromMessageParams]):
173
+ """Create a thread from this message
174
+
175
+ Args:
176
+ message_id: ID of message to attach thread
177
+ name (str): thread name
178
+
179
+ Returns:
180
+ (Channel): The updated channel object
181
+ """
182
+
183
+ content = {
184
+ 'name': name,
185
+ **kwargs
186
+ }
187
+
188
+ data = await self._http.request('POST', f"channels/{self.id}/messages/{message_id}/threads", data=content)
189
+
190
+ return Channel.from_dict(data, self._http)
191
+
163
192
  async def fetch_pins(self, **kwargs: Unpack[PinsFetchParams]):
164
193
  """Get this channel's pinned messages.
165
194
 
@@ -11,6 +11,7 @@ from ..parts.component_types import *
11
11
 
12
12
  from ..models.guild import GuildModel
13
13
  from ..models.member import MemberModel
14
+ from ..models.interaction import InteractionCallbackModel
14
15
 
15
16
  from .channel import Channel
16
17
 
@@ -98,11 +99,12 @@ class Interaction(DataModel):
98
99
  channel: Optional[Channel] = None
99
100
  """Partial channel object the interaction was invoked."""
100
101
 
101
- async def respond(self, message: str | MessageBuilder, **flags: Unpack[MessageFlagParams]):
102
+ async def respond(self, message: str | MessageBuilder, with_response: bool = False, **flags: Unpack[MessageFlagParams]):
102
103
  """Create a message in response to an interaction.
103
104
 
104
105
  Args:
105
106
  message (str | MessageBuilder): content as a string or from MessageBuilder
107
+ with_response (bool, optional): if the interaction data should be returned. Defaults to False.
106
108
  """
107
109
  if isinstance(message, str):
108
110
  message = MessageBuilder(content=message).set_flags(**flags)
@@ -112,12 +114,18 @@ class Interaction(DataModel):
112
114
  'data': message._to_dict()
113
115
  }
114
116
 
115
- await self._http.request(
117
+ params = {'with_response': with_response}
118
+
119
+ data = await self._http.request(
116
120
  'POST',
117
121
  f'/interactions/{self.id}/{self.token}/callback',
118
122
  content,
119
- files=[fp.path for fp in message.attachments])
123
+ files=[fp.path for fp in message.attachments],
124
+ params=params)
120
125
 
126
+ if with_response:
127
+ return InteractionCallbackModel.from_dict(data, self._http)
128
+
121
129
  async def update(self, message: str | MessageBuilder, **flags: Unpack[MessageFlagParams]):
122
130
  """Update a message in response to an interaction.
123
131
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scurrypy
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: Discord API Wrapper in Python
5
5
  Author: Furmissile
6
6
  Requires-Python: >=3.10
@@ -46,14 +46,14 @@ load_dotenv(dotenv_path='./path/to/env') # omit argument if your env file is on
46
46
 
47
47
  bot = discord.Client(
48
48
  token=os.getenv("DISCORD_TOKEN"),
49
- application_id=1234567890 # replace with your bot's user ID
49
+ application_id=APPLICATION_ID # replace with your bot's user ID
50
50
  )
51
51
 
52
52
  @bot.command(
53
53
  command=discord.SlashCommand(name='example', description='Demonstrate the minimal slash command!'),
54
54
  guild_id=GUILD_ID # must be a guild ID your bot is in!
55
55
  )
56
- async def example(event: discord.InteractionEvent):
56
+ async def example(bot: discord.Client, event: discord.InteractionEvent):
57
57
  await event.interaction.respond(f'Hello, {event.interaction.member.user.username}!')
58
58
 
59
59
  bot.run()
@@ -69,13 +69,13 @@ load_dotenv(dotenv_path='./path/to/env') # omit argument if your env file is on
69
69
 
70
70
  bot = discord.Client(
71
71
  token=os.getenv("DISCORD_TOKEN"),
72
- application_id=1234567890, # replace with your bot's user ID
72
+ application_id=APPLICATION_ID, # replace with your bot's user ID
73
73
  intents=discord.set_intents(message_content=True),
74
74
  prefix='!' # your custom prefix
75
75
  )
76
76
 
77
77
  @bot.prefix_command
78
- async def ping(event: discord.MessageCreateEvent): # the function name is the name of the command!
78
+ async def ping(bot: discord.Client, event: discord.MessageCreateEvent): # the function name is the name of the command!
79
79
  await event.message.send(f"Pong!")
80
80
 
81
81
  bot.run()
@@ -1,5 +1,5 @@
1
1
  discord/__init__.py,sha256=DPE5laK7mMQPeF2ky8D8QpokCDqsGlq6slHHhbNXmso,217
2
- discord/client.py,sha256=XJAxnfmwm16vfgKUZ15aFMXYHvK2WGVFQoJJ7vH2zMs,13353
2
+ discord/client.py,sha256=6fQsg7p4-LlWICdoten4I3X0PrkxtoPkv5X9rNLRmJc,13394
3
3
  discord/client_like.py,sha256=JyJq0XBq0vKuPBJ_ZnYf5yAAuX1zz_2B1TZBQE-BYbQ,473
4
4
  discord/config.py,sha256=OH1A2mNKhDlGvQYASEsVUx2pNxP1YQ2a7a7z-IM5xFg,200
5
5
  discord/error.py,sha256=AlislRTna554cM6KC0KrwKugzYDYtx_9C8_3QFe4XDc,2070
@@ -9,7 +9,7 @@ discord/intents.py,sha256=Lf2fogFFDqilZeKJv7tcUgKmMW3D7ykK4bBNi-zDzYA,2866
9
9
  discord/logger.py,sha256=GBcvldIrSBnwNSgus-oa1NsYV8hU7f8_4J4VX_GmkxA,4700
10
10
  discord/model.py,sha256=CmuxyoWLWokE_UvCQ9M7U9Cr7JH9R7ULMv9KMwzXjDQ,3105
11
11
  discord/dispatch/__init__.py,sha256=m7ixrbNhOV9QRORXPw6LSwxofQMAvLmPFBweBZu9ACc,20
12
- discord/dispatch/command_dispatcher.py,sha256=_91l4oJQ8LhMnxdVPzkdmDSv6AWznekNODtzudCQvrk,5740
12
+ discord/dispatch/command_dispatcher.py,sha256=pyJOQaZLZYrHUEs6HEWp8XMKTMZX4SBrwTizGKIeUG8,5904
13
13
  discord/dispatch/event_dispatcher.py,sha256=aPyfstFdIx510P_gKAExeZOICZooRgUdL19Adb19SPY,3085
14
14
  discord/dispatch/prefix_dispatcher.py,sha256=4mkn3cuXTjdEChbewkbZQqd_sMKm4jePSFKKOPbt12g,2065
15
15
  discord/events/__init__.py,sha256=BcmwAj84-nzMZEkip-V903jD0ZCKqhySzlAx5wDwJoo,630
@@ -25,6 +25,7 @@ discord/models/application.py,sha256=2sXtRysUc2TJ40FjdcrWgosmwMrp_h3ybddubQMixKM
25
25
  discord/models/emoji.py,sha256=6iz1DhWj_eTUj2KHmwMewjB3AdEBm68EmIZp2WFFCQg,932
26
26
  discord/models/guild.py,sha256=aXUByOUUIGt9d2qIGC6_X_vh0Nyib8Iqj5ZElBeNV_I,819
27
27
  discord/models/integration.py,sha256=V29RO2925mQbVXPAMt665cML3m8mJACYmdJLWwbbUyE,612
28
+ discord/models/interaction.py,sha256=VPbf49C1RmQpDSODk3e1voW8EnbVsH_w1qpmiq4hVRM,700
28
29
  discord/models/member.py,sha256=pkI-NVRMb3hUBkxI26FSYZxzx2mRNGXOeWWCw3BGGsY,705
29
30
  discord/models/role.py,sha256=erlERmK-IZz4YzSNY-XLNvCc-Z5PoVlClxPOX67dQJg,1169
30
31
  discord/models/user.py,sha256=lgG6GoU_7L68oHt6PGTzTkU1vrbsclRQzGjKzsLBeKA,298
@@ -42,13 +43,13 @@ discord/parts/role.py,sha256=cK96UdgT-kU0gY5C_1LZXPrYg144x2RDmGjT28so57A,920
42
43
  discord/resources/__init__.py,sha256=ubRaTXEy4dNJhqO8JXf-xBoJjPt9zKs1GZHY8Um2_mk,282
43
44
  discord/resources/application.py,sha256=vYMTli_FSbC7venMepsJ9bkzdEQVkKYpnxCJ9K2XDho,2765
44
45
  discord/resources/bot_emojis.py,sha256=RvGCSOBkjS39P2aab0FzYUOTzBOiHX99RLrJZzAYNiU,1701
45
- discord/resources/channel.py,sha256=-boYdVYW0v0oaV5X1SIhfdbKn0RDFF_HJo83dreVTm0,5943
46
+ discord/resources/channel.py,sha256=fe2JUp943VnXa-BKyRMtNP-JyNd_Mp516sWBKHKn_GI,6915
46
47
  discord/resources/guild.py,sha256=Unld1lWY3XynmRHU2FCi3-LA9VNp2thMI2BlILUTTxk,8183
47
- discord/resources/interaction.py,sha256=8z91X49KSknaT1syBfLr0SHRgAxaQ-8lbhkb3LU21fg,4911
48
+ discord/resources/interaction.py,sha256=JdZiGlG12-TGazjq98kak_3ydHFm9RZCUJPBFcCbMHk,5305
48
49
  discord/resources/message.py,sha256=RtvcCRx0lwW-mHPl3aNYoEvGffrvtpLsQ2fVWckywVI,7527
49
50
  discord/resources/user.py,sha256=vk89TnCVi-6ZgbDs_TZTCXrx_NfFS5Q9Wi_itYoaoyg,3085
50
- scurrypy-0.3.0.dist-info/licenses/LICENSE,sha256=NtspfRMAlryd1Eev4BYi9EFbKhvdmlCJJ2-ADUoEBoI,426
51
- scurrypy-0.3.0.dist-info/METADATA,sha256=v3X0WfX-Z1KetahNjl7PbPL_xvsqFKIdxcRKstJXrDI,2950
52
- scurrypy-0.3.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
53
- scurrypy-0.3.0.dist-info/top_level.txt,sha256=fJkrNbR-_8ubMBUcDEJBcfkpECrvSEmMrNKgvLlQFoM,8
54
- scurrypy-0.3.0.dist-info/RECORD,,
51
+ scurrypy-0.3.2.dist-info/licenses/LICENSE,sha256=NtspfRMAlryd1Eev4BYi9EFbKhvdmlCJJ2-ADUoEBoI,426
52
+ scurrypy-0.3.2.dist-info/METADATA,sha256=OSm3SIus5sVJNIpZ93FZLPeSClrIsPj4pPjH1MJKdUY,3000
53
+ scurrypy-0.3.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
54
+ scurrypy-0.3.2.dist-info/top_level.txt,sha256=fJkrNbR-_8ubMBUcDEJBcfkpECrvSEmMrNKgvLlQFoM,8
55
+ scurrypy-0.3.2.dist-info/RECORD,,