How to use ehforwarderbot - 10 common examples

To help you get started, we’ve selected a few ehforwarderbot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github blueset / ehForwarderBot / tests / mocks / master.py View on Github external
from logging import getLogger

from ehforwarderbot import EFBChannel, EFBMsg, EFBStatus, ChannelType, MsgType, coordinator, EFBChat
from ehforwarderbot.message import EFBMsgLinkAttribute, EFBMsgLocationAttribute
from ehforwarderbot.status import EFBMessageRemoval
from ehforwarderbot.types import ModuleID, MessageID
from ehforwarderbot.types import ChatID


class MockMasterChannel(EFBChannel):

    channel_name: str = "Mock Master"
    channel_emoji: str = "➕"
    channel_id: ModuleID = ModuleID("tests.mocks.master.MockMasterChannel")
    channel_type: ChannelType = ChannelType.Master
    supported_message_types: Set[MsgType] = {MsgType.Text, MsgType.Link}
    __version__: str = '0.0.1'

    logger = getLogger(channel_id)

    polling = threading.Event()

    def poll(self):
        self.polling.wait()

    def send_status(self, status: EFBStatus):
        self.logger.debug("Received status: %r", status)

    def send_message(self, msg: EFBMsg) -> EFBMsg:
        self.logger.debug("Received message: %r", msg)
        return msg
github blueset / ehForwarderBot / tests / base_class.py View on Github external
def setup(tmp_path):
    temp_dir = tmp_path
    os.environ['EFB_DATA_PATH'] = str(temp_dir)
    config_path = ehforwarderbot.utils.get_config_path()
    config = {
        "master_channel": "tests.mocks.master.MockMasterChannel",
        "slave_channels": ["tests.mocks.slave.MockSlaveChannel"],
        "middlewares": ["tests.mocks.middleware.MockMiddleware"]
    }
    with open(config_path, 'w') as f:
        yaml.dump(config, f)
    config = ehforwarderbot.config.load_config()
    ehforwarderbot.__main__.init(config)
    assert coordinator.master.channel_id == master.MockMasterChannel.channel_id
    assert slave.MockSlaveChannel.channel_id in coordinator.slaves
    assert coordinator.middlewares[0].middleware_id == middleware.MockMiddleware.middleware_id
github blueset / ehForwarderBot / tests / test_channel_loading.py View on Github external
os.environ['EFB_DATA_PATH'] = f

        master_id = "tests.mocks.master.MockMasterChannel#instance1"
        slave_ids = [
            "tests.mocks.slave.MockSlaveChannel#instance1",
            "tests.mocks.slave.MockSlaveChannel#instance2"
        ]

        config = {
            "master_channel": master_id,
            "slave_channels": slave_ids
        }
        config = dump_and_load_config(config)
        ehforwarderbot.__main__.init(config)

        assert coordinator.master.channel_id == master_id
        assert isinstance(coordinator.master, master.MockMasterChannel)
        for i in slave_ids:
            assert i in coordinator.slaves
            assert isinstance(coordinator.slaves[i], slave.MockSlaveChannel)
github blueset / ehForwarderBot / tests / test_channel_loading.py View on Github external
def test_custom_path_module_loading():
    with tempfile.TemporaryDirectory() as f:
        os.environ['EFB_DATA_PATH'] = f
        modules_path = ehforwarderbot.utils.get_custom_modules_path()
        config = {
            "master_channel": "master.MockMasterChannel",
            "slave_channels": ["slave.MockSlaveChannel",
                               "slave.MockSlaveChannel#instance"],
            "middlewares": ["middleware.MockMiddleware",
                            "middleware.MockMiddleware#instance"]
        }
        test_path: Path = Path(inspect.getfile(inspect.currentframe())).parent / 'mocks'
        # noinspection PyTypeChecker
        shutil.copy(test_path / 'master.py', modules_path)
        # noinspection PyTypeChecker
        shutil.copy(test_path / 'slave.py', modules_path)
        # noinspection PyTypeChecker
        shutil.copy(test_path / 'middleware.py', modules_path)
        config = dump_and_load_config(config)
        ehforwarderbot.__main__.init(config)
github blueset / ehForwarderBot / tests / base_class.py View on Github external
def setup(tmp_path):
    temp_dir = tmp_path
    os.environ['EFB_DATA_PATH'] = str(temp_dir)
    config_path = ehforwarderbot.utils.get_config_path()
    config = {
        "master_channel": "tests.mocks.master.MockMasterChannel",
        "slave_channels": ["tests.mocks.slave.MockSlaveChannel"],
        "middlewares": ["tests.mocks.middleware.MockMiddleware"]
    }
    with open(config_path, 'w') as f:
        yaml.dump(config, f)
    config = ehforwarderbot.config.load_config()
    ehforwarderbot.__main__.init(config)
    assert coordinator.master.channel_id == master.MockMasterChannel.channel_id
    assert slave.MockSlaveChannel.channel_id in coordinator.slaves
    assert coordinator.middlewares[0].middleware_id == middleware.MockMiddleware.middleware_id
