Python telegram 模块,Chat() 实例源码

我们从Python开源项目中,提取了以下14个代码示例,用于说明如何使用telegram.Chat()

项目:eddie    作者:greenkey    | 项目源码 | 文件源码
def create_telegram_update(message_text):
    """ Helper function: create an "Update" to simulate a message sent to the
        Telegram bot.
    """
    from datetime import datetime
    message = telegram.Message(
        message_id=0,
        from_user=telegram.User(0, 'greenkey'),
        date=datetime.now(),
        chat=telegram.Chat(0, ''),
        text=message_text
    )

    return telegram.Update(
        update_id=0,
        message=message
    )
项目:ownbot    作者:michaelimfeld    | 项目源码 | 文件源码
def __get_dummy_update():
        """Returns a dummy update instance"""
        user = User(1337, "@foouser")
        chat = Chat(1, None)
        message = Message(1, user, datetime.now(), chat)
        return Update(1, message=message)
项目:ownbot    作者:michaelimfeld    | 项目源码 | 文件源码
def __get_dummy_update():
        """Returns a dummy update instance"""
        user = User(1337, "@foouser")
        chat = Chat(1, None)
        message = Message(1, user, datetime.now(), chat)
        return Update(1, message=message)
项目:telebot    作者:DronMDF    | 项目源码 | 文件源码
def __init__(self, chat_id):
        super().__init__(
            chat=Chat(id=chat_id, type='private'),
            message_id=1,
            from_user=User(
                id=1,
                first_name='Test',
                is_bot=False
            ),
            date=1
        )
项目:telebot    作者:DronMDF    | 项目源码 | 文件源码
def __init__(self, text):
        super().__init__(
            chat=telegram.Chat(id=1, type='private'),
            message_id=1,
            from_user=telegram.User(
                id=1,
                first_name='Test',
                is_bot=False
            ),
            date=1,
            text=text,
        )
项目:freqtrade    作者:gcarq    | 项目源码 | 文件源码
def test_authorized_only(default_conf, mocker):
    mocker.patch.dict('freqtrade.rpc.telegram._CONF', default_conf)

    chat = Chat(0, 0)
    update = Update(randint(1, 100))
    update.message = Message(randint(1, 100), 0, datetime.utcnow(), chat)
    state = {'called': False}

    @authorized_only
    def dummy_handler(*args, **kwargs) -> None:
        state['called'] = True

    dummy_handler(MagicMock(), update)
    assert state['called'] is True
项目:freqtrade    作者:gcarq    | 项目源码 | 文件源码
def test_authorized_only_unauthorized(default_conf, mocker):
    mocker.patch.dict('freqtrade.rpc.telegram._CONF', default_conf)

    chat = Chat(0xdeadbeef, 0)
    update = Update(randint(1, 100))
    update.message = Message(randint(1, 100), 0, datetime.utcnow(), chat)
    state = {'called': False}

    @authorized_only
    def dummy_handler(*args, **kwargs) -> None:
        state['called'] = True

    dummy_handler(MagicMock(), update)
    assert state['called'] is False
项目:freqtrade    作者:gcarq    | 项目源码 | 文件源码
def test_authorized_only_exception(default_conf, mocker):
    mocker.patch.dict('freqtrade.rpc.telegram._CONF', default_conf)

    update = Update(randint(1, 100))
    update.message = Message(randint(1, 100), 0, datetime.utcnow(), Chat(0, 0))

    @authorized_only
    def dummy_handler(*args, **kwargs) -> None:
        raise Exception('test')

    dummy_handler(MagicMock(), update)
项目:freqtrade    作者:gcarq    | 项目源码 | 文件源码
def update():
    _update = Update(0)
    _update.message = Message(0, 0, datetime.utcnow(), Chat(0, 0))
    return _update
项目:mau_mau_bot    作者:jh0ker    | 项目源码 | 文件源码
def setUp(self):
        self.gm = GameManager()

        self.chat0 = Chat(0, 'group')
        self.chat1 = Chat(1, 'group')
        self.chat2 = Chat(2, 'group')

        self.user0 = User(0, 'user0')
        self.user1 = User(1, 'user1')
        self.user2 = User(2, 'user2')
项目:voiceru_bot    作者:just806me    | 项目源码 | 文件源码
def from_db(db: MongoClient, chat: Chat, admin_id: int = None, admin_name: str = None):
        from_db = db.find_one({'_id': chat.id})

        if from_db:
            return ChatSettings.from_dict(from_db)
        else:
            return ChatSettings(db, chat, admin_id=admin_id, admin_name=admin_name)
项目:HashDigestBot    作者:wagnerluis1982    | 项目源码 | 文件源码
def __init__(self, id, text, chat_id, reply_id=None):
        from_user = telegram.User(
            id=1, first_name="He", last_name="Man", username="heman")
        reply_to_user = telegram.User(
            id=2, first_name="She", last_name="Ra", username="shera")
        chat = telegram.Chat(id=chat_id, type="group")
        reply_to_message = reply_id and telegram.Message(reply_id, reply_to_user, None, chat)
        super().__init__(
            message_id=id,
            date=datetime.now(),
            text=text,
            chat=chat,
            from_user=from_user,
            reply_to_message=reply_to_message,
        )
项目:spin_everyday_bot    作者:evgfilim1    | 项目源码 | 文件源码
def auto_spin(bot: Bot, job: Job):
    from telegram import Message, Chat
    u = Update(0, message=Message(0, None, 0, Chat(job.context, '')))
    if core.results_today.get(job.context) is None:
        do_the_spin(bot, u)
项目:voiceru_bot    作者:just806me    | 项目源码 | 文件源码
def __init__(self, db = None, chat: Chat = None, voice: Voice = Voice.ermil, speed: float = 1.0,
                 emotion: Emotion = Emotion.good, first_time: int = time(), active_time: int = 0,
                 active_time_inline: int = 0, as_audio: bool = False, mode: Mode = Mode.both, admin_id: int = None,
                 admin_name: str = None, admin_only: bool = False, quiet: bool = False, yandex_key: str = ''):
        if chat:
            self.id = chat.id

            if hasattr(chat, 'username') and chat.username:
                self.tg_name = chat.username
            elif hasattr(chat, 'title') and chat.title:
                self.tg_name = chat.title
            elif hasattr(chat, 'first_name') and chat.first_name:
                self.tg_name = chat.first_name
            else:
                self.tg_name = ''

            self.tg_name = self.tg_name

            self.voice = voice
            self.speed = speed
            self.emotion = emotion
            self.first_time = first_time
            self.active_time = active_time
            self.active_time_inline = active_time_inline
            self.as_audio = as_audio
            self.mode = mode
            self.admin_id = admin_id
            self.admin_name = admin_name if admin_name else None
            self.admin_only = admin_only
            self.quiet = quiet
            self.yandex_key = yandex_key
        else:
            self.id = None
            self.tg_name = None
            self.voice = None
            self.speed = None
            self.emotion = None
            self.first_time = None
            self.active_time = None
            self.active_time_inline = None
            self.as_audio = None
            self.mode = None
            self.admin_id = None
            self.admin_name = None
            self.admin_only = None
            self.quiet = None
            self.yandex_key = None
        if db:
            db.insert_one(self.to_dict())