From 5ed5e60b2071e643a8cbe5125baee8ad0b55acfc Mon Sep 17 00:00:00 2001 From: jinyu <96060102+jinyu2022@users.noreply.github.com> Date: Sun, 8 Sep 2024 00:50:11 +0800 Subject: [PATCH] Fix: AttributeError in get_nick and jid_in_room due to incorrect JID type --- slixmpp/plugins/base.py | 4 +++- slixmpp/plugins/xep_0045/muc.py | 14 ++++++++------ slixmpp/types.py | 13 ++++++------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/slixmpp/plugins/base.py b/slixmpp/plugins/base.py index 2aaf1b99..6fe4f622 100644 --- a/slixmpp/plugins/base.py +++ b/slixmpp/plugins/base.py @@ -12,6 +12,8 @@ import copy import logging import threading +from slixmpp.clientxmpp import ClientXMPP + from typing import Any, Dict, Set, ClassVar @@ -272,7 +274,7 @@ class BasePlugin(object): #: `plugin.config['foo']`. default_config: ClassVar[Dict[str, Any]] = {} - def __init__(self, xmpp, config=None): + def __init__(self, xmpp: ClientXMPP, config=None): self.xmpp = xmpp if self.xmpp: self.api = self.xmpp.api.wrap(self.name) diff --git a/slixmpp/plugins/xep_0045/muc.py b/slixmpp/plugins/xep_0045/muc.py index b9ca4c14..58b9a0bb 100644 --- a/slixmpp/plugins/xep_0045/muc.py +++ b/slixmpp/plugins/xep_0045/muc.py @@ -49,11 +49,13 @@ from slixmpp.plugins.xep_0045.stanza import ( MUCUserItem, ) from slixmpp.types import ( + JidStr, MucRole, MucAffiliation, MucRoomItem, MucRoomItemKeys, PresenceArgs, + PresenceShows, ) JoinResult = Tuple[Presence, Message, List[Presence], List[Message]] @@ -187,7 +189,7 @@ class XEP_0045(BasePlugin): def _handle_config_change(self, msg: Message): """Handle a MUC configuration change (with status code).""" self.xmpp.event('groupchat_config_status', msg) - self.xmpp.event('muc::%s::config_status' % msg['from'].bare , msg) + self.xmpp.event('muc::%s::config_status' % msg['from'].bare, msg) def _client_handle_presence(self, pr: Presence): """As a client, handle a presence stanza""" @@ -358,7 +360,7 @@ class XEP_0045(BasePlugin): return (pres, subject, occupant_buffer, history_buffer) def join_muc(self, room: JID, nick: str, maxhistory="0", password='', - pstatus='', pshow='', pfrom='') -> asyncio.Future: + pstatus='', pshow: PresenceShows='chat', pfrom: JidStr='') -> asyncio.Future: """ Join the specified room, requesting 'maxhistory' lines of history. .. deprecated:: 1.8.0 @@ -646,13 +648,13 @@ class XEP_0045(BasePlugin): """Check if a JID is present in a room. :param room: Room to check. - :param jid: JID to check. + :param jid: FULL JID to check. """ for nick in self.rooms[room]: entry = self.rooms[room][nick] if not entry.get('jid'): continue - if entry is not None and entry['jid'].full == jid: + if entry is not None and entry['jid'] == jid.full: return True return False @@ -660,13 +662,13 @@ class XEP_0045(BasePlugin): """Get the nickname of a specific JID in a room. :param room: Room to inspect. - :param jid: JID whose nick to return. + :param jid: FULL JID whose nick to return. """ for nick in self.rooms[room]: entry = self.rooms[room][nick] if not entry.get('jid'): continue - if entry is not None and entry['jid'].full == jid: + if entry is not None and entry['jid'] == jid.full: return nick return None diff --git a/slixmpp/types.py b/slixmpp/types.py index f6a5f5d2..016bbfa4 100644 --- a/slixmpp/types.py +++ b/slixmpp/types.py @@ -53,17 +53,20 @@ MucAffiliation = Literal[ 'outcast', 'member', 'admin', 'owner', 'none' ] +OptJid = Optional[JID] +JidStr = Union[str, JID] +OptJidStr = Optional[Union[str, JID]] class PresenceArgs(TypedDict, total=False): - pfrom: JID - pto: JID + pfrom: JidStr + pto: JidStr pshow: PresenceShows ptype: PresenceTypes pstatus: str class MucRoomItem(TypedDict, total=False): - jid: JID + jid: str role: MucRole affiliation: MucAffiliation show: Optional[PresenceShows] @@ -75,10 +78,6 @@ MucRoomItemKeys = Literal[ 'jid', 'role', 'affiliation', 'show', 'status', 'alt_nick', ] -OptJid = Optional[JID] -JidStr = Union[str, JID] -OptJidStr = Optional[Union[str, JID]] - MAMDefault = Literal['always', 'never', 'roster'] FilterString = Literal['in', 'out', 'out_sync']