loopbot-discord-sdk 1.0.6__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.
Files changed (32) hide show
  1. loopbot_discord_sdk-1.0.6/PKG-INFO +433 -0
  2. loopbot_discord_sdk-1.0.6/README.md +400 -0
  3. loopbot_discord_sdk-1.0.6/loopbot/__init__.py +62 -0
  4. loopbot_discord_sdk-1.0.6/loopbot/bot.py +586 -0
  5. loopbot_discord_sdk-1.0.6/loopbot/builders/__init__.py +30 -0
  6. loopbot_discord_sdk-1.0.6/loopbot/builders/action_row.py +40 -0
  7. loopbot_discord_sdk-1.0.6/loopbot/builders/button.py +58 -0
  8. loopbot_discord_sdk-1.0.6/loopbot/builders/container.py +61 -0
  9. loopbot_discord_sdk-1.0.6/loopbot/builders/embed.py +95 -0
  10. loopbot_discord_sdk-1.0.6/loopbot/builders/file.py +33 -0
  11. loopbot_discord_sdk-1.0.6/loopbot/builders/media_gallery.py +36 -0
  12. loopbot_discord_sdk-1.0.6/loopbot/builders/modal.py +67 -0
  13. loopbot_discord_sdk-1.0.6/loopbot/builders/section.py +52 -0
  14. loopbot_discord_sdk-1.0.6/loopbot/builders/select_menu.py +63 -0
  15. loopbot_discord_sdk-1.0.6/loopbot/builders/separator.py +31 -0
  16. loopbot_discord_sdk-1.0.6/loopbot/builders/text_display.py +24 -0
  17. loopbot_discord_sdk-1.0.6/loopbot/client.py +885 -0
  18. loopbot_discord_sdk-1.0.6/loopbot/context/__init__.py +17 -0
  19. loopbot_discord_sdk-1.0.6/loopbot/context/base.py +265 -0
  20. loopbot_discord_sdk-1.0.6/loopbot/context/button.py +28 -0
  21. loopbot_discord_sdk-1.0.6/loopbot/context/command.py +93 -0
  22. loopbot_discord_sdk-1.0.6/loopbot/context/modal.py +46 -0
  23. loopbot_discord_sdk-1.0.6/loopbot/context/select.py +34 -0
  24. loopbot_discord_sdk-1.0.6/loopbot/database.py +70 -0
  25. loopbot_discord_sdk-1.0.6/loopbot/types.py +76 -0
  26. loopbot_discord_sdk-1.0.6/loopbot_discord_sdk.egg-info/PKG-INFO +433 -0
  27. loopbot_discord_sdk-1.0.6/loopbot_discord_sdk.egg-info/SOURCES.txt +30 -0
  28. loopbot_discord_sdk-1.0.6/loopbot_discord_sdk.egg-info/dependency_links.txt +1 -0
  29. loopbot_discord_sdk-1.0.6/loopbot_discord_sdk.egg-info/requires.txt +7 -0
  30. loopbot_discord_sdk-1.0.6/loopbot_discord_sdk.egg-info/top_level.txt +1 -0
  31. loopbot_discord_sdk-1.0.6/pyproject.toml +70 -0
  32. loopbot_discord_sdk-1.0.6/setup.cfg +4 -0
