Skip to content

Commit

Permalink
Merge pull request #19 from adator85/V1.x.x
Browse files Browse the repository at this point in the history
Adding Whowas model in the Definition class
  • Loading branch information
adator85 authored Oct 13, 2024
2 parents 3d5fe23 + a2ff8f5 commit 096920a
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 51 deletions.
Binary file added dist/unrealircd_rpc_py-1.0.6-py3-none-any.whl
Binary file not shown.
Binary file added dist/unrealircd_rpc_py-1.0.6.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='unrealircd_rpc_py',
version='1.0.5',
version='1.0.6',
packages=find_packages(),
install_requires=[
"requests>=2.25.1",
Expand Down
34 changes: 32 additions & 2 deletions unrealircd_rpc_py/Definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class RpcInfo:
version: str = None

#################
# Stats Class #
# Stats Class #
#################

@dataclass
Expand Down Expand Up @@ -415,4 +415,34 @@ class Stats:
server: StatsServer = field(default_factory=StatsServer)
user: StatsUser = field(default_factory=StatsUser)
channel: StatsChannel = field(default_factory=StatsChannel)
server_ban: StatsServerBan = field(default_factory=StatsServerBan)
server_ban: StatsServerBan = field(default_factory=StatsServerBan)

##################
# Whowas Class #
##################

@dataclass
class WhowasUser:
username: str = None
realname: str = None
vhost: str = None
servername: str = None

@dataclass
class Whowas:
"""Whowas Class
Depends on:
```
1- WhowasUser
```
"""
name: str = None
event: str = None
logon_time: str = None
logoff_time: str = None
hostname: str = None
ip: str = None
details: str = None
connected_since: str = None
user: WhowasUser = field(default_factory=WhowasUser)
2 changes: 1 addition & 1 deletion unrealircd_rpc_py/User.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def join(self, nickoruid: str, channel:str, key: str = '', force: bool = False)

if 'error' in response:
self.Logs.error(response['error']['message'])
self.Connection.set_error(**response["error"])
self.Connection.EngineError.set_error(**response["error"])
return False

return True
Expand Down
64 changes: 18 additions & 46 deletions unrealircd_rpc_py/Whowas.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
from types import SimpleNamespace
from typing import Union
from dataclasses import dataclass
from unrealircd_rpc_py.Connection import Connection
import unrealircd_rpc_py.Definition as dfn

class Whowas:

@dataclass
class ModelWhowas:
name: str
event: str
logon_time: str
logoff_time: str
hostname: str
ip: str
details: str
connected_since: str
user_username: str
user_realname: str
user_vhost: str
user_servername: str
geoip_country_code: str
geoip_asn: str
geoip_asname: str

DB_WHOWAS: list[ModelWhowas] = []
DB_WHOWAS: list[dfn.Whowas] = []

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

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

def get(self, nick: str = None, ip: str = None, object_detail_level:int = 2) -> Union[list[ModelWhowas], None]:
def get(self, nick: str = None, ip: str = None, object_detail_level:int = 2) -> list[dfn.Whowas]:
"""Get WHOWAS history of a user. 6.1.0+
Args:
_nick (str, optional): The nick name to search for. Defaults to None.
_ip (str, optional): The IP address to search for. Defaults to None.
_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.
nick (str, optional): The nick name to search for. Defaults to None.
ip (str, optional): The IP address to search for. Defaults to None.
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.
Returns:
List[ModelWhowas]: If success it return the object ModelWhowas | None if nothing or error, see Error property
List[dfn.Whowas]: The Whowas model or Empty Whowas model
"""
try:
self.DB_WHOWAS = []
Expand All @@ -62,35 +43,26 @@ def get(self, nick: str = None, ip: str = None, object_detail_level:int = 2) ->
if response is None:
self.Logs.error('Empty response')
self.Connection.EngineError.set_error(code=-2, message='Empty response')
return False
return self.DB_WHOWAS

if 'error' in response:
self.Logs.error(response['error']['message'])
self.Connection.EngineError.set_error(**response["error"])
return False
return self.DB_WHOWAS

whowass = response['result']['list']
whowass: list[dict] = response["result"]["list"]

for whowas in whowass:

whowas_exclude_user = whowas.copy()
whowas_exclude_user.pop('user', None)

self.DB_WHOWAS.append(
self.ModelWhowas(
name=whowas['name'] if 'name' in whowas else None,
event=whowas['event'] if 'event' in whowas else None,
logon_time=whowas['logon_time'] if 'logon_time' in whowas else None,
logoff_time=whowas['logoff_time'] if 'logoff_time' in whowas else None,
hostname=whowas['hostname'] if 'hostname' in whowas else None,
ip=whowas['ip'] if 'ip' in whowas else None,
details=whowas['details'] if 'details' in whowas else None,
connected_since=whowas['connected_since'] if 'connected_since' in whowas else None,
user_username=whowas['user'] if 'user' in whowas and 'username' in whowas['user'] else None,
user_realname=whowas['user'] if 'user' in whowas and 'realname' in whowas['user'] else None,
user_vhost=whowas['user'] if 'user' in whowas and 'vhost' in whowas['user'] else None,
user_servername=whowas['user'] if 'user' in whowas and 'servername' in whowas['user'] else None,
geoip_country_code=whowas['geoip'] if 'geoip' in whowas and 'username' in whowas['geoip'] else None,
geoip_asn=whowas['geoip'] if 'geoip' in whowas and 'asn' in whowas['geoip'] else None,
geoip_asname=whowas['geoip'] if 'geoip' in whowas and 'asname' in whowas['geoip'] else None
)
dfn.Whowas(
**whowas_exclude_user,
user=dfn.WhowasUser(**whowas.get('user', {}))
)
)

return self.DB_WHOWAS

Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "1.0.5"
"version": "1.0.6"
}

0 comments on commit 096920a

Please sign in to comment.