dswebhook 0.2.2__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.2/LICENSE +21 -0
- dswebhook-0.2.2/PKG-INFO +9 -0
- dswebhook-0.2.2/README.md +55 -0
- dswebhook-0.2.2/pyproject.toml +19 -0
- dswebhook-0.2.2/setup.cfg +4 -0
- dswebhook-0.2.2/src/dswebhook/__init__.py +3 -0
- dswebhook-0.2.2/src/dswebhook/dswebhook.py +53 -0
- dswebhook-0.2.2/src/dswebhook.egg-info/PKG-INFO +9 -0
- dswebhook-0.2.2/src/dswebhook.egg-info/SOURCES.txt +11 -0
- dswebhook-0.2.2/src/dswebhook.egg-info/dependency_links.txt +1 -0
- dswebhook-0.2.2/src/dswebhook.egg-info/requires.txt +1 -0
- dswebhook-0.2.2/src/dswebhook.egg-info/top_level.txt +2 -0
- dswebhook-0.2.2/src/exceptions.py +35 -0
dswebhook-0.2.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Beks1k
|
|
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.
|
dswebhook-0.2.2/PKG-INFO
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Simple Multi-Webhook Wrapper
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
## Custom Exceptions
|
|
6
|
+
|
|
7
|
+
The module imports custom exceptions from an external `exceptions` file:
|
|
8
|
+
|
|
9
|
+
- **`InvalidURL`**: Raised if the URL string is empty or missing.
|
|
10
|
+
- **`AlreadyExists`**: Raised if you try to register a URL on an ID that is already taken.
|
|
11
|
+
- **`NoSuchID`**: Raised if you try to send a message using an uninitialized ID.
|
|
12
|
+
- **`ContentTooLarge`**: Raised if the text payload exceeds the 2000-character limit.
|
|
13
|
+
- **`ConnectionError`**: Network issues or host is completely unreachable.
|
|
14
|
+
- **`SchemaError`**: Raised when the URL format misses `http://` or `https://`.
|
|
15
|
+
- **`BadRequest`**: Server returned an explicit HTTP `400` error.
|
|
16
|
+
- **`InternalServerError`**: Server encountered a critical HTTP `500` error.
|
|
17
|
+
- **`HTTPError`**: Triggers for any other non-2xx server responses.
|
|
18
|
+
|
|
19
|
+
## Core Functions
|
|
20
|
+
|
|
21
|
+
### `init(url: str, id=1)`
|
|
22
|
+
Registers a webhook URL under a unique identifier.
|
|
23
|
+
- **Default ID:** `1`
|
|
24
|
+
- **Raises:** `InvalidURL` if the URL is empty, `AlreadyExists` if the ID is already registered.
|
|
25
|
+
|
|
26
|
+
### `send(content: str, ids, statCode: bool = False, flush: bool = False)`
|
|
27
|
+
Dispatches a payload string to the webhook registered under the specified `ids`.
|
|
28
|
+
- **`ids`**: The target webhook identifier.
|
|
29
|
+
- **`statCode`**: If set to `True`, prints the server response status code in the console.
|
|
30
|
+
- **`flush`**: If set to `True`, prints the raw text/JSON response returned from the server endpoint.
|
|
31
|
+
|
|
32
|
+
## Usage Example
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
import dswebhook as dsw
|
|
36
|
+
|
|
37
|
+
# 1. Initialize dswebhook with ID
|
|
38
|
+
|
|
39
|
+
dsw.init("https://discord.com...", id=1)dsw.init("https://discord.com...", "id="backup_channel")
|
|
40
|
+
|
|
41
|
+
# 2. Send logs with debugging features enabled
|
|
42
|
+
try:
|
|
43
|
+
# Sends a message and prints out status code and server raw response text
|
|
44
|
+
dsw.send("System updated successfully!", ids=1, statCode=True, flush=True)
|
|
45
|
+
|
|
46
|
+
# Sends a message to the second text channel using a string ID
|
|
47
|
+
dsw.send("Alert triggered.", ids="backup_channel")
|
|
48
|
+
|
|
49
|
+
except dsw.AlreadyExists as e:
|
|
50
|
+
print(f"Configuration conflict: {e}")
|
|
51
|
+
except dsw.NoSuchID as e:
|
|
52
|
+
print(f"Targeting error: {e}")
|
|
53
|
+
except dsw.HTTPError as e:
|
|
54
|
+
print(f"Server communication failed: {e}")
|
|
55
|
+
```
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dswebhook"
|
|
7
|
+
version = "0.2.2"
|
|
8
|
+
description = "Lib for easy use of discord webhook"
|
|
9
|
+
requires-python = ">=3.8"
|
|
10
|
+
authors = [
|
|
11
|
+
{ name = "Beks1k"}
|
|
12
|
+
]
|
|
13
|
+
dependencies = [
|
|
14
|
+
"requests>=2.28.0",
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
[tool.setuptools]
|
|
18
|
+
# Указываем setuptools искать пакеты строго внутри директории src
|
|
19
|
+
package-dir = {"" = "src"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
|
|
3
|
+
from exceptions import (
|
|
4
|
+
InvalidURL, SchemaError, AlreadyExists, NoSuchID,
|
|
5
|
+
ContentTooLarge, ConnectionError, BadRequest, InternalServerError, HTTPError
|
|
6
|
+
)
|
|
7
|
+
urlr = {}
|
|
8
|
+
|
|
9
|
+
def init(url:str, id=1):
|
|
10
|
+
'''specify webhook url and id (Deafult 1)'''
|
|
11
|
+
global urlr
|
|
12
|
+
if not url:
|
|
13
|
+
raise InvalidURL(f"MUST BE VALID URL FOR ID {id}")
|
|
14
|
+
if id in urlr:
|
|
15
|
+
raise AlreadyExists(f"{id} ALREADY EXSISTS")
|
|
16
|
+
urlr[id] = url
|
|
17
|
+
|
|
18
|
+
def send(content:str, ids, statCode:bool=False, flush:bool = False):
|
|
19
|
+
'''Send content to specified webhook'''
|
|
20
|
+
global urlr
|
|
21
|
+
if not urlr:
|
|
22
|
+
raise InvalidURL("FIRST SPECIFY URL USING init(url, id) MODULE")
|
|
23
|
+
if len(content) > 2000:
|
|
24
|
+
raise ContentTooLarge(f"TOO LARGE CONTENT FOR {ids}")
|
|
25
|
+
data = {
|
|
26
|
+
"content":content
|
|
27
|
+
}
|
|
28
|
+
if urlr.get(ids) == None:
|
|
29
|
+
raise NoSuchID(f"NOT FOUND {ids}")
|
|
30
|
+
try:
|
|
31
|
+
a = requests.post(urlr.get(ids), json=data)
|
|
32
|
+
except requests.exceptions.ConnectionError:
|
|
33
|
+
raise ConnectionError(f"CONNECTION ERROR FOR {ids} PLEASE CHECK CONNETCTION AND URL FOR ANY ERRORS")
|
|
34
|
+
except requests.exceptions.MissingSchema:
|
|
35
|
+
raise SchemaError(f"MUST BE WITH https:// OR http:// IF HTTPS NOT SUPPORTED FOR {ids}")
|
|
36
|
+
|
|
37
|
+
if a.status_code == 400:
|
|
38
|
+
raise BadRequest(f"BAD REQUEST (HTTP ERROR: 400) FOR {ids}")
|
|
39
|
+
|
|
40
|
+
if a.status_code == 500:
|
|
41
|
+
raise InternalServerError(f"INTERNAL SERVER ERROR (HTTP ERROR: 500) FOR {ids}")
|
|
42
|
+
|
|
43
|
+
if not a.ok:
|
|
44
|
+
raise HTTPError(f"SERVER RETURNED NOT 2xx RESPONSE {a.status_code} FOR {ids}")
|
|
45
|
+
|
|
46
|
+
if statCode:
|
|
47
|
+
print(a.status_code, f"FOR {ids}")
|
|
48
|
+
|
|
49
|
+
if flush:
|
|
50
|
+
if a.text == "":
|
|
51
|
+
print(f"NOTHING FROM SERVER FOR {ids}")
|
|
52
|
+
else:
|
|
53
|
+
print(a.text, f"FOR {ids}")
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/exceptions.py
|
|
5
|
+
src/dswebhook/__init__.py
|
|
6
|
+
src/dswebhook/dswebhook.py
|
|
7
|
+
src/dswebhook.egg-info/PKG-INFO
|
|
8
|
+
src/dswebhook.egg-info/SOURCES.txt
|
|
9
|
+
src/dswebhook.egg-info/dependency_links.txt
|
|
10
|
+
src/dswebhook.egg-info/requires.txt
|
|
11
|
+
src/dswebhook.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
requests>=2.28.0
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
class BadRequest(Exception):
|
|
2
|
+
'''When 400 hits in'''
|
|
3
|
+
pass
|
|
4
|
+
|
|
5
|
+
class InternalServerError(Exception):
|
|
6
|
+
'''When 500 hits in'''
|
|
7
|
+
pass
|
|
8
|
+
|
|
9
|
+
class InvalidURL(Exception):
|
|
10
|
+
'''When Invalid url is given'''
|
|
11
|
+
pass
|
|
12
|
+
|
|
13
|
+
class ContentTooLarge(Exception):
|
|
14
|
+
'''When Given content bigger than 2000'''
|
|
15
|
+
pass
|
|
16
|
+
|
|
17
|
+
class ConnectionError(Exception):
|
|
18
|
+
'''When Connection error accures such as no inter net etc.'''
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
class SchemaError(Exception):
|
|
22
|
+
'''When schema not right'''
|
|
23
|
+
pass
|
|
24
|
+
|
|
25
|
+
class NoSuchID(Exception):
|
|
26
|
+
'''When id is not found in urlr'''
|
|
27
|
+
pass
|
|
28
|
+
|
|
29
|
+
class AlreadyExists(Exception):
|
|
30
|
+
'''When id is already exists in urlr'''
|
|
31
|
+
pass
|
|
32
|
+
|
|
33
|
+
class HTTPError(Exception):
|
|
34
|
+
'''When other HTTP error accures'''
|
|
35
|
+
pass
|