yapper.py 1.2.0__tar.gz → 1.6.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.
- yapper_py-1.6.0/PKG-INFO +132 -0
- yapper_py-1.6.0/README.md +114 -0
- {yapper_py-1.2.0 → yapper_py-1.6.0}/pyproject.toml +1 -1
- yapper_py-1.6.0/src/yapper/__init__.py +6 -0
- yapper_py-1.6.0/src/yapper/main.py +2399 -0
- yapper_py-1.6.0/src/yapper.py.egg-info/PKG-INFO +132 -0
- {yapper_py-1.2.0 → yapper_py-1.6.0}/src/yapper.py.egg-info/SOURCES.txt +2 -1
- {yapper_py-1.2.0 → yapper_py-1.6.0}/tests/test_errors_and_test_event.py +8 -9
- yapper_py-1.6.0/tests/test_package_and_dotenv.py +102 -0
- yapper_py-1.2.0/PKG-INFO +0 -72
- yapper_py-1.2.0/README.md +0 -54
- yapper_py-1.2.0/src/yapper/__init__.py +0 -16
- yapper_py-1.2.0/src/yapper/main.py +0 -1280
- yapper_py-1.2.0/src/yapper.py.egg-info/PKG-INFO +0 -72
- {yapper_py-1.2.0 → yapper_py-1.6.0}/LICENSE +0 -0
- {yapper_py-1.2.0 → yapper_py-1.6.0}/setup.cfg +0 -0
- {yapper_py-1.2.0 → yapper_py-1.6.0}/src/yapper.py.egg-info/dependency_links.txt +0 -0
- {yapper_py-1.2.0 → yapper_py-1.6.0}/src/yapper.py.egg-info/requires.txt +0 -0
- {yapper_py-1.2.0 → yapper_py-1.6.0}/src/yapper.py.egg-info/top_level.txt +0 -0
- {yapper_py-1.2.0 → yapper_py-1.6.0}/tests/test_api_surface.py +0 -0
- {yapper_py-1.2.0 → yapper_py-1.6.0}/tests/test_metadata.py +0 -0
yapper_py-1.6.0/PKG-INFO
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: yapper.py
|
|
3
|
+
Version: 1.6.0
|
|
4
|
+
Summary: A Python Library for Yapin'
|
|
5
|
+
Author-email: "LeAndre C." <leandre@lecanact.me>
|
|
6
|
+
License-Expression: GPL-3.0-only
|
|
7
|
+
Project-URL: Repository, https://github.com/our-websites/yapper.py
|
|
8
|
+
Project-URL: Issues, https://github.com/our-websites/yapper.py/issues
|
|
9
|
+
Project-URL: Documentation, https://yapin.gg/developers
|
|
10
|
+
Keywords: yapper.py,yapin.py,discord.py,yapper,yapin
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: python-dotenv>=1.2.4
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# yapper.py
|
|
20
|
+
|
|
21
|
+
Python library for building bots on [Yapin'](https://yapin.gg/developers).
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install yapper.py
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Python 3.10 or newer. Prefer a single file? Download <https://yapin.gg/sdk/yapper.py> next to your bot and `import yapper`; it works without installing anything (a `.env` file is only read when `python-dotenv` is installed, which `pip install yapper.py` does for you).
|
|
30
|
+
|
|
31
|
+
## Quick start
|
|
32
|
+
|
|
33
|
+
Make a bot token in **Settings -> Developer** (it starts with `yb_`) and put it in a `.env` file next to your bot:
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
YAPPER_BOT_TOKEN=yb_your_token_here
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Then write `bot.py`:
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
import yapper
|
|
43
|
+
|
|
44
|
+
bot = yapper.Bot() # reads YAPPER_BOT_TOKEN from the environment or your .env file
|
|
45
|
+
|
|
46
|
+
@bot.command("ping", "Check if the bot is alive")
|
|
47
|
+
def ping(msg):
|
|
48
|
+
msg.reply("pong")
|
|
49
|
+
|
|
50
|
+
@bot.command("vote", "Start a pizza vote")
|
|
51
|
+
def vote(msg):
|
|
52
|
+
msg.reply(
|
|
53
|
+
embeds=yapper.Embed().title("Pizza tonight?").color("blue"),
|
|
54
|
+
components=yapper.Row(
|
|
55
|
+
yapper.Button.success("Yes", "vote:yes"),
|
|
56
|
+
yapper.Button.danger("No", "vote:no"),
|
|
57
|
+
),
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
@bot.button("vote:") # clicks on buttons whose custom_id starts with "vote:"
|
|
61
|
+
def voted(i):
|
|
62
|
+
i.ephemeral("You picked " + i.custom_id[5:])
|
|
63
|
+
|
|
64
|
+
@bot.on("member_join")
|
|
65
|
+
def welcome(ev):
|
|
66
|
+
print(f"{ev.username} joined")
|
|
67
|
+
|
|
68
|
+
bot.run()
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Run it with `python bot.py`. People can now type `/ping` or `!ping`. Nothing to host: the bot connects out to Yapin' and gets its events pushed (it falls back to long polling by itself).
|
|
72
|
+
|
|
73
|
+
### The `.env` file
|
|
74
|
+
|
|
75
|
+
`YAPPER_BOT_TOKEN` is read from your environment first, then from a `.env` file. The library looks for `.env` in the folder of the script you ran, then in the current folder, and in each parent folder. A variable that is already set in the environment always wins over the file. You can also pass the token directly: `yapper.Bot("yb_...")`.
|
|
76
|
+
|
|
77
|
+
## Main concepts
|
|
78
|
+
|
|
79
|
+
- **Commands**: `@bot.command("name", "description")`. People type `/name` or `!name`; `msg.args` is the rest of the line and `msg.argv` is it split on spaces.
|
|
80
|
+
- **Events**: `@bot.on("member_join")`, or `@bot.event` on a function named `on_member_join`. Also `@bot.on_dm` for direct messages and `@bot.on_reaction_on_mine` for reactions on the bot's own messages.
|
|
81
|
+
- **Buttons**: `@bot.button("prefix:")` for every `custom_id` starting with a prefix, or `@bot.on_button("ping")` for one exact id (a `re.compile(...)` pattern works too). Answer with `i.reply`, `i.ephemeral`, `i.update` or `i.ack` within 3 seconds.
|
|
82
|
+
- **Embeds and buttons**: `yapper.Embed()`, `yapper.Button`, `yapper.Row`. Every setter returns the object, so they chain: `yapper.Embed().title("Score").field("Kills", "12", True).color("green")`. The plain `yapper.row(...)`, `yapper.btn(...)` and `yapper.link_button(...)` helpers still work.
|
|
83
|
+
- **Components V2 layouts**: build a message out of `yapper.Container`, `Section`, `TextDisplay`, `MediaGallery`, `Separator` and `FileComponent`, then send it with `bot.send_layout(channel_id, [...])`:
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
bot.send_layout(channel_id, [
|
|
87
|
+
yapper.Container(
|
|
88
|
+
"# Ready?",
|
|
89
|
+
yapper.Section("Press go to start").accessory(yapper.Button.primary("Go", "go")),
|
|
90
|
+
).accent("blue"),
|
|
91
|
+
])
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
- **Cogs and extensions**: group commands, listeners and buttons into a class, usually one file per topic, and load a whole folder with `bot.load_cogs("cogs")`:
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
# cogs/fun.py
|
|
98
|
+
import yapper
|
|
99
|
+
|
|
100
|
+
class Fun(yapper.Cog):
|
|
101
|
+
@yapper.command("joke", "Tell a joke")
|
|
102
|
+
def joke(self, msg):
|
|
103
|
+
msg.reply("I know a UDP joke, but you might not get it")
|
|
104
|
+
|
|
105
|
+
@yapper.listener("member_join")
|
|
106
|
+
def hello(self, ev):
|
|
107
|
+
print(ev.username, "joined")
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Use `bot.add_cog(...)`, `bot.load_extension(...)`, `bot.unload_extension(...)` and `bot.reload_extension(...)` to manage them while the bot runs.
|
|
111
|
+
- **Errors**: failed API calls raise `yapper.YapperError` (`.status`, `.retry_after`). Rate limits are waited out for you.
|
|
112
|
+
|
|
113
|
+
## Useful bot methods
|
|
114
|
+
|
|
115
|
+
- **Messages**: `send`, `send_embed`, `send_layout`, `edit`, `edit_layout`, `delete`, `bulk_delete`, `pin`, `unpin`, `react`, `unreact`, `reactions`, `message`, `messages`, `messages_after`, `dm`, `dm_send`
|
|
116
|
+
- **Interactions**: `respond` (or `i.reply`, `i.ephemeral`, `i.update`, `i.ack` on the click itself)
|
|
117
|
+
- **Servers and members**: `servers`, `server`, `member_counts`, `channels`, `members`, `member`, `roles`, `user`, `emojis`, `invites`, `events`
|
|
118
|
+
- **Roles, channels and permissions**: `add_role`, `remove_role`, `create_role`, `edit_role`, `delete_role`, `create_channel`, `edit_channel`, `delete_channel`, `create_category`, `channel_permissions`, `set_channel_permissions`, `set_everyone_perms`
|
|
119
|
+
- **Moderation**: `kick`, `ban`, `unban`, `bans`, `timeout`, `set_nickname`
|
|
120
|
+
- **Voice**: `voice`, `move_member`, `disconnect_member`, `join_voice`, `leave_voice`, and `await bot.connect_voice(...)` for music bots (needs `pip install livekit cryptography`)
|
|
121
|
+
- **Webhooks**: `create_webhook`, `webhooks`, `my_webhooks`, `send_webhook`, `delete_webhook`
|
|
122
|
+
- **Presence and profile**: `set_status`, `set_profile`, `set_avatar`, `set_banner`
|
|
123
|
+
|
|
124
|
+
Every method has a docstring: `help(yapper.Bot.send)`.
|
|
125
|
+
|
|
126
|
+
## API reference
|
|
127
|
+
|
|
128
|
+
For payload details and limits, see the Yapin' developer docs: <https://yapin.gg/developers>
|
|
129
|
+
|
|
130
|
+
## License
|
|
131
|
+
|
|
132
|
+
GPL-3.0-only
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# yapper.py
|
|
2
|
+
|
|
3
|
+
Python library for building bots on [Yapin'](https://yapin.gg/developers).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install yapper.py
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Python 3.10 or newer. Prefer a single file? Download <https://yapin.gg/sdk/yapper.py> next to your bot and `import yapper`; it works without installing anything (a `.env` file is only read when `python-dotenv` is installed, which `pip install yapper.py` does for you).
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
Make a bot token in **Settings -> Developer** (it starts with `yb_`) and put it in a `.env` file next to your bot:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
YAPPER_BOT_TOKEN=yb_your_token_here
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Then write `bot.py`:
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
import yapper
|
|
25
|
+
|
|
26
|
+
bot = yapper.Bot() # reads YAPPER_BOT_TOKEN from the environment or your .env file
|
|
27
|
+
|
|
28
|
+
@bot.command("ping", "Check if the bot is alive")
|
|
29
|
+
def ping(msg):
|
|
30
|
+
msg.reply("pong")
|
|
31
|
+
|
|
32
|
+
@bot.command("vote", "Start a pizza vote")
|
|
33
|
+
def vote(msg):
|
|
34
|
+
msg.reply(
|
|
35
|
+
embeds=yapper.Embed().title("Pizza tonight?").color("blue"),
|
|
36
|
+
components=yapper.Row(
|
|
37
|
+
yapper.Button.success("Yes", "vote:yes"),
|
|
38
|
+
yapper.Button.danger("No", "vote:no"),
|
|
39
|
+
),
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
@bot.button("vote:") # clicks on buttons whose custom_id starts with "vote:"
|
|
43
|
+
def voted(i):
|
|
44
|
+
i.ephemeral("You picked " + i.custom_id[5:])
|
|
45
|
+
|
|
46
|
+
@bot.on("member_join")
|
|
47
|
+
def welcome(ev):
|
|
48
|
+
print(f"{ev.username} joined")
|
|
49
|
+
|
|
50
|
+
bot.run()
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Run it with `python bot.py`. People can now type `/ping` or `!ping`. Nothing to host: the bot connects out to Yapin' and gets its events pushed (it falls back to long polling by itself).
|
|
54
|
+
|
|
55
|
+
### The `.env` file
|
|
56
|
+
|
|
57
|
+
`YAPPER_BOT_TOKEN` is read from your environment first, then from a `.env` file. The library looks for `.env` in the folder of the script you ran, then in the current folder, and in each parent folder. A variable that is already set in the environment always wins over the file. You can also pass the token directly: `yapper.Bot("yb_...")`.
|
|
58
|
+
|
|
59
|
+
## Main concepts
|
|
60
|
+
|
|
61
|
+
- **Commands**: `@bot.command("name", "description")`. People type `/name` or `!name`; `msg.args` is the rest of the line and `msg.argv` is it split on spaces.
|
|
62
|
+
- **Events**: `@bot.on("member_join")`, or `@bot.event` on a function named `on_member_join`. Also `@bot.on_dm` for direct messages and `@bot.on_reaction_on_mine` for reactions on the bot's own messages.
|
|
63
|
+
- **Buttons**: `@bot.button("prefix:")` for every `custom_id` starting with a prefix, or `@bot.on_button("ping")` for one exact id (a `re.compile(...)` pattern works too). Answer with `i.reply`, `i.ephemeral`, `i.update` or `i.ack` within 3 seconds.
|
|
64
|
+
- **Embeds and buttons**: `yapper.Embed()`, `yapper.Button`, `yapper.Row`. Every setter returns the object, so they chain: `yapper.Embed().title("Score").field("Kills", "12", True).color("green")`. The plain `yapper.row(...)`, `yapper.btn(...)` and `yapper.link_button(...)` helpers still work.
|
|
65
|
+
- **Components V2 layouts**: build a message out of `yapper.Container`, `Section`, `TextDisplay`, `MediaGallery`, `Separator` and `FileComponent`, then send it with `bot.send_layout(channel_id, [...])`:
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
bot.send_layout(channel_id, [
|
|
69
|
+
yapper.Container(
|
|
70
|
+
"# Ready?",
|
|
71
|
+
yapper.Section("Press go to start").accessory(yapper.Button.primary("Go", "go")),
|
|
72
|
+
).accent("blue"),
|
|
73
|
+
])
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
- **Cogs and extensions**: group commands, listeners and buttons into a class, usually one file per topic, and load a whole folder with `bot.load_cogs("cogs")`:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
# cogs/fun.py
|
|
80
|
+
import yapper
|
|
81
|
+
|
|
82
|
+
class Fun(yapper.Cog):
|
|
83
|
+
@yapper.command("joke", "Tell a joke")
|
|
84
|
+
def joke(self, msg):
|
|
85
|
+
msg.reply("I know a UDP joke, but you might not get it")
|
|
86
|
+
|
|
87
|
+
@yapper.listener("member_join")
|
|
88
|
+
def hello(self, ev):
|
|
89
|
+
print(ev.username, "joined")
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Use `bot.add_cog(...)`, `bot.load_extension(...)`, `bot.unload_extension(...)` and `bot.reload_extension(...)` to manage them while the bot runs.
|
|
93
|
+
- **Errors**: failed API calls raise `yapper.YapperError` (`.status`, `.retry_after`). Rate limits are waited out for you.
|
|
94
|
+
|
|
95
|
+
## Useful bot methods
|
|
96
|
+
|
|
97
|
+
- **Messages**: `send`, `send_embed`, `send_layout`, `edit`, `edit_layout`, `delete`, `bulk_delete`, `pin`, `unpin`, `react`, `unreact`, `reactions`, `message`, `messages`, `messages_after`, `dm`, `dm_send`
|
|
98
|
+
- **Interactions**: `respond` (or `i.reply`, `i.ephemeral`, `i.update`, `i.ack` on the click itself)
|
|
99
|
+
- **Servers and members**: `servers`, `server`, `member_counts`, `channels`, `members`, `member`, `roles`, `user`, `emojis`, `invites`, `events`
|
|
100
|
+
- **Roles, channels and permissions**: `add_role`, `remove_role`, `create_role`, `edit_role`, `delete_role`, `create_channel`, `edit_channel`, `delete_channel`, `create_category`, `channel_permissions`, `set_channel_permissions`, `set_everyone_perms`
|
|
101
|
+
- **Moderation**: `kick`, `ban`, `unban`, `bans`, `timeout`, `set_nickname`
|
|
102
|
+
- **Voice**: `voice`, `move_member`, `disconnect_member`, `join_voice`, `leave_voice`, and `await bot.connect_voice(...)` for music bots (needs `pip install livekit cryptography`)
|
|
103
|
+
- **Webhooks**: `create_webhook`, `webhooks`, `my_webhooks`, `send_webhook`, `delete_webhook`
|
|
104
|
+
- **Presence and profile**: `set_status`, `set_profile`, `set_avatar`, `set_banner`
|
|
105
|
+
|
|
106
|
+
Every method has a docstring: `help(yapper.Bot.send)`.
|
|
107
|
+
|
|
108
|
+
## API reference
|
|
109
|
+
|
|
110
|
+
For payload details and limits, see the Yapin' developer docs: <https://yapin.gg/developers>
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
GPL-3.0-only
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"""yapper: the Yapin' bot library. `import yapper` gives you everything in `yapper.main.__all__`."""
|
|
2
|
+
from . import main as _main
|
|
3
|
+
from .main import * # noqa: F401,F403 (the public API is whatever main.py lists in __all__)
|
|
4
|
+
from .main import __version__
|
|
5
|
+
|
|
6
|
+
__all__ = [*_main.__all__, "__version__"]
|