Skip to content

Commit da32b6a

Browse files
committed
chore: change example names
1 parent 6400ec3 commit da32b6a

File tree

8 files changed

+110
-74
lines changed

8 files changed

+110
-74
lines changed

discord_components/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Discord Components Constants"""
22

3-
__version__ = "2.0.4"
3+
__version__ = "2.0.5"

discord_components/dpy_overrides.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ async def edit(
6161
data["content"] = content
6262

6363
if embed is not None and embeds is not None:
64-
raise InvalidArgument("cannot pass both embed and embeds parameter to edit()")
64+
raise InvalidArgument(
65+
"cannot pass both embed and embeds parameter to edit()"
66+
)
6567

6668
if embed is not None:
6769
data["embeds"] = [embed.to_dict()]
@@ -75,11 +77,16 @@ async def edit(
7577
data["flags"] = flags.value
7678

7779
if allowed_mentions is None:
78-
if state.allowed_mentions is not None and self.author.id == self._state.self_id:
80+
if (
81+
state.allowed_mentions is not None
82+
and self.author.id == self._state.self_id
83+
):
7984
data["allowed_mentions"] = state.allowed_mentions.to_dict()
8085
else:
8186
if state.allowed_mentions is not None:
82-
data["allowed_mentions"] = state.allowed_mentions.merge(allowed_mentions).to_dict()
87+
data["allowed_mentions"] = state.allowed_mentions.merge(
88+
allowed_mentions
89+
).to_dict()
8390
else:
8491
data["allowed_mentions"] = allowed_mentions.to_dict()
8592

@@ -202,7 +209,8 @@ def send_message(
202209
payload["components"] = components
203210

204211
return self.request(
205-
Route("POST", "/channels/{channel_id}/messages", channel_id=channel_id), json=payload
212+
Route("POST", "/channels/{channel_id}/messages", channel_id=channel_id),
213+
json=payload,
206214
)
207215

208216

@@ -239,7 +247,9 @@ async def send(
239247

240248
elif embeds is not None:
241249
if len(embeds) > 10:
242-
raise InvalidArgument("embeds parameter must be a list of up to 10 elements")
250+
raise InvalidArgument(
251+
"embeds parameter must be a list of up to 10 elements"
252+
)
243253
embeds = [embed.to_dict() for embed in embeds]
244254

245255
if stickers is not None:
@@ -344,7 +354,7 @@ async def send_override(context_or_channel, *args, **kwargs):
344354
return await send(channel, *args, **kwargs)
345355

346356

347-
async def fetch_message(context_or_channel, id:int):
357+
async def fetch_message(context_or_channel, id: int):
348358
if isinstance(context_or_channel, Context):
349359
channel = context_or_channel.channel
350360
else:
@@ -356,4 +366,4 @@ async def fetch_message(context_or_channel, id:int):
356366

357367

358368
Messageable.send = send_override
359-
Messageable.fetch_message = fetch_message
369+
Messageable.fetch_message = fetch_message

discord_components/http.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@ class HTTPClient:
1313
def __init__(self, bot: Client):
1414
self.bot = bot
1515

16-
def edit_response(self, interaction_token: str, data: dict, files: List[File] = None):
16+
def edit_response(
17+
self, interaction_token: str, data: dict, files: List[File] = None
18+
):
1719
route = Route(
1820
"PATCH",
1921
f"/webhooks/{self.bot.user.id}/{interaction_token}/messages/@original",
2022
)
2123

2224
if files is not None:
23-
return self.bot.http.request(route, data=_form_files(data, files), files=files)
25+
return self.bot.http.request(
26+
route, data=_form_files(data, files), files=files
27+
)
2428
else:
2529
return self.bot.http.request(
2630
route,
@@ -40,7 +44,9 @@ def initial_response(
4044
)
4145

4246
if files is not None:
43-
return self.bot.http.request(route, data=_form_files(data, files), files=files)
47+
return self.bot.http.request(
48+
route, data=_form_files(data, files), files=files
49+
)
4450
else:
4551
return self.bot.http.request(
4652
route,

discord_components/interaction.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ def __init__(
5858
state=state, guild=self.guild, data=raw_data["member"]
5959
)
6060
elif raw_data.get("member"):
61-
self.user: Union[User, Member] = User(state=state, data=raw_data["member"]["user"])
61+
self.user: Union[User, Member] = User(
62+
state=state, data=raw_data["member"]["user"]
63+
)
6264
else:
6365
self.user: Union[User, Member] = User(state=state, data=raw_data["user"])
6466
self.author: Union[User, Member] = self.user
@@ -128,7 +130,9 @@ async def respond(
128130

129131
if embeds is not None:
130132
if len(embeds) > 10:
131-
raise InvalidArgument("embeds parameter must be a list of up to 10 elements")
133+
raise InvalidArgument(
134+
"embeds parameter must be a list of up to 10 elements"
135+
)
132136
data["embeds"] = [embed.to_dict() for embed in embeds]
133137

134138
if suppress is not None:
@@ -140,11 +144,15 @@ async def respond(
140144

141145
if allowed_mentions is not None:
142146
if state.allowed_mentions is not None:
143-
data["allowed_mentions"] = state.allowed_mentions.merge(allowed_mentions).to_dict()
147+
data["allowed_mentions"] = state.allowed_mentions.merge(
148+
allowed_mentions
149+
).to_dict()
144150
else:
145151
data["allowed_mentions"] = allowed_mentions.to_dict()
146152
else:
147-
data["allowed_mentions"] = state.allowed_mentions and state.allowed_mentions.to_dict()
153+
data["allowed_mentions"] = (
154+
state.allowed_mentions and state.allowed_mentions.to_dict()
155+
)
148156

149157
if components is not None:
150158
data["components"] = _get_components_json(components)
@@ -156,7 +164,9 @@ async def respond(
156164
raise InvalidArgument("cannot pass both file and files parameter to send()")
157165
elif files is not None:
158166
if len(files) > 10:
159-
raise InvalidArgument("files parameter must be a list of up to 10 elements")
167+
raise InvalidArgument(
168+
"files parameter must be a list of up to 10 elements"
169+
)
160170
if file is not None:
161171
files = [file]
162172

File renamed without changes.
Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,50 @@
1-
from discord.ext.commands import command, Cog
2-
from discord_components import (
3-
Button,
4-
ButtonStyle,
5-
Select,
6-
SelectOption,
7-
)
8-
9-
10-
class ExampleCog(Cog):
11-
def __init__(self, bot):
12-
self.bot = bot
13-
14-
@command()
15-
async def button(self, ctx):
16-
async def callback(interaction):
17-
await interaction.send(content="Yay")
18-
19-
await ctx.send(
20-
"Button callbacks!",
21-
components=[
22-
self.bot.components_manager.add_callback(
23-
Button(style=ButtonStyle.blue, label="Click this"), callback
24-
),
25-
],
26-
)
27-
28-
@command()
29-
async def select(self, ctx):
30-
async def callback(interaction):
31-
await interaction.send(content="Yay")
32-
33-
await ctx.send(
34-
"Select callbacks!",
35-
components=[
36-
self.bot.components_manager.add_callback(
37-
Select(
38-
options=[
39-
SelectOption(label="a", value="a"),
40-
SelectOption(label="b", value="b"),
41-
],
42-
),
43-
callback,
44-
)
45-
],
46-
)
47-
48-
49-
50-
def setup(bot):
51-
bot.add_cog(ExampleCog(bot))
1+
from discord.ext.commands import command, Cog
2+
from discord_components import (
3+
Button,
4+
ButtonStyle,
5+
Select,
6+
SelectOption,
7+
)
8+
9+
10+
class ExampleCog(Cog):
11+
def __init__(self, bot):
12+
self.bot = bot
13+
14+
@command()
15+
async def button(self, ctx):
16+
async def callback(interaction):
17+
await interaction.send(content="Yay")
18+
19+
await ctx.send(
20+
"Button callbacks!",
21+
components=[
22+
self.bot.components_manager.add_callback(
23+
Button(style=ButtonStyle.blue, label="Click this"), callback
24+
),
25+
],
26+
)
27+
28+
@command()
29+
async def select(self, ctx):
30+
async def callback(interaction):
31+
await interaction.send(content="Yay")
32+
33+
await ctx.send(
34+
"Select callbacks!",
35+
components=[
36+
self.bot.components_manager.add_callback(
37+
Select(
38+
options=[
39+
SelectOption(label="a", value="a"),
40+
SelectOption(label="b", value="b"),
41+
],
42+
),
43+
callback,
44+
)
45+
],
46+
)
47+
48+
49+
def setup(bot):
50+
bot.add_cog(ExampleCog(bot))

examples/simple_event.py renamed to examples/event.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async def select(ctx):
3838
],
3939
custom_id="select1",
4040
)
41-
]
41+
],
4242
)
4343

4444

examples/paginator.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ def get_components(self):
3232
Select(
3333
custom_id="paginator_select",
3434
options=[
35-
SelectOption(label=f"Page {i}", value=str(i), default=i == self.index)
35+
SelectOption(
36+
label=f"Page {i}", value=str(i), default=i == self.index
37+
)
3638
for i in range(len(self.contents))
3739
],
3840
),
@@ -43,11 +45,16 @@ def get_components(self):
4345
return [
4446
[
4547
self.client.add_callback(
46-
Button(style=ButtonStyle.blue, emoji="◀️"), self.button_left_callback
48+
Button(style=ButtonStyle.blue, emoji="◀️"),
49+
self.button_left_callback,
50+
),
51+
Button(
52+
label=f"Page {self.index + 1}/{len(self.contents)}",
53+
disabled=True,
4754
),
48-
Button(label=f"Page {self.index + 1}/{len(self.contents)}", disabled=True),
4955
self.client.add_callback(
50-
Button(style=ButtonStyle.blue, emoji="▶️"), self.button_right_callback
56+
Button(style=ButtonStyle.blue, emoji="▶️"),
57+
self.button_right_callback,
5158
),
5259
]
5360
]
@@ -59,7 +66,9 @@ async def start(self):
5966

6067
async def select_callback(self, inter: Interaction):
6168
self.index = int(inter.values[0])
62-
await inter.edit_origin(content=self.contents[self.index], components=self.get_components())
69+
await inter.edit_origin(
70+
content=self.contents[self.index], components=self.get_components()
71+
)
6372

6473
async def button_left_callback(self, inter: Interaction):
6574
if self.index == 0:
@@ -78,4 +87,6 @@ async def button_right_callback(self, inter: Interaction):
7887
await self.button_callback(inter)
7988

8089
async def button_callback(self, inter: Interaction):
81-
await inter.edit_origin(content=self.contents[self.index], components=self.get_components())
90+
await inter.edit_origin(
91+
content=self.contents[self.index], components=self.get_components()
92+
)

0 commit comments

Comments
 (0)