@@ -0,0 +1,433 @@
1
+ Metadata-Version: 2.4
2
+ Name: loopbot-discord-sdk
3
+ Version: 1.0.6
4
+ Summary: Official Loop Discord SDK for Python - Build Discord bots without websockets
5
+ Author-email: Loop <contact@loopbot.app>
6
+ License: MIT
7
+ Project-URL: Homepage, https://loopbot.app
8
+ Project-URL: Documentation, https://loopbot.app/docs
9
+ Project-URL: Repository, https://github.com/loopbot/python-sdk
10
+ Project-URL: Issues, https://github.com/loopbot/python-sdk/issues
11
+ Keywords: discord,bot,sdk,loop,loopbot,interactions,slash-commands,buttons,modals
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Topic :: Communications :: Chat
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.8
26
+ Description-Content-Type: text/markdown
27
+ Requires-Dist: aiohttp>=3.8.0
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
30
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
31
+ Requires-Dist: black>=23.0.0; extra == "dev"
32
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
33
+
34
+ # LoopBot SDK Python
35
+
36
+ Biblioteca oficial para criar bots no LoopBot usando Python.
37
+
38
+ ## Instalação
39
+
40
+ ```bash
41
+ pip install loopbot-sdk
42
+ ```
43
+
44
+ ## Inicialização
45
+
46
+ ```python
47
+ from loopbot import Bot
48
+
49
+ bot = Bot(
50
+ token="seu_token_aqui"
51
+ )
52
+
53
+ # ... seus comandos aqui ...
54
+
55
+ bot.start()
56
+ ```
57
+
58
+ ## Guia Completo
59
+
60
+ ### Trabalhando com Embeds
61
+
62
+ Embeds são mensagens ricas que permitem exibir informações de forma estruturada.
63
+
64
+ ```python
65
+ from loopbot.builders import EmbedBuilder
66
+
67
+ @bot.command("embed_demo", "Demonstração de Embed")
68
+ def embed_demo(ctx):
69
+ # Criando um embed
70
+ embed = (
71
+ EmbedBuilder()
72
+ .set_title("Título do Embed")
73
+ .set_description("Descrição detalhada aqui...")
74
+ .set_color(0x00FF00) # Cor em hexadecimal (ex: Verde)
75
+ .set_url("https://loopbot.app")
76
+ .set_footer("Rodapé", icon_url="https://exemplo.com/icone.png")
77
+ .set_author("Nome Autor", url="https://perfil.com", icon_url="https://avatar.com/img.png")
78
+ .set_image("https://exemplo.com/imagem_grande.png")
79
+ .set_thumbnail("https://exemplo.com/miniatura.png")
80
+ .add_field("Campo 1", "Valor 1", inline=True)
81
+ .add_field("Campo 2", "Valor 2", inline=True)
82
+ .set_timestamp() # Usa hora atual se não especificado
83
+ )
84
+
85
+ # Enviando o embed
86
+ ctx.reply(embeds=[embed])
87
+ ```
88
+
89
+ ### Trabalhando com Containers (Componentes V2)
90
+
91
+ Containers são componentes avançados que permitem agrupar outros componentes, como textos, separadores e galerias.
92
+
93
+ > **Nota:** Para enviar containers, use o método `reply_with_components` ou `update_with_components`.
94
+
95
+ ```python
96
+ from loopbot.builders import ContainerBuilder, SeparatorBuilder, MediaGalleryBuilder
97
+
98
+ @bot.command("container_demo", "Demonstração de Container")
99
+ def container_demo(ctx):
100
+ # Criando um container
101
+ container = (
102
+ ContainerBuilder()
103
+ .set_accent_color(0xFF0000) # Cor da barra lateral
104
+ .set_spoiler(False) # Se o conteúdo é spoiler
105
+ .add_text("# Título dentro do Container")
106
+ .add_text("Este é um texto normal dentro do container.")
107
+ )
108
+
109
+ # Adicionando um Separador
110
+ # spacing: 1 (pequeno) ou 2 (grande)
111
+ container.add_separator(divider=True, spacing=1)
112
+
113
+ # Adicionando uma Galeria de Mídia
114
+ gallery = (
115
+ MediaGalleryBuilder()
116
+ .add_item("https://exemplo.com/img1.png", "Legenda 1")
117
+ .add_item("https://exemplo.com/img2.png", "Legenda 2")
118
+ )
119
+ container.add_component(gallery)
120
+
121
+ # Enviando o container
122
+ ctx.reply_with_components(components=[container])
123
+ ```
124
+
125
+ ### Separadores
126
+
127
+ Separadores ajudam a organizar visualmente o conteúdo dentro de containers ou como componentes independentes.
128
+
129
+ ```python
130
+ from loopbot.builders import SeparatorBuilder
131
+
132
+ # Separador com linha visível e espaçamento grande
133
+ sep = SeparatorBuilder().set_divider(True).set_spacing(2)
134
+
135
+ container.add_component(sep)
136
+ ```
137
+
138
+ ### Respondendo Interações
139
+
140
+ O contexto (`ctx`) oferece vários métodos para responder a comandos e interações.
141
+
142
+ #### Responder com Texto e Embeds
143
+
144
+ ```python
145
+ # Apenas texto
146
+ ctx.reply("Olá mundo!")
147
+
148
+ # Texto e Embed
149
+ ctx.reply("Veja isso:", embeds=[embed])
150
+
151
+ # Resposta efêmera (visível apenas para o usuário que executou o comando)
152
+ ctx.reply("Segredo...", ephemeral=True)
153
+ ```
154
+
155
+ #### Responder com Componentes V2 (Containers)
156
+
157
+ Para enviar Containers, Galerias ou Separadores como resposta principal.
158
+
159
+ ```python
160
+ ctx.reply_with_components(components=[container1, container2])
161
+ ```
162
+
163
+ #### Atualizando a Mensagem Original
164
+
165
+ Útil para interações de botões ou menus de seleção, onde você deseja alterar a mensagem original em vez de enviar uma nova.
166
+
167
+ ```python
168
+ @bot.on_button("meu_botao")
169
+ def on_click(ctx):
170
+ # Atualiza texto e embeds da mensagem onde o botão estava
171
+ embed = EmbedBuilder().set_title("Atualizado!")
172
+ ctx.update(content="Nova mensagem", embeds=[embed])
173
+
174
+ # Ou para atualizar com Containers
175
+ # ctx.update_with_components(components=[novo_container])
176
+ ```
177
+
178
+ #### Editando a Resposta (Follow-up)
179
+
180
+ Se você já respondeu (por exemplo, com `defer` ou uma resposta rápida) e quer editar essa resposta depois.
181
+
182
+ ```python
183
+ @bot.command("processar", "Processamento longo")
184
+ def processar(ctx):
185
+ # Avise que está processando
186
+ ctx.defer()
187
+
188
+ # ... processamento demorado ...
189
+
190
+ # Edita a resposta original
191
+ ctx.edit_reply(content="Processamento concluído!", embeds=[resultado_embed])
192
+ ```
193
+
194
+ ### Botões e Action Rows
195
+
196
+ Botões são componentes interativos que os usuários podem clicar. Eles devem ser colocados dentro de uma `ActionRow`.
197
+
198
+ ```python
199
+ from loopbot.builders import ActionRowBuilder, ButtonBuilder
200
+
201
+ @bot.command("botoes", "Demo de botões")
202
+ def botoes(ctx):
203
+ # Criando botões
204
+ btn_primario = (
205
+ ButtonBuilder()
206
+ .set_label("Clique aqui")
207
+ .set_custom_id("btn_click")
208
+ .set_style(1) # 1: Primary (Azul)
209
+ )
210
+
211
+ btn_link = (
212
+ ButtonBuilder()
213
+ .set_label("Visite o site")
214
+ .set_url("https://loopbot.app")
215
+ .set_style(5) # 5: Link (Cinza)
216
+ )
217
+
218
+ # Adicionando à ActionRow
219
+ row = ActionRowBuilder().add_button(btn_primario).add_button(btn_link)
220
+
221
+ ctx.reply("Escolha uma opção:", components=[row])
222
+
223
+ @bot.on_button("btn_click")
224
+ def on_btn_click(ctx):
225
+ ctx.reply("Você clicou no botão!", ephemeral=True)
226
+ ```
227
+
228
+ ### Menus de Seleção (Dropdowns)
229
+
230
+ Menus de seleção permitem que o usuário escolha uma ou mais opções de uma lista.
231
+
232
+ ```python
233
+ from loopbot.builders import SelectMenuBuilder
234
+
235
+ @bot.command("menu", "Demo de menu")
236
+ def menu(ctx):
237
+ select = (
238
+ SelectMenuBuilder()
239
+ .set_custom_id("menu_selecao")
240
+ .set_placeholder("Escolha sua classe")
241
+ .add_option("Guerreiro", "warrior", "Classe de combate corpo a corpo")
242
+ .add_option("Mago", "mage", "Classe de magia", emoji={"name": "🔮"})
243
+ .set_min_values(1)
244
+ .set_max_values(1)
245
+ )
246
+
247
+ row = ActionRowBuilder().add_select_menu(select)
248
+ ctx.reply("Selecione sua classe:", components=[row])
249
+
250
+ @bot.on_select("menu_selecao") # Evento ainda não implementado na SDK Python, verifique suporte
251
+ def on_menu_select(ctx):
252
+ # Lógica de manipulação
253
+ pass
254
+ ```
255
+
256
+ ### Modais (Formulários)
257
+
258
+ Modais são janelas pop-up com formulários para entrada de texto.
259
+
260
+ ```python
261
+ from loopbot.builders import ModalBuilder
262
+
263
+ @bot.command("feedback", "Enviar feedback")
264
+ def feedback(ctx):
265
+ modal = (
266
+ ModalBuilder()
267
+ .set_custom_id("modal_feedback")
268
+ .set_title("Nos dê seu feedback")
269
+ .add_text_input(
270
+ custom_id="input_msg",
271
+ label="Mensagem",
272
+ style="paragraph", # ou "short"
273
+ placeholder="Escreva aqui...",
274
+ required=True
275
+ )
276
+ )
277
+
278
+ ctx.show_modal(modal)
279
+ ```
280
+
281
+ ### Layout Avançado (Sections)
282
+
283
+ Sections permitem agrupar texto com um "acessório" lateral, como um botão ou imagem.
284
+
285
+ ```python
286
+ from loopbot.builders import SectionBuilder, ButtonBuilder
287
+
288
+ @bot.command("section", "Demo de Section")
289
+ def section(ctx):
290
+ btn = ButtonBuilder().set_label("Ver Mais").set_url("https://google.com").set_style(5)
291
+
292
+ section = (
293
+ SectionBuilder()
294
+ .add_text("**Título da Seção**")
295
+ .add_text("Descrição detalhada ao lado do botão.")
296
+ .set_button_accessory(btn)
297
+ )
298
+
299
+ ctx.reply_with_components(components=[section])
300
+ ```
301
+
302
+ ### Arquivos
303
+
304
+ Envio de arquivos como anexos ou dentro de estruturas.
305
+
306
+ ```python
307
+ from loopbot.builders import FileBuilder
308
+
309
+ file = FileBuilder("https://exemplo.com/arquivo.pdf").set_spoiler(False)
310
+ # Adicione a um container ou envie conforme suporte da API
311
+ ```
312
+
313
+ ## Referência Rápida
314
+
315
+ | Funcionalidade | Builder / Método |
316
+ | :--- | :--- |
317
+ | **Embed** | `EmbedBuilder` |
318
+ | **Container** | `ContainerBuilder` |
319
+ | **Separador** | `SeparatorBuilder` |
320
+ | **Galeria** | `MediaGalleryBuilder` |
321
+ | **Botão** | `ButtonBuilder` |
322
+ | **Action Row** | `ActionRowBuilder` |
323
+ | **Select Menu** | `SelectMenuBuilder` |
324
+ | **Modal** | `ModalBuilder` |
325
+ | **Section** | `SectionBuilder` |
326
+ | **Arquivo** | `FileBuilder` |
327
+ | **Responder** | `ctx.reply(...)` |
328
+ | **Responder (Container)** | `ctx.reply_with_components(...)` |
329
+ | **Atualizar Msg** | `ctx.update(...)` |
330
+ | **Editar Resposta** | `ctx.edit_reply(...)` |
331
+
332
+ ## API de Mensagens Diretas
333
+
334
+ Envie mensagens fora do contexto de interação, gerencie canais, cargos e mais.
335
+
336
+ ### Enviando Mensagens
337
+
338
+ ```python
339
+ # Enviar mensagem para qualquer canal
340
+ await bot.send(channel_id, content="Olá!")
341
+
342
+ # Editar mensagem
343
+ await bot.edit_message(channel_id, message_id, content="Atualizado!")
344
+
345
+ # Deletar mensagem
346
+ await bot.delete_message(channel_id, message_id)
347
+ ```
348
+
349
+ ### Gerenciamento de Canais
350
+
351
+ ```python
352
+ # Criar canal
353
+ await bot.create_channel(guild_id, "novo-canal", topic="Descrição")
354
+
355
+ # Modificar canal
356
+ await bot.modify_channel(channel_id, name="canal-renomeado")
357
+
358
+ # Deletar canal
359
+ await bot.delete_channel(channel_id)
360
+ ```
361
+
362
+ ### Canais de Fórum
363
+
364
+ ```python
365
+ # Criar post no fórum
366
+ await bot.create_forum_post(
367
+ forum_channel_id,
368
+ name="Título do Post",
369
+ message={"content": "Conteúdo aqui"},
370
+ applied_tags=["tag_id"]
371
+ )
372
+
373
+ # Obter/modificar tags do fórum
374
+ tags = await bot.get_forum_tags(forum_channel_id)
375
+ await bot.modify_forum_tags(forum_channel_id, [{"name": "Nova Tag"}])
376
+
377
+ # Arquivar/trancar threads
378
+ await bot.archive_thread(thread_id)
379
+ await bot.lock_thread(thread_id)
380
+ ```
381
+
382
+ ### Cargos (Roles)
383
+
384
+ ```python
385
+ # Obter cargos
386
+ roles = await bot.get_roles(guild_id)
387
+
388
+ # Criar cargo
389
+ await bot.create_role(guild_id, name="Moderador", color=0x00FF00)
390
+
391
+ # Modificar cargo
392
+ await bot.modify_role(guild_id, role_id, name="Admin", hoist=True)
393
+
394
+ # Deletar cargo
395
+ await bot.delete_role(guild_id, role_id)
396
+
397
+ # Reordenar cargos
398
+ await bot.reorder_roles(guild_id, [{"id": role_id, "position": 2}])
399
+ ```
400
+
401
+ ### Webhooks
402
+
403
+ ```python
404
+ # Criar webhook
405
+ webhook = await bot.create_webhook(channel_id, "Meu Webhook")
406
+
407
+ # Enviar mensagem via webhook
408
+ await bot.execute_webhook(
409
+ webhook_id, webhook_token,
410
+ content="Mensagem via webhook!",
411
+ username="Nome Customizado"
412
+ )
413
+
414
+ # Editar/deletar mensagem do webhook
415
+ await bot.edit_webhook_message(webhook_id, webhook_token, message_id, content="Editado")
416
+ await bot.delete_webhook_message(webhook_id, webhook_token, message_id)
417
+
418
+ # Deletar webhook
419
+ await bot.delete_webhook(webhook_id)
420
+ ```
421
+
422
+ ### Gerenciamento de Membros
423
+
424
+ ```python
425
+ # Adicionar/remover cargos
426
+ await bot.add_member_role(guild_id, user_id, role_id)
427
+ await bot.remove_member_role(guild_id, user_id, role_id)
428
+
429
+ # Expulsar/banir membros
430
+ await bot.kick_member(guild_id, user_id)
431
+ await bot.ban_member(guild_id, user_id)
432
+ ```
433
+