Skip to content
This repository was archived by the owner on Feb 18, 2023. It is now read-only.

Commit f50abd7

Browse files
committed
[SPARK-243] Fix Vhost parsing
1 parent c9a6939 commit f50abd7

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

src/packages/user/user.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
"""
1313
from __future__ import annotations # enable forward-references
1414

15-
from dataclasses import dataclass
15+
import attr
16+
import cattr
1617
from typing import Union, Optional
1718

1819
from pydle import BasicClient
1920

2021

21-
@dataclass(frozen=True)
22+
@attr.define(frozen=True)
2223
class User:
2324
"""
2425
Represents an IRC user
@@ -50,7 +51,15 @@ async def from_pydle(cls, bot: BasicClient, nickname: str) -> Optional[User]:
5051

5152
# if we got a object back
5253
if data:
53-
return cls(**data)
54+
result = cls(**data)
55+
56+
# This needs to be an evolve as the cls is frozen.
57+
# That and wanting to avoid a converter on the class itself.
58+
59+
# Inspection false-positive. suppress.
60+
# noinspection PyDataclass
61+
result = attr.evolve(inst=result, hostname=cls.process_vhost(result.hostname))
62+
return result
5463

5564
@classmethod
5665
def process_vhost(cls, vhost: Union[str, None]) -> Optional[str]:

tests/fixtures/mock_bot.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,28 @@ def __init__(self, *args, **kwargs):
4444
"some_ov": {
4545
"nickname": "some_ov",
4646
"username": "ill_stop",
47-
"hostname": "overseer.fuelrats.com",
47+
"hostname": "some_ov@some-ov.overseer.fuelrats.com",
4848
"away": False,
4949
"away_message": None,
5050
"account": None,
5151
"identified": True,
5252
"realname": "Stop sign",
5353

5454
},
55+
"some_rat": {
56+
"nickname": "some_rat",
57+
"username": "ratlingDelux",
58+
"hostname": "delux@delux.rat.fuelrats.com",
59+
"away": False,
60+
"away_message": None,
61+
"account": None,
62+
"identified": True,
63+
"realname": "snakeeyes",
64+
},
5565
"some_admin": {
5666
"nickname": "some_admin",
5767
"username": "SirRaymondLuxuryYacht",
58-
"hostname": "admin.fuelrats.com",
68+
"hostname": "reality@netadmin.fuelrats.com",
5969
"away": False,
6070
"away_message": None,
6171
"account": None,

0 commit comments

Comments
 (0)