コード例 #1
0
    def setUp(self):
        self.reserves = []
        self.strings = RuReserve

        self.chat = Chat()
        self.chat.id = 101
        self.user = User()
        self.user.first_name = "Firstname"
        self.user.id = 111

        dp = Dispatcher()
        self.data_adapter = MemoryDataAdapter()
        self.state_manager = StateManager(self.data_adapter)
        self.processor = ReserveProcessor(dp, self.state_manager, self.strings)

        message = Message()
        message.chat = self.chat
        message.from_user = self.user
        message.message_id = 121
        message.text = "Some text"
        message.answer = self.answer_mock
        message.delete = self.delete_mock
        message.edit_text = self.edit_text_mock
        self.test_message = message

        callback = CallbackQuery()
        callback.bot = Bot()
        callback.answer = self.callback_answer_mock
        callback.message = message
        callback.from_user = User()
        callback.from_user.id = 101
        self.test_callback_query = callback
コード例 #2
0
    def bg(
        self,
        user_id: Optional[int] = None,
        chat_id: Optional[int] = None,
        stack_id: Optional[str] = None,
    ) -> "BaseDialogManager":
        if user_id is not None:
            user = User(id=user_id)
        else:
            user = self.user
        if chat_id is not None:
            chat = Chat(id=chat_id)
        else:
            chat = self.chat

        same_chat = (user.id == self.user.id and chat.id == self.chat.id)
        if stack_id is None:
            if same_chat:
                stack_id = self.stack_id
                intent_id = self.intent_id
            else:
                stack_id = DEFAULT_STACK_ID
                intent_id = None
        else:
            intent_id = None

        return BgManager(
            user=user,
            chat=chat,
            bot=self.bot,
            registry=self.registry,
            intent_id=intent_id,
            stack_id=stack_id,
        )
コード例 #3
0
    def bg(
        self,
        user_id: Optional[int] = None,
        chat_id: Optional[int] = None,
        stack_id: Optional[str] = None,
    ) -> "BaseDialogManager":
        if user_id is not None:
            user = User(id=user_id)
        else:
            user = self.event.from_user
        if chat_id is not None:
            chat = Chat(id=chat_id)
        else:
            chat = get_chat(self.event)

        same_chat = (user.id == self.event.from_user.id
                     and chat.id == get_chat(self.event).id)
        intent_id = None
        if stack_id is None:
            if same_chat:
                stack_id = self.current_stack().id
                if self.current_context():
                    intent_id = self.current_context().id
            else:
                stack_id = DEFAULT_STACK_ID
        return BgManager(
            user=user,
            chat=chat,
            bot=self.event.bot,
            registry=self.registry,
            intent_id=intent_id,
            stack_id=stack_id,
        )
コード例 #4
0
    def bg(self,
           user_id: Optional[int] = None,
           chat_id: Optional[int] = None) -> BgManagerProto:
        if self.disabled:
            raise IncorrectBackgroundError("Please call `manager.bg()` "
                                           "before starting background task")
        self.check_disabled()

        if user_id is not None:
            user = User(id=user_id)
        else:
            user = self.event.from_user
        if chat_id is not None:
            chat = Chat(id=chat_id)
        else:
            chat = get_chat(self.event)

        return BgManager(
            user,
            chat,
            self.event.bot,
            self.registry,
            self.current_intent(),
            self.context.state,
        )
コード例 #5
0
 async def check(self, obj: Union[Message, CallbackQuery]):
     if getattr(obj, "reply_to_message"):
         logger.info(obj.reply_to_message.from_user.id)
         if Chat.get_current().id == User.get_current().id:
             return True
     
     return False
コード例 #6
0
async def test_bot_status_awx(patched_bot, sub: Client, chat_id, target):
    await sub.subscribe(AWXApiSource.params().topic_in)
    await asyncio.sleep(.05)
    message_text = f'/status awx {target}'
    await patched_bot.handle_status(
        Message(text=message_text, chat=Chat(id=chat_id)))
    data = await sub.get(.1)
    assert data == f'{target};1'
コード例 #7
0
    def message(self, rand_user):
        c = TelegramChat()
        c.title = 'UnitTesting'
        u = TelegramUser()
        u.id = rand_user.id
        u.first_name = rand_user.first_name

        class _Message:
            def __init__(self, user, chat):
                self.from_user = user
                self.chat = chat

            @staticmethod
            async def reply(text):
                print(text)
                await asyncio.sleep(0)

        yield _Message(u, c)
コード例 #8
0
ファイル: t_state.py プロジェクト: alex13th/WakeBot
    def setUp(self):
        self.data_adapter = MemoryDataAdapter()
        self.state_provider.data_adapter = self.data_adapter

        self.chat = Chat()
        self.chat.id = 101
        self.user = User()
        self.user.id = 111

        state_data1 = {"state": "main", "state_type": "reserve"}
        state_data2 = {"state": "book", "state_type": "reserve"}
        self.data_adapter.append_data("101-111-121", state_data1)
        self.data_adapter.append_data("101-111-122", state_data2)
コード例 #9
0
    def bg(self,
           user_id: Optional[int] = None,
           chat_id: Optional[int] = None) -> BgManagerProto:
        if user_id is not None:
            user = User(id=user_id)
        else:
            user = self.user
        if chat_id is not None:
            chat = Chat(id=chat_id)
        else:
            chat = self.chat

        return BgManager(
            user,
            chat,
            self.bot,
            self.registry,
            self.current_intent(),
            self.current_state,
        )
コード例 #10
0
ファイル: storage.py プロジェクト: t2elzeth/truth-or-truth
 def chat(self):
     return Chat.get_current()
コード例 #11
0
ファイル: registry.py プロジェクト: Tishka17/aiogram_dialog
 async def _process_update(self, event: DialogUpdateEvent):
     Bot.set_current(event.bot)
     User.set_current(event.from_user)
     Chat.set_current(event.chat)
     await self.update_handler.notify(event)
コード例 #12
0
def message_stub(message_text, chat_id):
    return Message(text=message_text, chat=Chat(id=chat_id))