webhookspot 1.0.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.
- webhookspot-1.0.0/LICENSE +21 -0
- webhookspot-1.0.0/PKG-INFO +75 -0
- webhookspot-1.0.0/README.md +55 -0
- webhookspot-1.0.0/pyproject.toml +3 -0
- webhookspot-1.0.0/setup.cfg +4 -0
- webhookspot-1.0.0/setup.py +18 -0
- webhookspot-1.0.0/webhookspot/__init__.py +4 -0
- webhookspot-1.0.0/webhookspot/core.py +148 -0
- webhookspot-1.0.0/webhookspot.egg-info/PKG-INFO +75 -0
- webhookspot-1.0.0/webhookspot.egg-info/SOURCES.txt +10 -0
- webhookspot-1.0.0/webhookspot.egg-info/dependency_links.txt +1 -0
- webhookspot-1.0.0/webhookspot.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 webhookspot
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: webhookspot
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A tiny Python library for sending Discord webhook messages.
|
|
5
|
+
Author: webhookspot
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Dynamic: author
|
|
14
|
+
Dynamic: classifier
|
|
15
|
+
Dynamic: description
|
|
16
|
+
Dynamic: description-content-type
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
Dynamic: requires-python
|
|
19
|
+
Dynamic: summary
|
|
20
|
+
|
|
21
|
+
# webhookspot
|
|
22
|
+
|
|
23
|
+
`webhookspot` is a tiny Python library for sending Discord webhook messages.
|
|
24
|
+
|
|
25
|
+
## Install locally
|
|
26
|
+
|
|
27
|
+
Open a terminal in this folder and run:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
py -m pip install .
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
or:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install .
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Example
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
import webhookspot
|
|
43
|
+
|
|
44
|
+
x = webhookspot.Webhook("https://discord.com/api/webhooks/YOUR_WEBHOOK_ID/YOUR_WEBHOOK_TOKEN")
|
|
45
|
+
x.send_message("hello")
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## More examples
|
|
49
|
+
|
|
50
|
+
Change the webhook username:
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
import webhookspot
|
|
54
|
+
|
|
55
|
+
hook = webhookspot.Webhook("https://discord.com/api/webhooks/YOUR_WEBHOOK_ID/YOUR_WEBHOOK_TOKEN")
|
|
56
|
+
hook.send_message("Hello from webhookspot!", username="WebhookSpot Bot")
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Send an embed:
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
import webhookspot
|
|
63
|
+
|
|
64
|
+
hook = webhookspot.Webhook("https://discord.com/api/webhooks/YOUR_WEBHOOK_ID/YOUR_WEBHOOK_TOKEN")
|
|
65
|
+
|
|
66
|
+
hook.send_embed(
|
|
67
|
+
title="WebhookSpot",
|
|
68
|
+
description="This is an embed message.",
|
|
69
|
+
color=0x5865F2
|
|
70
|
+
)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Safety note
|
|
74
|
+
|
|
75
|
+
Do not post your real Discord webhook URL publicly. Anyone with the URL can send messages through it.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# webhookspot
|
|
2
|
+
|
|
3
|
+
`webhookspot` is a tiny Python library for sending Discord webhook messages.
|
|
4
|
+
|
|
5
|
+
## Install locally
|
|
6
|
+
|
|
7
|
+
Open a terminal in this folder and run:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
py -m pip install .
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
or:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install .
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Example
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
import webhookspot
|
|
23
|
+
|
|
24
|
+
x = webhookspot.Webhook("https://discord.com/api/webhooks/YOUR_WEBHOOK_ID/YOUR_WEBHOOK_TOKEN")
|
|
25
|
+
x.send_message("hello")
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## More examples
|
|
29
|
+
|
|
30
|
+
Change the webhook username:
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
import webhookspot
|
|
34
|
+
|
|
35
|
+
hook = webhookspot.Webhook("https://discord.com/api/webhooks/YOUR_WEBHOOK_ID/YOUR_WEBHOOK_TOKEN")
|
|
36
|
+
hook.send_message("Hello from webhookspot!", username="WebhookSpot Bot")
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Send an embed:
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
import webhookspot
|
|
43
|
+
|
|
44
|
+
hook = webhookspot.Webhook("https://discord.com/api/webhooks/YOUR_WEBHOOK_ID/YOUR_WEBHOOK_TOKEN")
|
|
45
|
+
|
|
46
|
+
hook.send_embed(
|
|
47
|
+
title="WebhookSpot",
|
|
48
|
+
description="This is an embed message.",
|
|
49
|
+
color=0x5865F2
|
|
50
|
+
)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Safety note
|
|
54
|
+
|
|
55
|
+
Do not post your real Discord webhook URL publicly. Anyone with the URL can send messages through it.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="webhookspot",
|
|
5
|
+
version="1.0.0",
|
|
6
|
+
description="A tiny Python library for sending Discord webhook messages.",
|
|
7
|
+
long_description=open("README.md", encoding="utf-8").read(),
|
|
8
|
+
long_description_content_type="text/markdown",
|
|
9
|
+
author="webhookspot",
|
|
10
|
+
packages=find_packages(),
|
|
11
|
+
python_requires=">=3.8",
|
|
12
|
+
classifiers=[
|
|
13
|
+
"Programming Language :: Python :: 3",
|
|
14
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
15
|
+
"License :: OSI Approved :: MIT License",
|
|
16
|
+
"Operating System :: OS Independent",
|
|
17
|
+
],
|
|
18
|
+
)
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import urllib.error
|
|
3
|
+
import urllib.request
|
|
4
|
+
from typing import Any, Dict, List, Optional
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class WebhookError(Exception):
|
|
8
|
+
"""Raised when Discord rejects the webhook request."""
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Webhook:
|
|
12
|
+
"""
|
|
13
|
+
Simple Discord webhook sender.
|
|
14
|
+
|
|
15
|
+
Example:
|
|
16
|
+
import webhookspot
|
|
17
|
+
|
|
18
|
+
x = webhookspot.Webhook("https://discord.com/api/webhooks/...")
|
|
19
|
+
x.send_message("hello")
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def __init__(self, url: str):
|
|
23
|
+
if not isinstance(url, str) or not url.strip():
|
|
24
|
+
raise ValueError("Webhook URL must be a non-empty string.")
|
|
25
|
+
|
|
26
|
+
if "discord.com/api/webhooks/" not in url and "discordapp.com/api/webhooks/" not in url:
|
|
27
|
+
raise ValueError("This does not look like a Discord webhook URL.")
|
|
28
|
+
|
|
29
|
+
self.url = url.strip()
|
|
30
|
+
|
|
31
|
+
def _post(self, payload: Dict[str, Any]) -> Dict[str, Any]:
|
|
32
|
+
data = json.dumps(payload).encode("utf-8")
|
|
33
|
+
|
|
34
|
+
req = urllib.request.Request(
|
|
35
|
+
self.url,
|
|
36
|
+
data=data,
|
|
37
|
+
headers={
|
|
38
|
+
"Content-Type": "application/json",
|
|
39
|
+
"User-Agent": "webhookspot/1.0.0",
|
|
40
|
+
},
|
|
41
|
+
method="POST",
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
try:
|
|
45
|
+
with urllib.request.urlopen(req, timeout=15) as response:
|
|
46
|
+
text = response.read().decode("utf-8", errors="replace")
|
|
47
|
+
if text:
|
|
48
|
+
try:
|
|
49
|
+
return json.loads(text)
|
|
50
|
+
except json.JSONDecodeError:
|
|
51
|
+
return {"raw": text}
|
|
52
|
+
return {"ok": True, "status": response.status}
|
|
53
|
+
|
|
54
|
+
except urllib.error.HTTPError as e:
|
|
55
|
+
body = e.read().decode("utf-8", errors="replace")
|
|
56
|
+
raise WebhookError(f"Discord returned HTTP {e.code}: {body}") from e
|
|
57
|
+
|
|
58
|
+
except urllib.error.URLError as e:
|
|
59
|
+
raise WebhookError(f"Could not connect to Discord: {e}") from e
|
|
60
|
+
|
|
61
|
+
def send_message(
|
|
62
|
+
self,
|
|
63
|
+
message: str,
|
|
64
|
+
username: Optional[str] = None,
|
|
65
|
+
avatar_url: Optional[str] = None,
|
|
66
|
+
tts: bool = False,
|
|
67
|
+
) -> Dict[str, Any]:
|
|
68
|
+
"""
|
|
69
|
+
Send a normal text message.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
message: The message to send.
|
|
73
|
+
username: Optional custom webhook username.
|
|
74
|
+
avatar_url: Optional custom webhook avatar URL.
|
|
75
|
+
tts: Whether Discord should read the message using text-to-speech.
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
A dictionary with request result information.
|
|
79
|
+
"""
|
|
80
|
+
if not isinstance(message, str) or not message:
|
|
81
|
+
raise ValueError("Message must be a non-empty string.")
|
|
82
|
+
|
|
83
|
+
payload: Dict[str, Any] = {
|
|
84
|
+
"content": message,
|
|
85
|
+
"tts": bool(tts),
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if username:
|
|
89
|
+
payload["username"] = username
|
|
90
|
+
|
|
91
|
+
if avatar_url:
|
|
92
|
+
payload["avatar_url"] = avatar_url
|
|
93
|
+
|
|
94
|
+
return self._post(payload)
|
|
95
|
+
|
|
96
|
+
def send_embed(
|
|
97
|
+
self,
|
|
98
|
+
title: Optional[str] = None,
|
|
99
|
+
description: Optional[str] = None,
|
|
100
|
+
color: Optional[int] = None,
|
|
101
|
+
fields: Optional[List[Dict[str, Any]]] = None,
|
|
102
|
+
username: Optional[str] = None,
|
|
103
|
+
avatar_url: Optional[str] = None,
|
|
104
|
+
) -> Dict[str, Any]:
|
|
105
|
+
"""
|
|
106
|
+
Send a simple Discord embed.
|
|
107
|
+
|
|
108
|
+
Args:
|
|
109
|
+
title: Embed title.
|
|
110
|
+
description: Embed description.
|
|
111
|
+
color: Embed color as an integer, like 0x5865F2.
|
|
112
|
+
fields: Optional list of embed fields.
|
|
113
|
+
username: Optional custom webhook username.
|
|
114
|
+
avatar_url: Optional custom webhook avatar URL.
|
|
115
|
+
|
|
116
|
+
Returns:
|
|
117
|
+
A dictionary with request result information.
|
|
118
|
+
"""
|
|
119
|
+
embed: Dict[str, Any] = {}
|
|
120
|
+
|
|
121
|
+
if title:
|
|
122
|
+
embed["title"] = title
|
|
123
|
+
|
|
124
|
+
if description:
|
|
125
|
+
embed["description"] = description
|
|
126
|
+
|
|
127
|
+
if color is not None:
|
|
128
|
+
if not isinstance(color, int):
|
|
129
|
+
raise ValueError("Color must be an integer, like 0x5865F2.")
|
|
130
|
+
embed["color"] = color
|
|
131
|
+
|
|
132
|
+
if fields:
|
|
133
|
+
embed["fields"] = fields
|
|
134
|
+
|
|
135
|
+
if not embed:
|
|
136
|
+
raise ValueError("Embed must have at least a title, description, color, or fields.")
|
|
137
|
+
|
|
138
|
+
payload: Dict[str, Any] = {
|
|
139
|
+
"embeds": [embed],
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if username:
|
|
143
|
+
payload["username"] = username
|
|
144
|
+
|
|
145
|
+
if avatar_url:
|
|
146
|
+
payload["avatar_url"] = avatar_url
|
|
147
|
+
|
|
148
|
+
return self._post(payload)
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: webhookspot
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A tiny Python library for sending Discord webhook messages.
|
|
5
|
+
Author: webhookspot
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Dynamic: author
|
|
14
|
+
Dynamic: classifier
|
|
15
|
+
Dynamic: description
|
|
16
|
+
Dynamic: description-content-type
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
Dynamic: requires-python
|
|
19
|
+
Dynamic: summary
|
|
20
|
+
|
|
21
|
+
# webhookspot
|
|
22
|
+
|
|
23
|
+
`webhookspot` is a tiny Python library for sending Discord webhook messages.
|
|
24
|
+
|
|
25
|
+
## Install locally
|
|
26
|
+
|
|
27
|
+
Open a terminal in this folder and run:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
py -m pip install .
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
or:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install .
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Example
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
import webhookspot
|
|
43
|
+
|
|
44
|
+
x = webhookspot.Webhook("https://discord.com/api/webhooks/YOUR_WEBHOOK_ID/YOUR_WEBHOOK_TOKEN")
|
|
45
|
+
x.send_message("hello")
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## More examples
|
|
49
|
+
|
|
50
|
+
Change the webhook username:
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
import webhookspot
|
|
54
|
+
|
|
55
|
+
hook = webhookspot.Webhook("https://discord.com/api/webhooks/YOUR_WEBHOOK_ID/YOUR_WEBHOOK_TOKEN")
|
|
56
|
+
hook.send_message("Hello from webhookspot!", username="WebhookSpot Bot")
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Send an embed:
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
import webhookspot
|
|
63
|
+
|
|
64
|
+
hook = webhookspot.Webhook("https://discord.com/api/webhooks/YOUR_WEBHOOK_ID/YOUR_WEBHOOK_TOKEN")
|
|
65
|
+
|
|
66
|
+
hook.send_embed(
|
|
67
|
+
title="WebhookSpot",
|
|
68
|
+
description="This is an embed message.",
|
|
69
|
+
color=0x5865F2
|
|
70
|
+
)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Safety note
|
|
74
|
+
|
|
75
|
+
Do not post your real Discord webhook URL publicly. Anyone with the URL can send messages through it.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
webhookspot
|