Python telepot 模块,delegate() 实例源码

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

项目:six_hack    作者:petr-tik    | 项目源码 | 文件源码
def __init__(self, token):
        self._seen = set()
        self._store = DBStore()  # Imagine a dictionary for storing amounts.

        super(ChatBox, self).__init__(token, [
            # Here is a delegate to specially handle owner commands.
            (per_chat_id(), create_open(TransferHandler, 60*5, self._store, self._seen)),
            (per_chat_id(), create_open(OwnerHandler, 60*5, self._store, self._seen)),
            (per_chat_id(), create_open(FirstTimeHandler, 60*5, self._store, self._seen))
            # For senders never seen before, send him a welcome message.
            # (self._is_newcomer, custom_thread(call(self._send_welcome))),
        ])

    # seed-calculating function: use returned value to indicate whether to spawn a delegate
项目:six_hack    作者:petr-tik    | 项目源码 | 文件源码
def _is_newcomer(self, msg):
        chat_id = msg['chat']['id']

        if chat_id in self._seen:  # Sender has been seen before
            return None  # No delegate spawned

        self._seen.add(chat_id)
        return []  # non-hashable ==> delegates are independent, no seed association is made.