dswebhook 0.2.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dswebhook
3
- Version: 0.2.3
3
+ Version: 0.2.4
4
4
  Summary: Lib for easy use of discord webhook
5
5
  Author: Beks1k
6
6
  Requires-Python: >=3.8
@@ -13,9 +13,9 @@ 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:
18
+ The module imports exceptions from an external `exceptions` file:
19
19
 
20
20
  - **`InvalidURL`**: Raised if the URL string is empty or missing.
21
21
  - **`AlreadyExists`**: Raised if you try to register a URL on an ID that is already taken.
@@ -26,6 +26,7 @@ The module imports custom exceptions from an external `exceptions` file:
26
26
  - **`BadRequest`**: Server returned an explicit HTTP `400` error.
27
27
  - **`InternalServerError`**: Server encountered a critical HTTP `500` error.
28
28
  - **`HTTPError`**: Triggers for any other non-2xx server responses.
29
+ - **`NotJSON`**: Triggers if given value isnt JSON
29
30
 
30
31
  ## Core Functions
31
32
 
@@ -39,6 +40,7 @@ Dispatches a payload string to the webhook registered under the specified `ids`.
39
40
  - **`ids`**: The target webhook identifier.
40
41
  - **`statCode`**: If set to `True`, prints the server response status code in the console.
41
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
42
44
 
43
45
  ## Usage Example
44
46
 
@@ -47,7 +49,8 @@ import dswebhook as dsw
47
49
 
48
50
  # 1. Initialize dswebhook with ID
49
51
 
50
- dsw.init("https://discord.com...", id=1)dsw.init("https://discord.com...", "id="backup_channel")
52
+ dsw.init("https://discord.com...", id=1)
53
+ dsw.init("https://discord.com...", id="backup_channel")
51
54
 
52
55
  # 2. Send logs with debugging features enabled
53
56
  try:
@@ -64,3 +67,35 @@ except dsw.NoSuchID as e:
64
67
  except dsw.HTTPError as e:
65
68
  print(f"Server communication failed: {e}")
66
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
- ## Custom Exceptions
5
+ ## Exceptions
6
6
 
7
- The module imports custom exceptions from an external `exceptions` file:
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)dsw.init("https://discord.com...", "id="backup_channel")
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
+ ```
@@ -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.4"
8
8
  readme = "README.md"
9
9
  description = "Lib for easy use of discord webhook"
10
10
  requires-python = ">=3.8"
@@ -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
 
@@ -25,6 +25,8 @@ def send(content:str, ids, statCode:bool=False, flush:bool = False, customJSON =
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}")
28
30
  if customJSON:
29
31
  data = customJSON
30
32
  if urlr.get(ids) == None:
@@ -32,18 +34,18 @@ def send(content:str, ids, statCode:bool=False, flush:bool = False, customJSON =
32
34
  try:
33
35
  a = requests.post(urlr.get(ids), json=data)
34
36
  except requests.exceptions.ConnectionError:
35
- 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")
36
38
  except requests.exceptions.MissingSchema:
37
- 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}")
38
40
 
39
41
  if a.status_code == 400:
40
- raise BadRequest(f"BAD REQUEST (HTTP ERROR: 400) FOR {ids}")
42
+ raise BadRequest(f"BAD REQUEST (HTTP ERROR: 400). FOR id{ids}")
41
43
 
42
44
  if a.status_code == 500:
43
- raise InternalServerError(f"INTERNAL SERVER ERROR (HTTP ERROR: 500) FOR {ids}")
45
+ raise InternalServerError(f"INTERNAL SERVER ERROR (HTTP ERROR: 500). FOR id={ids}")
44
46
 
45
47
  if not a.ok:
46
- 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}")
47
49
 
48
50
  if statCode:
49
51
  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.4
4
4
  Summary: Lib for easy use of discord webhook
5
5
  Author: Beks1k
6
6
  Requires-Python: >=3.8
@@ -13,9 +13,9 @@ 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:
18
+ The module imports exceptions from an external `exceptions` file:
19
19
 
20
20
  - **`InvalidURL`**: Raised if the URL string is empty or missing.
21
21
  - **`AlreadyExists`**: Raised if you try to register a URL on an ID that is already taken.
@@ -26,6 +26,7 @@ The module imports custom exceptions from an external `exceptions` file:
26
26
  - **`BadRequest`**: Server returned an explicit HTTP `400` error.
27
27
  - **`InternalServerError`**: Server encountered a critical HTTP `500` error.
28
28
  - **`HTTPError`**: Triggers for any other non-2xx server responses.
29
+ - **`NotJSON`**: Triggers if given value isnt JSON
29
30
 
30
31
  ## Core Functions
31
32
 
@@ -39,6 +40,7 @@ Dispatches a payload string to the webhook registered under the specified `ids`.
39
40
  - **`ids`**: The target webhook identifier.
40
41
  - **`statCode`**: If set to `True`, prints the server response status code in the console.
41
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
42
44
 
43
45
  ## Usage Example
44
46
 
@@ -47,7 +49,8 @@ import dswebhook as dsw
47
49
 
48
50
  # 1. Initialize dswebhook with ID
49
51
 
50
- dsw.init("https://discord.com...", id=1)dsw.init("https://discord.com...", "id="backup_channel")
52
+ dsw.init("https://discord.com...", id=1)
53
+ dsw.init("https://discord.com...", id="backup_channel")
51
54
 
52
55
  # 2. Send logs with debugging features enabled
53
56
  try:
@@ -64,3 +67,35 @@ except dsw.NoSuchID as e:
64
67
  except dsw.HTTPError as e:
65
68
  print(f"Server communication failed: {e}")
66
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
+ ```
@@ -32,4 +32,8 @@ class AlreadyExists(Exception):
32
32
 
33
33
  class HTTPError(Exception):
34
34
  '''When other HTTP error accures'''
35
+ pass
36
+
37
+ class NotJSON(Exception):
38
+ '''If customJSON is not a dictionary'''
35
39
  pass
File without changes
File without changes