dswebhook 0.2.3__tar.gz → 0.2.5__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dswebhook
3
- Version: 0.2.3
3
+ Version: 0.2.5
4
4
  Summary: Lib for easy use of discord webhook
5
5
  Author: Beks1k
6
6
  Requires-Python: >=3.8
@@ -13,9 +13,8 @@ Dynamic: license-file
13
13
 
14
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
15
 
16
- ## Custom Exceptions
16
+ ## Exceptions
17
17
 
18
- The module imports custom exceptions from an external `exceptions` file:
19
18
 
20
19
  - **`InvalidURL`**: Raised if the URL string is empty or missing.
21
20
  - **`AlreadyExists`**: Raised if you try to register a URL on an ID that is already taken.
@@ -26,6 +25,7 @@ The module imports custom exceptions from an external `exceptions` file:
26
25
  - **`BadRequest`**: Server returned an explicit HTTP `400` error.
27
26
  - **`InternalServerError`**: Server encountered a critical HTTP `500` error.
28
27
  - **`HTTPError`**: Triggers for any other non-2xx server responses.
28
+ - **`NotJSON`**: Triggers if given value isnt JSON
29
29
 
30
30
  ## Core Functions
31
31
 
@@ -39,6 +39,7 @@ Dispatches a payload string to the webhook registered under the specified `ids`.
39
39
  - **`ids`**: The target webhook identifier.
40
40
  - **`statCode`**: If set to `True`, prints the server response status code in the console.
41
41
  - **`flush`**: If set to `True`, prints the raw text/JSON response returned from the server endpoint.
42
+ - **`customJSON`**: Must be a variable dictionary, sends custom JSON request for custom url
42
43
 
43
44
  ## Usage Example
44
45
 
@@ -47,7 +48,8 @@ import dswebhook as dsw
47
48
 
48
49
  # 1. Initialize dswebhook with ID
49
50
 