github blueset / ehForwarderBot / tests / test_channel_loading.py View on Github external
"tests.mocks.slave.MockSlaveChannel#instance1",
            "tests.mocks.slave.MockSlaveChannel#instance2"
        ]

        config = {
            "master_channel": master_id,
            "slave_channels": slave_ids
        }
        config = dump_and_load_config(config)
        ehforwarderbot.__main__.init(config)

        assert coordinator.master.channel_id == master_id
        assert isinstance(coordinator.master, master.MockMasterChannel)
        for i in slave_ids:
            assert i in coordinator.slaves
            assert isinstance(coordinator.slaves[i], slave.MockSlaveChannel)
github blueset / ehForwarderBot / tests / mocks / master.py View on Github external
import threading
from typing import Set, Optional, IO, List
from logging import getLogger

from ehforwarderbot import EFBChannel, EFBMsg, EFBStatus, ChannelType, MsgType, coordinator, EFBChat
from ehforwarderbot.message import EFBMsgLinkAttribute, EFBMsgLocationAttribute
from ehforwarderbot.status import EFBMessageRemoval
from ehforwarderbot.types import ModuleID, MessageID
from ehforwarderbot.types import ChatID


class MockMasterChannel(EFBChannel):

    channel_name: str = "Mock Master"
    channel_emoji: str = "➕"
    channel_id: ModuleID = ModuleID("tests.mocks.master.MockMasterChannel")
    channel_type: ChannelType = ChannelType.Master
    supported_message_types: Set[MsgType] = {MsgType.Text, MsgType.Link}
    __version__: str = '0.0.1'

    logger = getLogger(channel_id)

    polling = threading.Event()

    def poll(self):
        self.polling.wait()

    def send_status(self, status: EFBStatus):
        self.logger.debug("Received status: %r", status)

    def send_message(self, msg: EFBMsg) -> EFBMsg:
        self.logger.debug("Received message: %r", msg)
github blueset / ehForwarderBot / tests / base_class.py View on Github external
def setup(tmp_path):
    temp_dir = tmp_path
    os.environ['EFB_DATA_PATH'] = str(temp_dir)
    config_path = ehforwarderbot.utils.get_config_path()
    config = {
        "master_channel": "tests.mocks.master.MockMasterChannel",
        "slave_channels": ["tests.mocks.slave.MockSlaveChannel"],
        "middlewares": ["tests.mocks.middleware.MockMiddleware"]
    }
    with open(config_path, 'w') as f:
        yaml.dump(config, f)
    config = ehforwarderbot.config.load_config()
    ehforwarderbot.__main__.init(config)
    assert coordinator.master.channel_id == master.MockMasterChannel.channel_id
    assert slave.MockSlaveChannel.channel_id in coordinator.slaves
    assert coordinator.middlewares[0].middleware_id == middleware.MockMiddleware.middleware_id
github blueset / ehForwarderBot / tests / mocks / master.py View on Github external
def send_text_msg(self):
        slave = next(iter(coordinator.slaves.values()))
        wonderland = slave.get_chat('wonderland001')
        msg = EFBMsg()
        msg.deliver_to = slave
        msg.chat = wonderland
        msg.author = EFBChat(self).self()
        msg.type = MsgType.Text
        msg.text = "Hello, world."
        return coordinator.send_message(msg)
github blueset / efb-telegram-master / tests / mocks / slave.py View on Github external
raise EFBMessageReactionNotPossible("Message reaction is rejected by flag.")
        if self.accept_message_reactions == "reject_all":
            raise EFBOperationNotSupported("All message reactions are rejected by flag.")
        message = self.messages_sent.get(status.msg_id)
        if message is None:
            raise EFBOperationNotSupported("Message is not found.")

        if status.reaction is None:
            for idx, i in message.reactions.items():
                message.reactions[idx] = [j for j in i if not isinstance(j, SelfChatMember)]
        else:
            if status.reaction not in message.reactions:
                message.reactions[status.reaction] = []
            message.reactions[status.reaction].append(message.chat.self)

        coordinator.send_status(MessageReactionsUpdate(
            chat=message.chat,
            msg_id=message.uid,
            reactions=message.reactions
        ))