Fix: AttributeError in get_nick and jid_in_room due to incorrect JID type

This commit is contained in:
jinyu 2024-09-08 00:50:11 +08:00 committed by mathieui
parent e5fe53ef45
commit 5ed5e60b20
3 changed files with 17 additions and 14 deletions

View File

@ -12,6 +12,8 @@ import copy
import logging import logging
import threading import threading
from slixmpp.clientxmpp import ClientXMPP
from typing import Any, Dict, Set, ClassVar from typing import Any, Dict, Set, ClassVar
@ -272,7 +274,7 @@ class BasePlugin(object):
#: `plugin.config['foo']`. #: `plugin.config['foo']`.
default_config: ClassVar[Dict[str, Any]] = {} default_config: ClassVar[Dict[str, Any]] = {}
def __init__(self, xmpp, config=None): def __init__(self, xmpp: ClientXMPP, config=None):
self.xmpp = xmpp self.xmpp = xmpp
if self.xmpp: if self.xmpp:
self.api = self.xmpp.api.wrap(self.name) self.api = self.xmpp.api.wrap(self.name)

View File

@ -49,11 +49,13 @@ from slixmpp.plugins.xep_0045.stanza import (
MUCUserItem, MUCUserItem,
) )
from slixmpp.types import ( from slixmpp.types import (
JidStr,
MucRole, MucRole,
MucAffiliation, MucAffiliation,
MucRoomItem, MucRoomItem,
MucRoomItemKeys, MucRoomItemKeys,
PresenceArgs, PresenceArgs,
PresenceShows,
) )
JoinResult = Tuple[Presence, Message, List[Presence], List[Message]] JoinResult = Tuple[Presence, Message, List[Presence], List[Message]]
@ -187,7 +189,7 @@ class XEP_0045(BasePlugin):
def _handle_config_change(self, msg: Message): def _handle_config_change(self, msg: Message):
"""Handle a MUC configuration change (with status code).""" """Handle a MUC configuration change (with status code)."""
self.xmpp.event('groupchat_config_status', msg) 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): def _client_handle_presence(self, pr: Presence):
"""As a client, handle a presence stanza""" """As a client, handle a presence stanza"""
@ -358,7 +360,7 @@ class XEP_0045(BasePlugin):
return (pres, subject, occupant_buffer, history_buffer) return (pres, subject, occupant_buffer, history_buffer)
def join_muc(self, room: JID, nick: str, maxhistory="0", password='', 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. """ Join the specified room, requesting 'maxhistory' lines of history.
.. deprecated:: 1.8.0 .. deprecated:: 1.8.0
@ -646,13 +648,13 @@ class XEP_0045(BasePlugin):
"""Check if a JID is present in a room. """Check if a JID is present in a room.
:param room: Room to check. :param room: Room to check.
:param jid: JID to check. :param jid: FULL JID to check.
""" """
for nick in self.rooms[room]: for nick in self.rooms[room]:
entry = self.rooms[room][nick] entry = self.rooms[room][nick]
if not entry.get('jid'): if not entry.get('jid'):
continue continue
if entry is not None and entry['jid'].full == jid: if entry is not None and entry['jid'] == jid.full:
return True return True
return False return False
@ -660,13 +662,13 @@ class XEP_0045(BasePlugin):
"""Get the nickname of a specific JID in a room. """Get the nickname of a specific JID in a room.
:param room: Room to inspect. :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]: for nick in self.rooms[room]:
entry = self.rooms[room][nick] entry = self.rooms[room][nick]
if not entry.get('jid'): if not entry.get('jid'):
continue continue
if entry is not None and entry['jid'].full == jid: if entry is not None and entry['jid'] == jid.full:
return nick return nick
return None return None

View File

@ -53,17 +53,20 @@ MucAffiliation = Literal[
'outcast', 'member', 'admin', 'owner', 'none' 'outcast', 'member', 'admin', 'owner', 'none'
] ]
OptJid = Optional[JID]
JidStr = Union[str, JID]
OptJidStr = Optional[Union[str, JID]]
class PresenceArgs(TypedDict, total=False): class PresenceArgs(TypedDict, total=False):
pfrom: JID pfrom: JidStr
pto: JID pto: JidStr
pshow: PresenceShows pshow: PresenceShows
ptype: PresenceTypes ptype: PresenceTypes
pstatus: str pstatus: str
class MucRoomItem(TypedDict, total=False): class MucRoomItem(TypedDict, total=False):
jid: JID jid: str
role: MucRole role: MucRole
affiliation: MucAffiliation affiliation: MucAffiliation
show: Optional[PresenceShows] show: Optional[PresenceShows]
@ -75,10 +78,6 @@ MucRoomItemKeys = Literal[
'jid', 'role', 'affiliation', 'show', 'status', 'alt_nick', 'jid', 'role', 'affiliation', 'show', 'status', 'alt_nick',
] ]
OptJid = Optional[JID]
JidStr = Union[str, JID]
OptJidStr = Optional[Union[str, JID]]
MAMDefault = Literal['always', 'never', 'roster'] MAMDefault = Literal['always', 'never', 'roster']
FilterString = Literal['in', 'out', 'out_sync'] FilterString = Literal['in', 'out', 'out_sync']