11from types import SimpleNamespace
2- from typing import Union
3- from dataclasses import dataclass
2+ from typing import Union , Literal
3+ from time import time
44from unrealircd_rpc_py .Connection import Connection
5+ # import Definition
56
67class 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
0 commit comments