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 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)

View File

@ -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

View File

@ -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']