Skip to content

Commit cb875a3

Browse files
committed
V0.1.6
1 parent 892405e commit cb875a3

File tree

7 files changed

+32
-75
lines changed

7 files changed

+32
-75
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ docs/*
77
setup.py
88
test.py
99
CallbackObject.py
10+
unrealircd_rpc_py/Definition.py
1011
*.zip

README.MD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,6 @@ This package allows easy interfacing with UnrealIRCd through regular Python3 cod
167167
Stats = rpc.Stats
168168
User = rpc.User
169169
Whowas = rpc.Whowas
170+
Log = rpc.Log # This feature requires unrealIRCd 6.1.8 or higher
170171

171172
```

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='unrealircd_rpc_py',
5-
version='0.1.5',
5+
version='0.1.6',
66
packages=find_packages(),
77
install_requires=[
88
"requests>=2.25.1"

unrealircd_rpc_py/Connection.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Connection:
1010

1111
@dataclass
1212
class ErrorModel:
13+
"""This model will contain the error if any"""
1314
code: int
1415
message: str
1516

@@ -19,6 +20,7 @@ def __init__(self, req_method:str, url: str, path_to_socket_file: str, username:
1920
self.Logs: logging
2021
self.__init_log_system()
2122
self.Error = self.ErrorModel(0, '')
23+
"""This model will contain the error if any"""
2224

2325
self.url = url
2426
self.path_to_socket_file = path_to_socket_file

unrealircd_rpc_py/Loader.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,7 @@ def __init__(self, req_method: Literal['requests', 'socket', 'unixsocket'], url:
100100
# Create Whowas Instance
101101
self.Whowas = Whowas(self.Connection)
102102
"""The Whowas module instance"""
103+
104+
# Create Log Instance
105+
self.Log = Log(self.Connection)
106+
"""This include mainly send method requires unrealIRCd 6.1.8 or higher"""

unrealircd_rpc_py/Log.py

Lines changed: 22 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
from types import SimpleNamespace
2-
from typing import Union
3-
from dataclasses import dataclass
2+
from typing import Union, Literal
3+
from time import time
44
from unrealircd_rpc_py.Connection import Connection
5+
# import Definition
56

67
class Log:
78

8-
@dataclass
9-
class ModelLog:
10-
type: str
11-
type_string: str
12-
set_by: str
13-
set_at: str
14-
expire_at: str
15-
set_at_string: str
16-
expire_at_string: str
17-
duration_string: str
18-
set_at_delta: int
19-
set_in_config: bool
20-
name: str
21-
reason: str
22-
23-
DB_NAME_BANS: list[ModelLog] = []
9+
# DB_LOG_CONNECT: list[Definition.LogConnect]
2410

2511
def __init__(self, Connection: Connection) -> None:
2612

@@ -68,80 +54,43 @@ def list_(self, sources: list = None) -> Union[SimpleNamespace, None]:
6854
except Exception as err:
6955
self.Logs.error(f'General error: {err}')
7056

71-
def subscribe(self, sources: list) -> bool:
72-
"""Subscribe to one or more log sources. Any previous subscriptions are overwritten (lost).
57+
def send(self, msg: str, level: Literal['debug','info','warn','error','fatal'], subsystem: str, event_id: str, timestamp: float = time()) -> bool:
58+
""" Send a log message / server notice.
7359
74-
Args:
75-
sources (list): an array of log sources. See log block sources.
76-
For example ["!debug","all"] would give you all log messages except for debug messages. And ["connect"] would give only client connects/disconnects.
77-
78-
Returns:
79-
bool: True if success
80-
"""
81-
try:
82-
response = self.Connection.query(
83-
method='log.subscribe',
84-
param={"sources": sources}
85-
)
60+
Requires UnrealIRCd 6.1.8 or later
8661
87-
self.response_raw = response
88-
self.response_np = self.Connection.json_response_np
89-
90-
if response is None:
91-
return False
92-
93-
if 'error' in response:
94-
self.Connection.set_error(response)
95-
return False
96-
97-
if 'result' in response:
98-
if response['result']:
99-
self.Logs.debug(response)
100-
return True
101-
else:
102-
self.Logs.debug(response)
103-
return False
104-
105-
return True
106-
107-
except KeyError as ke:
108-
self.Logs.error(f'KeyError: {ke}')
109-
except Exception as err:
110-
self.Logs.error(f'General error: {err}')
111-
112-
def unsubscribe(self) -> bool:
113-
"""Unsubscribe from all log events.
114-
After this UnrealIRCd will stop streaming log events to you.
62+
Args:
63+
msg (str): The message you want to send to the server
64+
level (Literal['debug','info','warn','error','fatal']): You can pick the level in the list
65+
subsystem (str): You can put anything you want as a subsystem
66+
event_id (str): You can put anything you want as a event_id
67+
timestamp (float, optional): The current timestamp. Defaults to time().
11568
11669
Returns:
117-
bool: Always returns true
70+
bool: True if is okey, else if there is an error
11871
"""
72+
# waiting for the documentation.
11973
try:
12074
response = self.Connection.query(
121-
method='log.unsubscribe'
122-
)
75+
method='log.send',
76+
param={"msg": msg, "level": level, "subsystem": subsystem, "event_id": event_id, "timestamp": timestamp}
77+
)
12378

12479
self.response_raw = response
12580
self.response_np = self.Connection.json_response_np
12681

127-
if response is None:
128-
return False
129-
13082
if 'error' in response:
83+
self.Logs.error(response["error"])
13184
self.Connection.set_error(response)
13285
return False
13386

134-
if 'result' in response:
135-
if response['result']:
136-
self.Logs.debug(response)
137-
return True
138-
else:
139-
self.Logs.debug(response)
140-
return False
87+
self.Logs.debug(response)
14188

14289
return True
14390

14491
except KeyError as ke:
14592
self.Logs.error(f'KeyError: {ke}')
93+
return False
14694
except Exception as err:
14795
self.Logs.error(f'General error: {err}')
96+
return False

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"version": "0.1.5"
2+
"version": "0.1.6"
33
}

0 commit comments

Comments
 (0)