dswebhook 0.2.2__tar.gz → 0.2.4__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.
- dswebhook-0.2.4/PKG-INFO +101 -0
- {dswebhook-0.2.2 → dswebhook-0.2.4}/README.md +38 -3
- {dswebhook-0.2.2 → dswebhook-0.2.4}/pyproject.toml +2 -1
- {dswebhook-0.2.2 → dswebhook-0.2.4}/src/dswebhook/dswebhook.py +11 -7
- dswebhook-0.2.4/src/dswebhook.egg-info/PKG-INFO +101 -0
- {dswebhook-0.2.2 → dswebhook-0.2.4}/src/exceptions.py +4 -0
- dswebhook-0.2.2/PKG-INFO +0 -9
- dswebhook-0.2.2/src/dswebhook.egg-info/PKG-INFO +0 -9
- {dswebhook-0.2.2 → dswebhook-0.2.4}/LICENSE +0 -0
- {dswebhook-0.2.2 → dswebhook-0.2.4}/setup.cfg +0 -0
- {dswebhook-0.2.2 → dswebhook-0.2.4}/src/dswebhook/__init__.py +0 -0
- {dswebhook-0.2.2 → dswebhook-0.2.4}/src/dswebhook.egg-info/SOURCES.txt +0 -0
- {dswebhook-0.2.2 → dswebhook-0.2.4}/src/dswebhook.egg-info/dependency_links.txt +0 -0
- {dswebhook-0.2.2 → dswebhook-0.2.4}/src/dswebhook.egg-info/requires.txt +0 -0
- {dswebhook-0.2.2 → dswebhook-0.2.4}/src/dswebhook.egg-info/top_level.txt +0 -0
dswebhook-0.2.4/PKG-INFO
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dswebhook
|
|
3
|
+
Version: 0.2.4
|
|
4
|
+
Summary: Lib for easy use of discord webhook
|
|
5
|
+
Author: Beks1k
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: requests>=2.28.0
|
|
10
|
+
Dynamic: license-file
|
|
11
|
+
|
|
12
|
+
# Simple Multi-Webhook Wrapper
|
|
13
|
+
|
|
14
|
+
A minimal and efficient Python wrapper for managing and sending messages to multiple webhooks simultaneously using numeric or string IDs. It includes built-in safeguards, response flashing, and clean custom error descriptions.
|
|
15
|
+
|
|
16
|
+
## Exceptions
|
|
17
|
+
|
|
18
|
+
The module imports exceptions from an external `exceptions` file:
|
|
19
|
+
|
|
20
|
+
- **`InvalidURL`**: Raised if the URL string is empty or missing.
|
|
21
|
+
- **`AlreadyExists`**: Raised if you try to register a URL on an ID that is already taken.
|
|
22
|
+
- **`NoSuchID`**: Raised if you try to send a message using an uninitialized ID.
|
|
23
|
+
- **`ContentTooLarge`**: Raised if the text payload exceeds the 2000-character limit.
|
|
24
|
+
- **`ConnectionError`**: Network issues or host is completely unreachable.
|
|
25
|
+
- **`SchemaError`**: Raised when the URL format misses `http://` or `https://`.
|
|
26
|
+
- **`BadRequest`**: Server returned an explicit HTTP `400` error.
|
|
27
|
+
- **`InternalServerError`**: Server encountered a critical HTTP `500` error.
|
|
28
|
+
- **`HTTPError`**: Triggers for any other non-2xx server responses.
|
|
29
|
+
- **`NotJSON`**: Triggers if given value isnt JSON
|
|
30
|
+
|
|
31
|
+
## Core Functions
|
|
32
|
+
|
|
33
|
+
### `init(url: str, id=1)`
|
|
34
|
+
Registers a webhook URL under a unique identifier.
|
|
35
|
+
- **Default ID:** `1`
|
|
36
|
+
- **Raises:** `InvalidURL` if the URL is empty, `AlreadyExists` if the ID is already registered.
|
|
37
|
+
|
|
38
|
+
### `send(content: str, ids, statCode: bool = False, flush: bool = False)`
|
|
39
|
+
Dispatches a payload string to the webhook registered under the specified `ids`.
|
|
40
|
+
- **`ids`**: The target webhook identifier.
|
|
41
|
+
- **`statCode`**: If set to `True`, prints the server response status code in the console.
|
|
42
|
+
- **`flush`**: If set to `True`, prints the raw text/JSON response returned from the server endpoint.
|
|
43
|
+
- **`customJSON`**: Must be a variable dictionary, sends custom JSON request for custom url
|
|
44
|
+
|
|
45
|
+
## Usage Example
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
import dswebhook as dsw
|
|
49
|
+
|
|
50
|
+
# 1. Initialize dswebhook with ID
|
|
51
|
+
|
|
52
|
+
dsw.init("https://discord.com...", id=1)
|
|
53
|
+
dsw.init("https://discord.com...", id="backup_channel")
|
|
54
|
+
|
|
55
|
+
# 2. Send logs with debugging features enabled
|
|
56
|
+
try:
|
|
57
|
+
# Sends a message and prints out status code and server raw response text
|
|
58
|
+
dsw.send("System updated successfully!", ids=1, statCode=True, flush=True)
|
|
59
|
+
|
|
60
|
+
# Sends a message to the second text channel using a string ID
|
|
61
|
+
dsw.send("Alert triggered.", ids="backup_channel")
|
|
62
|
+
|
|
63
|
+
except dsw.AlreadyExists as e:
|
|
64
|
+
print(f"Configuration conflict: {e}")
|
|
65
|
+
except dsw.NoSuchID as e:
|
|
66
|
+
print(f"Targeting error: {e}")
|
|
67
|
+
except dsw.HTTPError as e:
|
|
68
|
+
print(f"Server communication failed: {e}")
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Usage example for custom JSON request
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
import dswebhook as dsw
|
|
75
|
+
|
|
76
|
+
# 1. Initialize dswebhook with ID
|
|
77
|
+
|
|
78
|
+
customData = {
|
|
79
|
+
"auth":"User"
|
|
80
|
+
"token":"token"
|
|
81
|
+
...
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
dsw.init("https://your-custom-URL...", id=1)
|
|
85
|
+
dsw.init("https://your-custom-URL...", id="backup_channel")
|
|
86
|
+
|
|
87
|
+
# 2. Send logs with debugging features enabled
|
|
88
|
+
try:
|
|
89
|
+
# Sends a message with custom JSON and prints out status code and server raw response text
|
|
90
|
+
dsw.send("System updated successfully!", ids=1, statCode=True, flush=True, customJSON=customData )
|
|
91
|
+
|
|
92
|
+
# Sends a message to the second text channel using a string ID
|
|
93
|
+
dsw.send("Alert triggered.", ids="backup_channel")
|
|
94
|
+
|
|
95
|
+
except dsw.AlreadyExists as e:
|
|
96
|
+
print(f"Configuration conflict: {e}")
|
|
97
|
+
except dsw.NoSuchID as e:
|
|
98
|
+
print(f"Targeting error: {e}")
|
|
99
|
+
except dsw.HTTPError as e:
|
|
100
|
+
print(f"Server communication failed: {e}")
|
|
101
|
+
```
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
A minimal and efficient Python wrapper for managing and sending messages to multiple webhooks simultaneously using numeric or string IDs. It includes built-in safeguards, response flashing, and clean custom error descriptions.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Exceptions
|
|
6
6
|
|
|
7
|
-
The module imports
|
|
7
|
+
The module imports exceptions from an external `exceptions` file:
|
|
8
8
|
|
|
9
9
|
- **`InvalidURL`**: Raised if the URL string is empty or missing.
|
|
10
10
|
- **`AlreadyExists`**: Raised if you try to register a URL on an ID that is already taken.
|
|
@@ -15,6 +15,7 @@ The module imports custom exceptions from an external `exceptions` file:
|
|
|
15
15
|
- **`BadRequest`**: Server returned an explicit HTTP `400` error.
|
|
16
16
|
- **`InternalServerError`**: Server encountered a critical HTTP `500` error.
|
|
17
17
|
- **`HTTPError`**: Triggers for any other non-2xx server responses.
|
|
18
|
+
- **`NotJSON`**: Triggers if given value isnt JSON
|
|
18
19
|
|
|
19
20
|
## Core Functions
|
|
20
21
|
|
|
@@ -28,6 +29,7 @@ Dispatches a payload string to the webhook registered under the specified `ids`.
|
|
|
28
29
|
- **`ids`**: The target webhook identifier.
|
|
29
30
|
- **`statCode`**: If set to `True`, prints the server response status code in the console.
|
|
30
31
|
- **`flush`**: If set to `True`, prints the raw text/JSON response returned from the server endpoint.
|
|
32
|
+
- **`customJSON`**: Must be a variable dictionary, sends custom JSON request for custom url
|
|
31
33
|
|
|
32
34
|
## Usage Example
|
|
33
35
|
|
|
@@ -36,7 +38,8 @@ import dswebhook as dsw
|
|
|
36
38
|
|
|
37
39
|
# 1. Initialize dswebhook with ID
|
|
38
40
|
|
|
39
|
-
dsw.init("https://discord.com...", id=1)
|
|
41
|
+
dsw.init("https://discord.com...", id=1)
|
|
42
|
+
dsw.init("https://discord.com...", id="backup_channel")
|
|
40
43
|
|
|
41
44
|
# 2. Send logs with debugging features enabled
|
|
42
45
|
try:
|
|
@@ -53,3 +56,35 @@ except dsw.NoSuchID as e:
|
|
|
53
56
|
except dsw.HTTPError as e:
|
|
54
57
|
print(f"Server communication failed: {e}")
|
|
55
58
|
```
|
|
59
|
+
|
|
60
|
+
### Usage example for custom JSON request
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
import dswebhook as dsw
|
|
64
|
+
|
|
65
|
+
# 1. Initialize dswebhook with ID
|
|
66
|
+
|
|
67
|
+
customData = {
|
|
68
|
+
"auth":"User"
|
|
69
|
+
"token":"token"
|
|
70
|
+
...
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
dsw.init("https://your-custom-URL...", id=1)
|
|
74
|
+
dsw.init("https://your-custom-URL...", id="backup_channel")
|
|
75
|
+
|
|
76
|
+
# 2. Send logs with debugging features enabled
|
|
77
|
+
try:
|
|
78
|
+
# Sends a message with custom JSON and prints out status code and server raw response text
|
|
79
|
+
dsw.send("System updated successfully!", ids=1, statCode=True, flush=True, customJSON=customData )
|
|
80
|
+
|
|
81
|
+
# Sends a message to the second text channel using a string ID
|
|
82
|
+
dsw.send("Alert triggered.", ids="backup_channel")
|
|
83
|
+
|
|
84
|
+
except dsw.AlreadyExists as e:
|
|
85
|
+
print(f"Configuration conflict: {e}")
|
|
86
|
+
except dsw.NoSuchID as e:
|
|
87
|
+
print(f"Targeting error: {e}")
|
|
88
|
+
except dsw.HTTPError as e:
|
|
89
|
+
print(f"Server communication failed: {e}")
|
|
90
|
+
```
|
|
@@ -2,7 +2,7 @@ import requests
|
|
|
2
2
|
|
|
3
3
|
from exceptions import (
|
|
4
4
|
InvalidURL, SchemaError, AlreadyExists, NoSuchID,
|
|
5
|
-
ContentTooLarge, ConnectionError, BadRequest, InternalServerError, HTTPError
|
|
5
|
+
ContentTooLarge, ConnectionError, BadRequest, InternalServerError, HTTPError, NotJSON
|
|
6
6
|
)
|
|
7
7
|
urlr = {}
|
|
8
8
|
|
|
@@ -15,7 +15,7 @@ def init(url:str, id=1):
|
|
|
15
15
|
raise AlreadyExists(f"{id} ALREADY EXSISTS")
|
|
16
16
|
urlr[id] = url
|
|
17
17
|
|
|
18
|
-
def send(content:str, ids, statCode:bool=False, flush:bool = False):
|
|
18
|
+
def send(content:str, ids, statCode:bool=False, flush:bool = False, customJSON = {}):
|
|
19
19
|
'''Send content to specified webhook'''
|
|
20
20
|
global urlr
|
|
21
21
|
if not urlr:
|
|
@@ -25,23 +25,27 @@ def send(content:str, ids, statCode:bool=False, flush:bool = False):
|
|
|
25
25
|
data = {
|
|
26
26
|
"content":content
|
|
27
27
|
}
|
|
28
|
+
if not isinstance(customJSON, dict):
|
|
29
|
+
raise NotJSON("customJSON PARAMETR IS NOT DICTIONARY. FOR id{ids}")
|
|
30
|
+
if customJSON:
|
|
31
|
+
data = customJSON
|
|
28
32
|
if urlr.get(ids) == None:
|
|
29
33
|
raise NoSuchID(f"NOT FOUND {ids}")
|
|
30
34
|
try:
|
|
31
35
|
a = requests.post(urlr.get(ids), json=data)
|
|
32
36
|
except requests.exceptions.ConnectionError:
|
|
33
|
-
raise ConnectionError(f"CONNECTION ERROR FOR {ids} PLEASE CHECK CONNETCTION AND URL FOR ANY ERRORS")
|
|
37
|
+
raise ConnectionError(f"CONNECTION ERROR FOR id={ids}. PLEASE CHECK CONNETCTION AND URL FOR ANY ERRORS")
|
|
34
38
|
except requests.exceptions.MissingSchema:
|
|
35
|
-
raise SchemaError(f"MUST BE WITH https:// OR http:// IF HTTPS NOT SUPPORTED FOR {ids}")
|
|
39
|
+
raise SchemaError(f"MUST BE WITH https:// OR http:// IF HTTPS NOT SUPPORTED. FOR id={ids}")
|
|
36
40
|
|
|
37
41
|
if a.status_code == 400:
|
|
38
|
-
raise BadRequest(f"BAD REQUEST (HTTP ERROR: 400) FOR {ids}")
|
|
42
|
+
raise BadRequest(f"BAD REQUEST (HTTP ERROR: 400). FOR id{ids}")
|
|
39
43
|
|
|
40
44
|
if a.status_code == 500:
|
|
41
|
-
raise InternalServerError(f"INTERNAL SERVER ERROR (HTTP ERROR: 500) FOR {ids}")
|
|
45
|
+
raise InternalServerError(f"INTERNAL SERVER ERROR (HTTP ERROR: 500). FOR id={ids}")
|
|
42
46
|
|
|
43
47
|
if not a.ok:
|
|
44
|
-
raise HTTPError(f"SERVER RETURNED NOT 2xx RESPONSE {a.status_code} FOR {ids}")
|
|
48
|
+
raise HTTPError(f"SERVER RETURNED NOT 2xx RESPONSE {a.status_code}. FOR id={ids}")
|
|
45
49
|
|
|
46
50
|
if statCode:
|
|
47
51
|
print(a.status_code, f"FOR {ids}")
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dswebhook
|
|
3
|
+
Version: 0.2.4
|
|
4
|
+
Summary: Lib for easy use of discord webhook
|
|
5
|
+
Author: Beks1k
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: requests>=2.28.0
|
|
10
|
+
Dynamic: license-file
|
|
11
|
+
|
|
12
|
+
# Simple Multi-Webhook Wrapper
|
|
13
|
+
|
|
14
|
+
A minimal and efficient Python wrapper for managing and sending messages to multiple webhooks simultaneously using numeric or string IDs. It includes built-in safeguards, response flashing, and clean custom error descriptions.
|
|
15
|
+
|
|
16
|
+
## Exceptions
|
|
17
|
+
|
|
18
|
+
The module imports exceptions from an external `exceptions` file:
|
|
19
|
+
|
|
20
|
+
- **`InvalidURL`**: Raised if the URL string is empty or missing.
|
|
21
|
+
- **`AlreadyExists`**: Raised if you try to register a URL on an ID that is already taken.
|
|
22
|
+
- **`NoSuchID`**: Raised if you try to send a message using an uninitialized ID.
|
|
23
|
+
- **`ContentTooLarge`**: Raised if the text payload exceeds the 2000-character limit.
|
|
24
|
+
- **`ConnectionError`**: Network issues or host is completely unreachable.
|
|
25
|
+
- **`SchemaError`**: Raised when the URL format misses `http://` or `https://`.
|
|
26
|
+
- **`BadRequest`**: Server returned an explicit HTTP `400` error.
|
|
27
|
+
- **`InternalServerError`**: Server encountered a critical HTTP `500` error.
|
|
28
|
+
- **`HTTPError`**: Triggers for any other non-2xx server responses.
|
|
29
|
+
- **`NotJSON`**: Triggers if given value isnt JSON
|
|
30
|
+
|
|
31
|
+
## Core Functions
|
|
32
|
+
|
|
33
|
+
### `init(url: str, id=1)`
|
|
34
|
+
Registers a webhook URL under a unique identifier.
|
|
35
|
+
- **Default ID:** `1`
|
|
36
|
+
- **Raises:** `InvalidURL` if the URL is empty, `AlreadyExists` if the ID is already registered.
|
|
37
|
+
|
|
38
|
+
### `send(content: str, ids, statCode: bool = False, flush: bool = False)`
|
|
39
|
+
Dispatches a payload string to the webhook registered under the specified `ids`.
|
|
40
|
+
- **`ids`**: The target webhook identifier.
|
|
41
|
+
- **`statCode`**: If set to `True`, prints the server response status code in the console.
|
|
42
|
+
- **`flush`**: If set to `True`, prints the raw text/JSON response returned from the server endpoint.
|
|
43
|
+
- **`customJSON`**: Must be a variable dictionary, sends custom JSON request for custom url
|
|
44
|
+
|
|
45
|
+
## Usage Example
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
import dswebhook as dsw
|
|
49
|
+
|
|
50
|
+
# 1. Initialize dswebhook with ID
|
|
51
|
+
|
|
52
|
+
dsw.init("https://discord.com...", id=1)
|
|
53
|
+
dsw.init("https://discord.com...", id="backup_channel")
|
|
54
|
+
|
|
55
|
+
# 2. Send logs with debugging features enabled
|
|
56
|
+
try:
|
|
57
|
+
# Sends a message and prints out status code and server raw response text
|
|
58
|
+
dsw.send("System updated successfully!", ids=1, statCode=True, flush=True)
|
|
59
|
+
|
|
60
|
+
# Sends a message to the second text channel using a string ID
|
|
61
|
+
dsw.send("Alert triggered.", ids="backup_channel")
|
|
62
|
+
|
|
63
|
+
except dsw.AlreadyExists as e:
|
|
64
|
+
print(f"Configuration conflict: {e}")
|
|
65
|
+
except dsw.NoSuchID as e:
|
|
66
|
+
print(f"Targeting error: {e}")
|
|
67
|
+
except dsw.HTTPError as e:
|
|
68
|
+
print(f"Server communication failed: {e}")
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Usage example for custom JSON request
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
import dswebhook as dsw
|
|
75
|
+
|
|
76
|
+
# 1. Initialize dswebhook with ID
|
|
77
|
+
|
|
78
|
+
customData = {
|
|
79
|
+
"auth":"User"
|
|
80
|
+
"token":"token"
|
|
81
|
+
...
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
dsw.init("https://your-custom-URL...", id=1)
|
|
85
|
+
dsw.init("https://your-custom-URL...", id="backup_channel")
|
|
86
|
+
|
|
87
|
+
# 2. Send logs with debugging features enabled
|
|
88
|
+
try:
|
|
89
|
+
# Sends a message with custom JSON and prints out status code and server raw response text
|
|
90
|
+
dsw.send("System updated successfully!", ids=1, statCode=True, flush=True, customJSON=customData )
|
|
91
|
+
|
|
92
|
+
# Sends a message to the second text channel using a string ID
|
|
93
|
+
dsw.send("Alert triggered.", ids="backup_channel")
|
|
94
|
+
|
|
95
|
+
except dsw.AlreadyExists as e:
|
|
96
|
+
print(f"Configuration conflict: {e}")
|
|
97
|
+
except dsw.NoSuchID as e:
|
|
98
|
+
print(f"Targeting error: {e}")
|
|
99
|
+
except dsw.HTTPError as e:
|
|
100
|
+
print(f"Server communication failed: {e}")
|
|
101
|
+
```
|
dswebhook-0.2.2/PKG-INFO
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|