50
- dsw.init("https://discord.com...", id=1)dsw.init("https://discord.com...", "id="backup_channel")
51
+ dsw.init("https://discord.com...", id=1)
52
+ dsw.init("https://discord.com...", id="backup_channel")
51
53
 
52
54
  # 2. Send logs with debugging features enabled
53
55
  try:
@@ -64,3 +66,35 @@ except dsw.NoSuchID as e:
64
66
  except dsw.HTTPError as e:
65
67
  print(f"Server communication failed: {e}")
66
68
  ```
69
+
70
+ ### Usage example for custom JSON request
71
+
72
+ ```python
73
+ import dswebhook as dsw
74
+
75
+ # 1. Initialize dswebhook with ID
76
+
77
+ customData = {
78
+ "auth":"User"
79
+ "token":"token"
80
+ ...
81
+ }
82
+
83
+ dsw.init("https://your-custom-URL...", id=1)
84
+ dsw.init("https://your-custom-URL...", id="backup_channel")
85
+
86
+ # 2. Send logs with debugging features enabled
87
+ try:
88
+ # Sends a message with custom JSON and prints out status code and server raw response text
89
+ dsw.send("System updated successfully!", ids=1, statCode=True, flush=True, customJSON=customData )
90
+
91
+ # Sends a message to the second text channel using a string ID
92
+ dsw.send("Alert triggered.", ids="backup_channel")
93
+
94
+ except dsw.AlreadyExists as e:
95
+ print(f"Configuration conflict: {e}")
96
+ except dsw.NoSuchID as e:
97
+ print(f"Targeting error: {e}")
98
+ except dsw.HTTPError as e:
99
+ print(f"Server communication failed: {e}")
100
+ ```
@@ -2,9 +2,8 @@
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
- ## Custom Exceptions
5
+ ## Exceptions
6
6
 
7
- The module imports custom exceptions from an external `exceptions` file:
8
7
 
9
8
  - **`InvalidURL`**: Raised if the URL string is empty or missing.
10
9
  - **`AlreadyExists`**: Raised if you try to register a URL on an ID that is already taken.
@@ -15,6 +14,7 @@ The module imports custom exceptions from an external `exceptions` file:
15
14
  - **`BadRequest`**: Server returned an explicit HTTP `400` error.
16
15
  - **`InternalServerError`**: Server encountered a critical HTTP `500` error.
17
16
  - **`HTTPError`**: Triggers for any other non-2xx server responses.
17
+ - **`NotJSON`**: Triggers if given value isnt JSON
18
18
 
19
19
  ## Core Functions
20
20
 
@@ -28,6 +28,7 @@ Dispatches a payload string to the webhook registered under the specified `ids`.
28
28
  - **`ids`**: The target webhook identifier.
29
29
  - **`statCode`**: If set to `True`, prints the server response status code in the console.
30
30
  - **`flush`**: If set to `True`, prints the raw text/JSON response returned from the server endpoint.
31
+ - **`customJSON`**: Must be a variable dictionary, sends custom JSON request for custom url
31
32
 
32
33
  ## Usage Example
33
34
 
@@ -36,7 +37,8 @@ import dswebhook as dsw
36
37
 
37
38
  # 1. Initialize dswebhook with ID
38
39
 
39
- dsw.init("https://discord.com...", id=1)dsw.init("https://discord.com...", "id="backup_channel")
40
+ dsw.init("https://discord.com...", id=1)
41
+ dsw.init("https://discord.com...", id="backup_channel")
40
42
 
41
43
  # 2. Send logs with debugging features enabled
42
44
  try:
@@ -53,3 +55,35 @@ except dsw.NoSuchID as e:
53
55
  except dsw.HTTPError as e:
54
56
  print(f"Server communication failed: {e}")
55
57
  ```
58
+
59
+ ### Usage example for custom JSON request
60
+
61
+ ```python
62
+ import dswebhook as dsw
63
+
64
+ # 1. Initialize dswebhook with ID
65
+
66
+ customData = {
67
+ "auth":"User"
68
+ "token":"token"
69
+ ...
70
+ }
71
+
72
+ dsw.init("https://your-custom-URL...", id=1)
73
+ dsw.init("https://your-custom-URL...", id="backup_channel")
74
+
75
+ # 2. Send logs with debugging features enabled
76
+ try:
77
+ # Sends a message with custom JSON and prints out status code and server raw response text
78
+ dsw.send("System updated successfully!", ids=1, statCode=True, flush=True, customJSON=customData )
79
+
80
+ # Sends a message to the second text channel using a string ID
81
+ dsw.send("Alert triggered.", ids="backup_channel")
82
+
83
+ except dsw.AlreadyExists as e:
84
+ print(f"Configuration conflict: {e}")
85
+ except dsw.NoSuchID as e:
86
+ print(f"Targeting error: {e}")
87
+ except dsw.HTTPError as e:
88
+ print(f"Server communication failed: {e}")
89
+ ```
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "dswebhook"
7
- version = "0.2.3"
7
+ version = "0.2.5"
8
8
  readme = "README.md"
9
9
  description = "Lib for easy use of discord webhook"
10
10
  requires-python = ">=3.8"
@@ -1,9 +1,45 @@
1
1
  import requests
2
2
 
3
- from exceptions import (
4
- InvalidURL, SchemaError, AlreadyExists, NoSuchID,
5
- ContentTooLarge, ConnectionError, BadRequest, InternalServerError, HTTPError
6
- )
3
+ class BadRequest(Exception):
4
+ '''When 400 hits in'''
5
+ pass
6
+
7
+ class InternalServerError(Exception):
8
+ '''When 500 hits in'''
9
+ pass
10
+
11
+ class InvalidURL(Exception):
12
+ '''When Invalid url is given'''
13
+ pass
14
+
15
+ class ContentTooLarge(Exception):
16
+ '''When Given content bigger than 2000'''
17
+ pass
18
+
19
+ class ConnectionError(Exception):
20
+ '''When Connection error accures such as no inter net etc.'''
21
+ pass
22
+
23
+ class SchemaError(Exception):
24
+ '''When schema not right'''
25
+ pass
26
+
27
+ class NoSuchID(Exception):
28
+ '''When id is not found in urlr'''
29
+ pass
30
+
31
+ class AlreadyExists(Exception):
32
+ '''When id is already exists in urlr'''
33
+ pass
34
+
35
+ class HTTPError(Exception):
36
+ '''When other HTTP error accures'''
37
+ pass
38
+
39
+ class NotJSON(Exception):
40
+ '''If customJSON is not a dictionary'''
41
+ pass
42
+
7
43
  urlr = {}
8
44
 
9
45
  def init(url:str, id=1):
@@ -25,6 +61,8 @@ def send(content:str, ids, statCode:bool=False, flush:bool = False, customJSON =
25
61
  data = {
26
62
  "content":content
27
63
  }
64
+ if not isinstance(customJSON, dict):
65
+ raise NotJSON("customJSON PARAMETR IS NOT DICTIONARY. FOR id{ids}")
28
66
  if customJSON:
29
67
  data = customJSON
30
68
  if urlr.get(ids) == None:
@@ -32,18 +70,18 @@ def send(content:str, ids, statCode:bool=False, flush:bool = False, customJSON =
32
70
  try:
33
71
  a = requests.post(urlr.get(ids), json=data)
34
72
  except requests.exceptions.ConnectionError:
35
- raise ConnectionError(f"CONNECTION ERROR FOR {ids} PLEASE CHECK CONNETCTION AND URL FOR ANY ERRORS")
73
+ raise ConnectionError(f"CONNECTION ERROR FOR id={ids}. PLEASE CHECK CONNETCTION AND URL FOR ANY ERRORS")
36
74
  except requests.exceptions.MissingSchema:
37
- raise SchemaError(f"MUST BE WITH https:// OR http:// IF HTTPS NOT SUPPORTED FOR {ids}")
75
+ raise SchemaError(f"MUST BE WITH https:// OR http:// IF HTTPS NOT SUPPORTED. FOR id={ids}")
38
76
 
39
77
  if a.status_code == 400:
40
- raise BadRequest(f"BAD REQUEST (HTTP ERROR: 400) FOR {ids}")
78
+ raise BadRequest(f"BAD REQUEST (HTTP ERROR: 400). FOR id{ids}")
41
79
 
42
80
  if a.status_code == 500:
43
- raise InternalServerError(f"INTERNAL SERVER ERROR (HTTP ERROR: 500) FOR {ids}")
81
+ raise InternalServerError(f"INTERNAL SERVER ERROR (HTTP ERROR: 500). FOR id={ids}")
44
82
 
45
83
  if not a.ok:
46
- raise HTTPError(f"SERVER RETURNED NOT 2xx RESPONSE {a.status_code} FOR {ids}")
84
+ raise HTTPError(f"SERVER RETURNED NOT 2xx RESPONSE {a.status_code}. FOR id={ids}")
47
85
 
48
86
  if statCode:
49
87
  print(a.status_code, f"FOR {ids}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dswebhook
3
- Version: 0.2.3
3
+ Version: 0.2.5
4
4
  Summary: Lib for easy use of discord webhook
5
5
  Author: Beks1k
6
6
  Requires-Python: >=3.8
@@ -13,9 +13,8 @@ Dynamic: license-file
13
13
 
14
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
15
 
16
- ## Custom Exceptions
16
+ ## Exceptions
17
17
 
18
- The module imports custom exceptions from an external `exceptions` file:
19
18
 
20
19
  - **`InvalidURL`**: Raised if the URL string is empty or missing.
21
20
  - **`AlreadyExists`**: Raised if you try to register a URL on an ID that is already taken.
@@ -26,6 +25,7 @@ The module imports custom exceptions from an external `exceptions` file:
26
25
  - **`BadRequest`**: Server returned an explicit HTTP `400` error.
27
26
  - **`InternalServerError`**: Server encountered a critical HTTP `500` error.
28
27
  - **`HTTPError`**: Triggers for any other non-2xx server responses.
28
+ - **`NotJSON`**: Triggers if given value isnt JSON
29
29
 
30
30
  ## Core Functions
31
31
 
@@ -39,6 +39,7 @@ Dispatches a payload string to the webhook registered under the specified `ids`.
39
39
  - **`ids`**: The target webhook identifier.
40
40
  - **`statCode`**: If set to `True`, prints the server response status code in the console.
41
41
  - **`flush`**: If set to `True`, prints the raw text/JSON response returned from the server endpoint.
42
+ - **`customJSON`**: Must be a variable dictionary, sends custom JSON request for custom url
42
43
 
43
44
  ## Usage Example
44
45
 
@@ -47,7 +48,8 @@ import dswebhook as dsw
47
48
 
48
49
  # 1. Initialize dswebhook with ID
49
50
 
50
- dsw.init("https://discord.com...", id=1)dsw.init("https://discord.com...", "id="backup_channel")
51
+ dsw.init("https://discord.com...", id=1)
52
+ dsw.init("https://discord.com...", id="backup_channel")
51
53
 
52
54
  # 2. Send logs with debugging features enabled
53
55
  try:
@@ -64,3 +66,35 @@ except dsw.NoSuchID as e:
64
66
  except dsw.HTTPError as e:
65
67
  print(f"Server communication failed: {e}")
66
68
  ```
69
+
70
+ ### Usage example for custom JSON request
71
+
72
+ ```python
73
+ import dswebhook as dsw
74
+
75
+ # 1. Initialize dswebhook with ID
76
+
77
+ customData = {
78
+ "auth":"User"
79
+ "token":"token"
80
+ ...
81
+ }
82
+
83
+ dsw.init("https://your-custom-URL...", id=1)
84
+ dsw.init("https://your-custom-URL...", id="backup_channel")
85
+
86
+ # 2. Send logs with debugging features enabled
87
+ try:
88
+ # Sends a message with custom JSON and prints out status code and server raw response text
89
+ dsw.send("System updated successfully!", ids=1, statCode=True, flush=True, customJSON=customData )
90
+
91
+ # Sends a message to the second text channel using a string ID
92
+ dsw.send("Alert triggered.", ids="backup_channel")
93
+
94
+ except dsw.AlreadyExists as e:
95
+ print(f"Configuration conflict: {e}")
96
+ except dsw.NoSuchID as e:
97
+ print(f"Targeting error: {e}")
98
+ except dsw.HTTPError as e:
99
+ print(f"Server communication failed: {e}")
100
+ ```
@@ -1,7 +1,6 @@
1
1
  LICENSE
2
2
  README.md
3
3
  pyproject.toml
4
- src/exceptions.py
5
4
  src/dswebhook/__init__.py
6
5
  src/dswebhook/dswebhook.py
7
6
  src/dswebhook.egg-info/PKG-INFO
@@ -0,0 +1 @@
1
+ dswebhook
@@ -1,2 +0,0 @@
1
- dswebhook
2
- exceptions
@@ -1,35 +0,0 @@
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
File without changes
File without changes