Commit 95f63964 authored by Guillaume Binet's avatar Guillaume Binet

Merge branch 'room-as-id' of github.com:errbotio/errbot into room-as-id

parents 5e625356 b9ae4d06
......@@ -26,6 +26,17 @@ log = logging.getLogger('errbot.backends.base')
class Identifier(ABC):
"""This is just use for type hinting representing the Identifier contract,
NEVER TRY TO SUBCLASS IT OUTSIDE OF A BACKEND, it is just here to show you what you can expect from an Identifier.
To get an instance of a real identifier, always use the properties from Message (to, from) or self.build_identifier
to make an identifier from a String.
The semantics is anything you can talk to: Person, Room, RoomOccupant etc.
"""
pass
class Person(Identifier):
"""This is just use for type hinting representing the Identifier contract,
NEVER TRY TO SUBCLASS IT OUTSIDE OF A BACKEND, it is just here to show you what you can expect from an Identifier.
To get an instance of a real identifier, always use the properties from Message (to, from) or self.build_identifier
......@@ -69,9 +80,9 @@ class Identifier(ABC):
pass
class MUCIdentifier(Identifier):
class RoomOccupant(Identifier):
@abstractproperty
def room(self) -> Any: # this is MUCRoom defined below
def room(self) -> Any: # this is oom defined below
"""
Some backends have the full name of a user.
:return: the fullname of this user if available.
......@@ -79,7 +90,7 @@ class MUCIdentifier(Identifier):
pass
class MUCRoom(object):
class Room(Identifier):
"""
This class represents a Multi-User Chatroom.
"""
......@@ -168,7 +179,7 @@ class MUCRoom(object):
raise NotImplementedError("It should be implemented specifically for your backend")
@property
def occupants(self) -> List[MUCIdentifier]:
def occupants(self) -> List[RoomOccupant]:
"""
The room's occupants.
......@@ -219,7 +230,6 @@ class Message(object):
def __init__(self,
body: str='',
type_: str='chat',
frm: Identifier=None,
to: Identifier=None,
delayed: bool=False,
......@@ -227,20 +237,17 @@ class Message(object):
"""
:param body:
The plaintext body of the message.
:param type_:
The type of message (generally one of either 'chat' or 'groupchat').
:param extras:
Extra data attached by a backend
"""
self._body = compat_str(body)
self._type = type_
self._from = frm
self._to = to
self._delayed = delayed
self._extras = extras or dict()
def clone(self):
return Message(self._body, self._type, self._from, self._to, self._delayed, self.extras)
return Message(self._body, self._from, self._to, self._delayed, self.extras)
@property
def to(self) -> Identifier:
......@@ -265,28 +272,6 @@ class Message(object):
% (to, to.__class__))
self._to = to
@property
def type(self) -> str:
"""
Get the type of the message.
:returns:
The message type as a string (generally one of either
'chat' or 'groupchat')
"""
return self._type
@type.setter
def type(self, type_: str):
"""
Set the type of the message.
:param type_:
The message type (generally one of either 'chat'
or 'groupchat').
"""
self._type = type_
@property
def frm(self) -> Identifier:
"""
......@@ -340,8 +325,13 @@ class Message(object):
def __str__(self):
return self._body
# deprecated stuff ...
@property
def is_direct(self) -> bool:
return isinstance(self.frm, Person) and isinstance(self.to, Person)
@property
def is_group(self) -> bool:
return isinstance(self.frm, Room) or isinstance(self.to, Room)
ONLINE = 'online'
OFFLINE = 'offline'
......@@ -359,9 +349,8 @@ class Presence(object):
def __init__(self,
nick: str=None,
identifier: Identifier=None,
occupant: RoomOccupant=None,
status: str=None,
chatroom: Identifier=None,
message: str=None):
if nick is None and identifier is None:
raise ValueError('Presence: nick and identifiers are both None')
......@@ -370,18 +359,10 @@ class Presence(object):
if status is None and message is None:
raise ValueError('Presence: at least a new status or a new status message mustbe present')
self._nick = nick
self._identifier = identifier
self._chatroom = chatroom
self._occupant = occupant
self._status = status
self._message = message
@property
def chatroom(self) -> Identifier:
""" Returns the identifier pointing the room in which the event occurred.
If it returns None, the event occurred outside of a chatroom.
"""
return self._chatroom
@property
def nick(self) -> str:
""" Returns a plain string of the presence nick.
......@@ -392,11 +373,11 @@ class Presence(object):
return self._nick
@property
def identifier(self) -> Identifier:
def occupant(self) -> RoomOccupant:
""" Returns the identifier of the event.
Can be None *only* if chatroom is not None
"""
return self._identifier
return self._occupant
@property
def status(self) -> str:
......@@ -419,12 +400,10 @@ class Presence(object):
response = ''
if self._nick:
response += 'Nick:%s ' % self._nick
if self._identifier:
response += 'Idd:%s ' % self._identifier
if self._occupant:
response += 'Idd:%s ' % self._occupant
if self._status:
response += 'Status:%s ' % self._status
if self._chatroom:
response += 'Room:%s ' % self._chatroom
if self._message:
response += 'Msg:%s ' % self._message
return response
......@@ -591,17 +570,17 @@ class Backend(ABC):
pass
@abstractmethod
def callback_room_joined(self, room: MUCRoom) -> None:
def callback_room_joined(self, room: Room) -> None:
""" See :class:`~errbot.errBot.ErrBot` """
pass
@abstractmethod
def callback_room_left(self, room: MUCRoom) -> None:
def callback_room_left(self, room: Room) -> None:
""" See :class:`~errbot.errBot.ErrBot` """
pass
@abstractmethod
def callback_room_topic(self, room: MUCRoom) -> None:
def callback_room_topic(self, room: Room) -> None:
""" See :class:`~errbot.errBot.ErrBot` """
pass
......@@ -670,7 +649,7 @@ class Backend(ABC):
"""
@abstractmethod
def build_identifier(self, text_representation: str) -> Union[Identifier, MUCIdentifier]:
def build_identifier(self, text_representation: str) -> Identifier:
pass
def serve_once(self) -> None:
......@@ -692,14 +671,14 @@ class Backend(ABC):
"""Connects the bot to server or returns current connection """
@abstractmethod
def query_room(self, room: str) -> MUCRoom:
def query_room(self, room: str) -> Room:
"""
Query a room for information.
:param room:
The room to query for.
:returns:
An instance of :class:`~MUCRoom`.
An instance of :class:`~Room`.
"""
@abstractmethod
......@@ -715,10 +694,10 @@ class Backend(ABC):
pass
@abstractproperty
def rooms(self) -> Sequence[MUCRoom]:
def rooms(self) -> Sequence[Room]:
"""
Return a list of rooms the bot is currently in.
:returns:
A list of :class:`~errbot.backends.base.MUCRoom` instances.
A list of :class:`~errbot.backends.base.Room` instances.
"""
......@@ -9,7 +9,7 @@ from markdown.extensions import Extension
from markdown.treeprocessors import Treeprocessor
from errbot.backends.base import RoomDoesNotExistError
from errbot.backends.xmpp import XMPPMUCOccupant, XMPPMUCRoom, XMPPBackend, XMPPConnection
from errbot.backends.xmpp import XMPPMUCOccupant, XMPPRoom, XMPPBackend, XMPPConnection
# Can't use __name__ because of Yapsy
......@@ -87,7 +87,7 @@ class HipChatMUCOccupant(XMPPMUCOccupant):
return self.name
class HipChatMUCRoom(XMPPMUCRoom):
class HipChatMUCRoom(XMPPRoom):
"""
This class represents a Multi-User Chatroom.
"""
......
......@@ -10,9 +10,9 @@ import time
from markdown import Markdown
from markdown.extensions.extra import ExtraExtension
from errbot.backends.base import Message, MUCRoom, Stream, RoomError, \
from errbot.backends.base import Message, Room, Stream, RoomError, \
RoomNotJoinedError, Stream, Identifier, \
MUCIdentifier, ONLINE
Occupant, ONLINE
from errbot.errBot import ErrBot
from errbot.utils import rate_limited
from errbot.rendering.ansi import AnsiExtension, enable_format, \
......@@ -132,7 +132,7 @@ class IRCIdentifier(Identifier):
return self.__unicode__()
class IRCMUCOccupant(MUCIdentifier, IRCIdentifier):
class IRCMUCOccupant(Occupant, IRCIdentifier):
def __init__(self, mask, room, aclpattern):
super().__init__(mask, aclpattern)
self._room = room
......@@ -155,7 +155,7 @@ class IRCMUCOccupant(MUCIdentifier, IRCIdentifier):
return "<{} - {}>".format(self.__unicode__(), super().__repr__())
class IRCMUCRoom(MUCRoom):
class IRCMUCRoom(Room):
def __init__(self, room, bot, aclpattern):
self._bot = bot
self.room = room
......
......@@ -6,8 +6,8 @@ import time
import sys
import pprint
from errbot.backends.base import Message, Presence, ONLINE, AWAY, MUCRoom, RoomError, RoomDoesNotExistError, \
UserDoesNotExistError, Identifier, MUCIdentifier
from errbot.backends.base import Message, Presence, ONLINE, AWAY, Room, RoomError, RoomDoesNotExistError, \
UserDoesNotExistError, Identifier, RoomOccupant
from errbot.errBot import ErrBot
from errbot.utils import deprecated, PY3, split_string_after
from errbot.rendering import imtext
......@@ -152,7 +152,7 @@ class SlackIdentifier(Identifier):
return self.__unicode__()
class SlackMUCOccupant(MUCIdentifier, SlackIdentifier):
class SlackRoomOccupant(RoomOccupant, SlackIdentifier):
"""
This class represents a person inside a MUC.
"""
......@@ -358,7 +358,6 @@ class SlackBackend(ErrBot):
msg = Message(
text,
type_=message_type,
extras={'attachments': event.get('attachments')})
if message_type == 'chat':
......@@ -366,9 +365,9 @@ class SlackBackend(ErrBot):
msg.to = SlackIdentifier(self.sc, self.username_to_userid(self.sc.server.username),
event['channel'])
else:
msg.frm = SlackMUCOccupant(self.sc, user, event['channel'])
msg.to = SlackMUCOccupant(self.sc, self.username_to_userid(self.sc.server.username),
event['channel'])
msg.frm = SlackRoomOccupant(self.sc, user, event['channel'])
msg.to = SlackRoomOccupant(self.sc, self.username_to_userid(self.sc.server.username),
event['channel'])
self.callback_message(msg)
......@@ -582,7 +581,7 @@ class SlackBackend(ErrBot):
return SlackIdentifier(self.sc, userid, self.get_im_channel(userid))
if channelname is not None:
channelid = self.channelname_to_channelid(channelname)
return SlackMUCOccupant(self.sc, userid, channelid)
return SlackRoomOccupant(self.sc, userid, channelid)
raise Exception(
"You found a bug. I expected at least one of userid, channelid, username or channelname "
......@@ -637,7 +636,7 @@ class SlackBackend(ErrBot):
return match_object.group()
class SlackRoom(MUCRoom):
class SlackRoom(Room):
def __init__(self, name=None, channelid=None, bot=None):
if channelid is not None and name is not None:
raise ValueError("channelid and name are mutually exclusive")
......@@ -799,7 +798,7 @@ class SlackRoom(MUCRoom):
@property
def occupants(self):
members = self._channel_info['members']
return [SlackMUCOccupant(self.sc, self._bot.userid_to_username(m), self._name) for m in members]
return [SlackRoomOccupant(self.sc, self._bot.userid_to_username(m), self._name) for m in members]
def invite(self, *args):
users = {user['name']: user['id'] for user in self._bot.api_call('users.list')['members']}
......
import logging
import sys
from errbot.backends.base import RoomError, Identifier, MUCIdentifier, ONLINE
from errbot.backends.base import RoomError, Identifier, Occupant, ONLINE
from errbot.errBot import ErrBot
from errbot.rendering import text
......@@ -102,7 +102,7 @@ class TelegramIdentifier(Identifier):
aclattr = id
class TelegramMUCOccupant(MUCIdentifier, TelegramIdentifier):
class TelegramMUCOccupant(Occupant, TelegramIdentifier):
"""
This class represents a person inside a MUC.
"""
......
......@@ -10,7 +10,7 @@ from threading import Thread
import pytest
from errbot.rendering import text
from errbot.backends.base import Message, MUCRoom, Identifier, MUCIdentifier, ONLINE
from errbot.backends.base import Message, Room, Identifier, RoomOccupant, ONLINE
from errbot.core_plugins.wsview import reset_app
from errbot.errBot import ErrBot
from errbot.main import setup_bot
......@@ -82,7 +82,7 @@ class TestIdentifier(Identifier):
# noinspection PyAbstractClass
class TestMUCOccupant(TestIdentifier, MUCIdentifier):
class TestMUCOccupant(TestIdentifier, RoomOccupant):
""" This is a MUC occupant represented as a string.
DO NOT USE THIS DIRECTLY AS IT IS NOT COMPATIBLE WITH MOST BACKENDS,
"""
......@@ -104,7 +104,7 @@ class TestMUCOccupant(TestIdentifier, MUCIdentifier):
return self.person == other.person and self.room == other.room
class TestMUCRoom(MUCRoom):
class TestRoom(Room):
def invite(self, *args):
pass
......@@ -291,7 +291,7 @@ class TestBackend(ErrBot):
try:
return [r for r in self._rooms if str(r) == str(room)][0]
except IndexError:
r = TestMUCRoom(room, bot=self)
r = TestRoom(room, bot=self)
return r
def prefix_groupchat_reply(self, message, identifier):
......
......@@ -12,7 +12,7 @@ from pygments.lexers import get_lexer_by_name
from errbot.rendering import ansi, text, xhtml, imtext
from errbot.rendering.ansi import enable_format, ANSI_CHRS, AnsiExtension
from errbot.backends.base import Message, Presence, ONLINE, OFFLINE, MUCRoom
from errbot.backends.base import Message, Presence, ONLINE, OFFLINE, Room
from errbot.backends.test import TestIdentifier
from errbot.errBot import ErrBot
from errbot.utils import deprecated
......@@ -134,7 +134,7 @@ class TextBackend(ErrBot):
return 'text'
def query_room(self, room):
room = TextMUCRoom()
room = TextRoom()
self._rooms.add(room)
return room
......@@ -145,7 +145,7 @@ class TextBackend(ErrBot):
message.body = '@{0} {1}'.format(identifier.nick, message.body)
class TextMUCRoom(MUCRoom):
class TextRoom(Room):
def __init__(self):
self.topic_ = ''
......
......@@ -3,12 +3,55 @@ import sys
import warnings
from threading import Thread
from time import sleep
from html.entities import entitydefs
from html import _invalid_codepoints, _invalid_charrefs
from errbot.backends.base import Message, MUCRoom, Presence, RoomNotJoinedError, Identifier, MUCIdentifier
import re
from errbot.backends.base import Message, Room, Presence, RoomNotJoinedError, Identifier, Occupant
from errbot.backends.base import ONLINE, OFFLINE, AWAY, DND
from errbot.errBot import ErrBot
from errbot.rendering import text, xhtml
SAFE_ENTITIES = {e: entitydefs[e] for e in entitydefs if e not in ('amp', 'quot', 'apos', 'gt', 'lt')}
def _replace_charref(s):
s = s.group(1)
if s[0] == '#':
# numeric charref
if s[1] in 'xX':
num = int(s[2:].rstrip(';'), 16)
else:
num = int(s[1:].rstrip(';'))
if num in _invalid_charrefs:
return _invalid_charrefs[num]
if 0xD800 <= num <= 0xDFFF or num > 0x10FFFF:
return '\uFFFD'
if num in _invalid_codepoints:
return ''
return chr(num)
else:
# named charref
if s in SAFE_ENTITIES:
return SAFE_ENTITIES[s]
# find the longest matching name (as defined by the standard)
for x in range(len(s)-1, 1, -1):
if s[:x] in SAFE_ENTITIES:
return SAFE_ENTITIES[s[:x]] + s[x:]
else:
return '&' + s
_charref = re.compile(r'&(#[0-9]+;?'
r'|#[xX][0-9a-fA-F]+;?'
r'|[^\t\n\f <&#;]{1,32};?)')
def unescape(s):
if '&' not in s:
return s
return _charref.sub(_replace_charref, s)
# Can't use __name__ because of Yapsy
log = logging.getLogger('errbot.backends.xmpp')
......@@ -87,8 +130,14 @@ class XMPPIdentifier(Identifier):
def __unicode__(self):
return str(self.__str__())
def __eq__(self, other):
if not isinstance(other, XMPPIdentifier):
log.debug("Weird, you are comparing an XMPPIdentifier to a %s", type(other))
return False
return self._domain == other._domain and self._node == other._node and self._resource == other._resource
class XMPPMUCRoom(MUCRoom):
class XMPPRoom(Room):
def __init__(self, name, bot):
self._bot = bot
self._name = name
......@@ -284,7 +333,7 @@ class XMPPMUCRoom(MUCRoom):
.format(room, affiliation))
class XMPPMUCOccupant(MUCIdentifier, XMPPIdentifier):
class XMPPMUCOccupant(Occupant, XMPPIdentifier):
@property
def person(self):
return str(self) # this is the full identifier.
......@@ -481,7 +530,7 @@ class XMPPBackend(ErrBot):
if topic == "":
topic = None
self._room_topics[room] = topic
room = XMPPMUCRoom(event.values['mucroom'], self)
room = XMPPRoom(event.values['mucroom'], self)
self.callback_room_topic(room)
def user_changed_status(self, event):
......@@ -516,7 +565,8 @@ class XMPPBackend(ErrBot):
mess.to = XMPPIdentifier(mess.to.node, mess.to.domain, None)
log.debug("send_message to %s", mess.to)
mhtml = self.md_xhtml.convert(mess.body) if self.xhtmlim else None
# We need to unescape the unicode characters (not the markup incompatible ones)
mhtml = unescape(self.md_xhtml.convert(mess.body)) if self.xhtmlim else None
self.conn.client.send_message(mto=str(mess.to),
mbody=self.md_text.convert(mess.body),
......@@ -608,7 +658,7 @@ class XMPPBackend(ErrBot):
A list of :class:`~errbot.backends.base.XMPPMUCRoom` instances.
"""
xep0045 = self.conn.client.plugin['xep_0045']
return [XMPPMUCRoom(room, self) for room in xep0045.getJoinedRooms()]
return [XMPPRoom(room, self) for room in xep0045.getJoinedRooms()]
def query_room(self, room):
"""
......@@ -619,7 +669,7 @@ class XMPPBackend(ErrBot):
:returns:
An instance of :class:`~XMPPMUCRoom`.
"""
return XMPPMUCRoom(room, self)
return XMPPRoom(room, self)
def prefix_groupchat_reply(self, message, identifier):
message.body = '@{0} {1}'.format(identifier.nick, message.body)
......@@ -7,7 +7,7 @@ from io import IOBase
from .utils import recurse_check_structure
from .storage import StoreMixin, StoreNotOpenError
from errbot.backends.base import Message, Presence, Stream, MUCRoom, Identifier, ONLINE
from errbot.backends.base import Message, Presence, Stream, Room, Identifier, ONLINE
log = logging.getLogger(__name__)
......@@ -301,7 +301,7 @@ class BotPlugin(BotPluginBase):
"""
pass
def callback_room_joined(self, room: MUCRoom):
def callback_room_joined(self, room: Room):
"""
Triggered when the bot has joined a MUC.
......@@ -311,7 +311,7 @@ class BotPlugin(BotPluginBase):
"""
pass
def callback_room_left(self, room: MUCRoom):
def callback_room_left(self, room: Room):
"""
Triggered when the bot has left a MUC.
......@@ -321,7 +321,7 @@ class BotPlugin(BotPluginBase):
"""
pass
def callback_room_topic(self, room: MUCRoom):
def callback_room_topic(self, room: Room):
"""
Triggered when the topic in a MUC changes.
......@@ -342,7 +342,7 @@ class BotPlugin(BotPluginBase):
self._bot.warn_admins(warning)
def send(self,
user_or_room: Union[Identifier, MUCRoom],
identifier: Union[Identifier],
text: str,
in_reply_to: Message=None,
message_type: str=None,
......@@ -355,14 +355,14 @@ class BotPlugin(BotPluginBase):
:param message_type: DEPRECATED
:param in_reply_to: optionally, the original message this message is the answer to.
:param text: markdown formatted text to send to the user.
:param user_or_room: identifier of the user or a room to which you want to send a message to.
see build_identifier.
:param identifier: identifier of the user or a room to which you want to send a message to.
see build_identifier, room_join.
"""
if type(user_or_room) is str:
raise ValueError("user_or_send needs to be Identifier or MUCRoom, the old string behavior is not supported")
raise ValueError("identifier needs to be of type Identifier, the old string behavior is not supported")
if message_type is not None:
self.log.warn("send message_type is DEPRECATED. Either pass a user identifier or a room to send.")
return self._bot.send(user_or_room, text, in_reply_to, groupchat_nick_reply)
return self._bot.send(identifier, text, in_reply_to, groupchat_nick_reply)
def change_presence(self, status: str = ONLINE, message: str = '') -> None:
"""
......@@ -375,7 +375,7 @@ class BotPlugin(BotPluginBase):
self._bot.change_presence(status, message)
def send_templated(self,
user: Identifier,
identifier: Identifier,
template_name: str,
template_parameters: Mapping,
in_reply_to: Message=None,
......@@ -392,7 +392,7 @@ class BotPlugin(BotPluginBase):
:param message_type: DEPRECATED
:param in_reply_to: optionally, the original message this message is the answer to.
:param text: markdown formatted text to send to the user.
:param user: identifier of the user to which you want to send a message to. see build_identifier.
:param identifier: identifier of the user or room to which you want to send a message to. see build_identifier.
"""
return self._bot.send_templated(user, template_name, template_parameters, in_reply_to, message_type,
groupchat_nick_reply)
......@@ -426,13 +426,13 @@ class BotPlugin(BotPluginBase):
"""
return self._bot.send_stream_request(user, fsource, name, size, stream_type)
def rooms(self) -> Sequence[MUCRoom]:
def rooms(self) -> Sequence[Room]:
"""
The list of rooms the bot is currently in.
"""
return self._bot.rooms()
def query_room(self, room: str) -> MUCRoom:
def query_room(self, room: str) -> Room:
"""
Query a room for information.
......
......@@ -52,7 +52,6 @@ class ACLS(BotPlugin):
self.log.debug("Check %s for ACLs." % cmd)
usr = get_acl_usr(msg)
typ = msg.type
self.log.debug("Matching ACLs against username %s" % usr)
......@@ -67,7 +66,7 @@ class ACLS(BotPlugin):
glob(usr, self.bot_config.ACCESS_CONTROLS[cmd]['denyusers'])):
return self.access_denied(msg, "You're not allowed to access this command from this user", dry_run)
if typ == 'groupchat':
if msg.is_group:
if not hasattr(msg.frm, 'room'):
raise Exception('msg.frm is not a MUCIdentifier as it misses the "room" property. Class of frm : %s'
% msg.frm.__class__)
......@@ -107,7 +106,7 @@ class ACLS(BotPlugin):
f = self._bot.all_commands[cmd]
if f._err_command_admin_only:
if msg.type == 'groupchat':
if msg.is_group:
return self.access_denied(
msg,
"You cannot administer the bot from a chatroom, message the bot directly", dry_run)
......
......@@ -230,16 +230,16 @@ class ChatRoom(BotPlugin):
def callback_message(self, mess):
try:
mess_type = mess.type
if mess_type == 'chat':
if mess.is_direct:
username = mess.frm.person
if username in self.bot_config.CHATROOM_RELAY:
self.log.debug('Message to relay from %s.' % username)
body = mess.body
rooms = self.bot_config.CHATROOM_RELAY[username]
for room in rooms:
self.send(room, body, message_type='groupchat')
elif mess_type == 'groupchat':
for roomstr in rooms:
room = self.room_join(roomstr)
self.send(room, body)
elif mess.is_group:
fr = mess.frm
chat_room = fr.room
if chat_room in self.bot_config.REVERSE_CHATROOM_RELAY:
......
......@@ -19,7 +19,7 @@ import inspect
import logging
import traceback
from .backends.base import Backend, MUCRoom, Identifier
from .backends.base import Backend, Room, Identifier, Person
from threadpool import ThreadPool, WorkRequest
from .streaming import Tee
from .templating import tenv
......@@ -135,10 +135,10 @@ class ErrBot(Backend, StoreMixin):
except Exception:
log.exception("{} on {} crashed".format(method, plugin_name))
def send(self, user_or_room, text, in_reply_to=None, groupchat_nick_reply=False):
def send(self, identifier, text, in_reply_to=None, groupchat_nick_reply=False):
""" Sends a simple message to the specified user.
:param user:
:param identifier:
an identifier from build_identifier or from an incoming message
:param in_reply_to:
the original message the bot is answering from
......@@ -148,15 +148,15 @@ class ErrBot(Backend, StoreMixin):
authorized the prefixing with the nick form the user
"""
# protect a little bit the backends here
if not isinstance(user_or_room, (MUCRoom, Identifier)):
raise ValueError("user_or_room should be either a MUCRoom or an Identifier")
if not isinstance(identifier, Identifier):
raise ValueError("identifier should be an Identifier")
mess = self.build_message(text)
mess.to = user_or_room
mess.to = identifier
mess.frm = in_reply_to.to if in_reply_to else self.bot_identifier
nick_reply = self.bot_config.GROUPCHAT_NICK_PREFIXED
if isinstance(user_or_room, MUCRoom) and in_reply_to and nick_reply and groupchat_nick_reply:
if isinstance(user_or_room, Room) and in_reply_to and nick_reply and groupchat_nick_reply:
self.prefix_groupchat_reply(mess, in_reply_to.frm)
self.split_and_send_message(mess)
......@@ -213,7 +213,7 @@ class ErrBot(Backend, StoreMixin):
:param mess: the incoming message.
"""
# Prepare to handle either private chats or group chats
type_ = mess.type
frm = mess.frm
text = mess.body
if not hasattr(mess.frm, 'person'):
......@@ -227,18 +227,12 @@ class ErrBot(Backend, StoreMixin):
log.debug("Message from history, ignore it")