Skip to content

Commit 3b7c9b7

Browse files
authored
Merge pull request #14 from adator85/dev
Dev
2 parents b9888b7 + 0f826dc commit 3b7c9b7

File tree

16 files changed

+42
-75
lines changed

16 files changed

+42
-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.7',
66
packages=find_packages(),
77
install_requires=[
88
"requests>=2.25.1"

unrealircd_rpc_py/Channel.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def list_(self, _object_detail_level: int = 1) -> Union[list[ModelChannel], None
5050
ModelChannel: List of ModelChannel, None if nothing see the Error property
5151
"""
5252
try:
53+
self.DB_CHANNELS = []
5354
response = self.Connection.query(method='channel.list', param={'object_detail_level': _object_detail_level})
5455

5556
self.response_raw = response

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

unrealircd_rpc_py/Name_ban.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def list_(self) -> Union[list[ModelNameBan], None]:
4343
ModelNameBan: List of ModelNameBan, None if nothing see Error property
4444
"""
4545
try:
46+
self.DB_NAME_BANS = []
4647
response = self.Connection.query(method='name_ban.list')
4748

4849
self.response_raw = response

unrealircd_rpc_py/Rpc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def info(self) -> Union[list[ModelRpcInfo], None]:
3535
list[ModelRpcInfo]: List of ModelRpcInfo, None if nothing see the Error property
3636
"""
3737
try:
38+
self.DB_RPC_INFO = []
3839
response = self.Connection.query(method='rpc.info')
3940

4041
self.response_raw = response

unrealircd_rpc_py/Server.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def list_(self) -> Union[list[ModelServer], None]:
8080
list[ModelServer]: List with an object contains all Servers information
8181
"""
8282
try:
83+
self.DB_SERVER = []
8384
response = self.Connection.query('server.list')
8485

8586
self.response_raw = response
@@ -329,6 +330,7 @@ def module_list(self, _serverorsid: str = None) -> Union[list[ModelModules], Non
329330
bool: if False means that we have an error
330331
"""
331332
try:
333+
self.DB_MODULES = []
332334
response = self.Connection.query('server.module_list', {'server': _serverorsid})
333335

334336
self.response_raw = response

0 commit comments

Comments
 (0)