Commit b9ae4d06 authored by Guillaume Binet's avatar Guillaume Binet

big rename, still some failing cases.

parent 0684ce74
......@@ -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_ = ''
......
......@@ -8,7 +8,7 @@ from html import _invalid_codepoints, _invalid_charrefs
import re
from errbot.backends.base import Message, MUCRoom, Presence, RoomNotJoinedError, Identifier, MUCIdentifier
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
......@@ -130,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
......@@ -327,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.
......@@ -524,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):
......@@ -652,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):
"""
......@@ -663,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],
user_or_room: Union[Identifier, Room],
text: str,
in_reply_to: Message=None,
message_type: str=None,
......@@ -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
......@@ -148,7 +148,7 @@ 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)):
if not isinstance(user_or_room, (Room, Identifier)):
raise ValueError("user_or_room should be either a MUCRoom or an Identifier")
mess = self.build_message(text)
......@@ -156,7 +156,7 @@ class ErrBot(Backend, StoreMixin):
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")
return False
if type_ not in ("groupchat", "chat"):
log.debug("unhandled message type %s" % mess)
if (mess.is_direct and frm == self.bot_identifier) or (mess.is_group and frm.nick == self.bot_config.CHATROOM_FN):
log.debug("Ignoring message from self")
return False
if (frm.person == self.bot_identifier.person or
type_ == "groupchat" and mess.frm.nick == self.bot_config.CHATROOM_FN): # noqa
log.debug("Ignoring message from self")
return False
log.debug("*** frm = %s" % frm)
log.debug("*** username = %s" % username)
log.debug("*** type = %s" % type_)
log.debug("*** text = %s" % text)
suppress_cmd_not_found = self.bot_config.SUPPRESS_CMD_NOT_FOUND
......@@ -267,7 +261,7 @@ class ErrBot(Backend, StoreMixin):
l = len(sep)
if text[:l] == sep:
text = text[l:]
elif type_ == "chat" and self.bot_config.BOT_PREFIX_OPTIONAL_ON_CHAT:
elif mess.is_direct and self.bot_config.BOT_PREFIX_OPTIONAL_ON_CHAT:
log.debug("Assuming '%s' to be a command because BOT_PREFIX_OPTIONAL_ON_CHAT is True" % text)
# In order to keep noise down we surpress messages about the command
# not being found, because it's possible a plugin will trigger on what
......@@ -314,7 +308,7 @@ class ErrBot(Backend, StoreMixin):
# Try to match one of the regex commands if the regular commands produced no match
matched_on_re_command = False
if not cmd:
if prefixed or (type_ == "chat" and self.bot_config.BOT_PREFIX_OPTIONAL_ON_CHAT):
if prefixed or (mess.is_direct and self.bot_config.BOT_PREFIX_OPTIONAL_ON_CHAT):
commands = self.re_commands
else:
commands = {k: self.re_commands[k] for k in self.re_commands
......
......@@ -11,7 +11,7 @@ import re # noqa
from queue import Queue, Empty # noqa
from mock import patch # noqa
from errbot.errBot import ErrBot
from errbot.backends.base import Message, MUCRoom, Identifier, ONLINE
from errbot.backends.base import Message, Room, Identifier, ONLINE
from errbot.backends.test import TestIdentifier, TestMUCOccupant
from errbot import botcmd, re_botcmd, arg_botcmd, templating # noqa
from errbot.main import CORE_STORAGE
......@@ -49,7 +49,7 @@ class DummyBackend(ErrBot):
def prefix_groupchat_reply(self, message: Message, identifier: Identifier):
pass
def query_room(self, room: str) -> MUCRoom:
def query_room(self, room: str) -> Room:
pass
def __init__(self, extra_config=None):
......@@ -350,7 +350,7 @@ class BotCmds(unittest.TestCase):
def setUp(self):
self.dummy = DummyBackend()
def makemessage(self, message, from_=None, to=None, type="chat"):
def makemessage(self, message, from_=None, to=None):
if not from_:
from_ = self.dummy.build_identifier("noterr")
if not to:
......@@ -358,7 +358,6 @@ class BotCmds(unittest.TestCase):
m = self.dummy.build_message(message)
m.frm = from_
m.to = to
m.type = type
return m
def test_inject_skips_methods_without_botcmd_decorator(self):
......@@ -568,32 +567,32 @@ class BotCmds(unittest.TestCase):
expected_response="Regular command"
),
dict(
message=self.makemessage("!command", type="groupchat", from_=TestMUCOccupant("someone", "room")),
message=self.makemessage("!command", from_=TestMUCOccupant("someone", "room")),
acl={'command': {'allowrooms': ('room',)}},
expected_response="Regular command"
),
dict(
message=self.makemessage("!command", type="groupchat", from_=TestMUCOccupant("someone", "room_1")),
message=self.makemessage("!command", from_=TestMUCOccupant("someone", "room_1")),
acl={'command': {'allowrooms': ('room_*',)}},
expected_response="Regular command"
),
dict(
message=self.makemessage("!command", type="groupchat", from_=TestMUCOccupant("someone", "room")),
message=self.makemessage("!command", from_=TestMUCOccupant("someone", "room")),
acl={'command': {'allowrooms': ('anotherroom@localhost',)}},
expected_response="You're not allowed to access this command from this room",
),
dict(
message=self.makemessage("!command", type="groupchat", from_=TestMUCOccupant("someone", "room")),
message=self.makemessage("!command", from_=TestMUCOccupant("someone", "room")),
acl={'command': {'denyrooms': ('room',)}},
expected_response="You're not allowed to access this command from this room",
),
dict(
message=self.makemessage("!command", type="groupchat", from_=TestMUCOccupant("someone", "room")),
message=self.makemessage("!command", from_=TestMUCOccupant("someone", "room")),
acl={'command': {'denyrooms': ('*',)}},
expected_response="You're not allowed to access this command from this room",
),
dict(