Skip to content

Commit 096920a

Browse files
authored
Merge pull request #19 from adator85/V1.x.x
Adding Whowas model in the Definition class
2 parents 3d5fe23 + a2ff8f5 commit 096920a

File tree

7 files changed

+53
-51
lines changed

7 files changed

+53
-51
lines changed
34.7 KB
Binary file not shown.

dist/unrealircd_rpc_py-1.0.6.tar.gz

24.4 KB
Binary file not shown.

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

unrealircd_rpc_py/Definition.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ class RpcInfo:
352352
version: str = None
353353

354354
#################
355-
# Stats Class #
355+
# Stats Class #
356356
#################
357357

358358
@dataclass
@@ -415,4 +415,34 @@ class Stats:
415415
server: StatsServer = field(default_factory=StatsServer)
416416
user: StatsUser = field(default_factory=StatsUser)
417417
channel: StatsChannel = field(default_factory=StatsChannel)
418-
server_ban: StatsServerBan = field(default_factory=StatsServerBan)
418+
server_ban: StatsServerBan = field(default_factory=StatsServerBan)
419+
420+
##################
421+
# Whowas Class #
422+
##################
423+
424+
@dataclass
425+
class WhowasUser:
426+
username: str = None
427+
realname: str = None
428+
vhost: str = None
429+
servername: str = None
430+
431+
@dataclass
432+
class Whowas:
433+
"""Whowas Class
434+
435+
Depends on:
436+
```
437+
1- WhowasUser
438+
```
439+
"""
440+
name: str = None
441+
event: str = None
442+
logon_time: str = None
443+
logoff_time: str = None
444+
hostname: str = None
445+
ip: str = None
446+
details: str = None
447+
connected_since: str = None
448+
user: WhowasUser = field(default_factory=WhowasUser)

unrealircd_rpc_py/User.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ def join(self, nickoruid: str, channel:str, key: str = '', force: bool = False)
432432

433433
if 'error' in response:
434434
self.Logs.error(response['error']['message'])
435-
self.Connection.set_error(**response["error"])
435+
self.Connection.EngineError.set_error(**response["error"])
436436
return False
437437

438438
return True

unrealircd_rpc_py/Whowas.py

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,10 @@
11
from types import SimpleNamespace
2-
from typing import Union
3-
from dataclasses import dataclass
42
from unrealircd_rpc_py.Connection import Connection
3+
import unrealircd_rpc_py.Definition as dfn
54

65
class Whowas:
76

8-
@dataclass
9-
class ModelWhowas:
10-
name: str
11-
event: str
12-
logon_time: str
13-
logoff_time: str
14-
hostname: str
15-
ip: str
16-
details: str
17-
connected_since: str
18-
user_username: str
19-
user_realname: str
20-
user_vhost: str
21-
user_servername: str
22-
geoip_country_code: str
23-
geoip_asn: str
24-
geoip_asname: str
25-
26-
DB_WHOWAS: list[ModelWhowas] = []
7+
DB_WHOWAS: list[dfn.Whowas] = []
278

289
def __init__(self, Connection: Connection) -> None:
2910

@@ -39,16 +20,16 @@ def __init__(self, Connection: Connection) -> None:
3920
self.Logs = Connection.Logs
4021
self.Error = Connection.Error
4122

42-
def get(self, nick: str = None, ip: str = None, object_detail_level:int = 2) -> Union[list[ModelWhowas], None]:
23+
def get(self, nick: str = None, ip: str = None, object_detail_level:int = 2) -> list[dfn.Whowas]:
4324
"""Get WHOWAS history of a user. 6.1.0+
4425
4526
Args:
46-
_nick (str, optional): The nick name to search for. Defaults to None.
47-
_ip (str, optional): The IP address to search for. Defaults to None.
48-
_object_detail_level (int, optional): set the detail of the response object, this is similar to the Detail level column in Structure of a client object. In this RPC call it defaults to 2 if this parameter is not specified. Defaults to 2.
27+
nick (str, optional): The nick name to search for. Defaults to None.
28+
ip (str, optional): The IP address to search for. Defaults to None.
29+
object_detail_level (int, optional): set the detail of the response object, this is similar to the Detail level column in Structure of a client object. In this RPC call it defaults to 2 if this parameter is not specified. Defaults to 2.
4930
5031
Returns:
51-
List[ModelWhowas]: If success it return the object ModelWhowas | None if nothing or error, see Error property
32+
List[dfn.Whowas]: The Whowas model or Empty Whowas model
5233
"""
5334
try:
5435
self.DB_WHOWAS = []
@@ -62,35 +43,26 @@ def get(self, nick: str = None, ip: str = None, object_detail_level:int = 2) ->
6243
if response is None:
6344
self.Logs.error('Empty response')
6445
self.Connection.EngineError.set_error(code=-2, message='Empty response')
65-
return False
46+
return self.DB_WHOWAS
6647

6748
if 'error' in response:
6849
self.Logs.error(response['error']['message'])
6950
self.Connection.EngineError.set_error(**response["error"])
70-
return False
51+
return self.DB_WHOWAS
7152

72-
whowass = response['result']['list']
53+
whowass: list[dict] = response["result"]["list"]
7354

7455
for whowas in whowass:
56+
57+
whowas_exclude_user = whowas.copy()
58+
whowas_exclude_user.pop('user', None)
59+
7560
self.DB_WHOWAS.append(
76-
self.ModelWhowas(
77-
name=whowas['name'] if 'name' in whowas else None,
78-
event=whowas['event'] if 'event' in whowas else None,
79-
logon_time=whowas['logon_time'] if 'logon_time' in whowas else None,
80-
logoff_time=whowas['logoff_time'] if 'logoff_time' in whowas else None,
81-
hostname=whowas['hostname'] if 'hostname' in whowas else None,
82-
ip=whowas['ip'] if 'ip' in whowas else None,
83-
details=whowas['details'] if 'details' in whowas else None,
84-
connected_since=whowas['connected_since'] if 'connected_since' in whowas else None,
85-
user_username=whowas['user'] if 'user' in whowas and 'username' in whowas['user'] else None,
86-
user_realname=whowas['user'] if 'user' in whowas and 'realname' in whowas['user'] else None,
87-
user_vhost=whowas['user'] if 'user' in whowas and 'vhost' in whowas['user'] else None,
88-
user_servername=whowas['user'] if 'user' in whowas and 'servername' in whowas['user'] else None,
89-
geoip_country_code=whowas['geoip'] if 'geoip' in whowas and 'username' in whowas['geoip'] else None,
90-
geoip_asn=whowas['geoip'] if 'geoip' in whowas and 'asn' in whowas['geoip'] else None,
91-
geoip_asname=whowas['geoip'] if 'geoip' in whowas and 'asname' in whowas['geoip'] else None
92-
)
61+
dfn.Whowas(
62+
**whowas_exclude_user,
63+
user=dfn.WhowasUser(**whowas.get('user', {}))
9364
)
65+
)
9466

9567
return self.DB_WHOWAS
9668

version.json

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

0 commit comments

Comments
 (0)