我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用telepot.delegate()。
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
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.