Exemplo n.º 1
0
def dims_connect(terminal: Terminal, server: Server, messenger: ClientMessenger) -> Terminal:
    messenger.delegate = server
    messenger.terminal = terminal
    server.messenger = messenger
    # client
    terminal.messenger = messenger
    terminal.start(server=server)
    server.handshake()
    return terminal
Exemplo n.º 2
0
 def __get_client(self, identifier: ID) -> Terminal:
     client = self.__clients.get(identifier)
     if client is None:
         if identifier == g_station.identifier:
             messenger = g_messenger
             station = g_station
         else:
             messenger = OuterMessenger()
             # client for remote station
             station = load_station(identifier=identifier,
                                    facebook=messenger.facebook)
             assert isinstance(station,
                               Station), 'station error: %s' % identifier
         # create client for station with octopus and messenger
         client = Terminal()
         client.octopus = octopus
         dims_connect(terminal=client, messenger=messenger, server=station)
         self.__clients[identifier] = client
     return client
Exemplo n.º 3
0
def create_client(user: User) -> Terminal:
    client = Terminal()
    client.messenger = g_messenger
    # context
    client.messenger.context['database'] = g_database
    client.messenger.context['remote_address'] = (g_station.host, g_station.port)
    client.messenger.context['handshake_delegate'] = client
    # current user
    client.current_user = user
    # connect
    client.connect(station=g_station)
    client.handshake()
    return client
Exemplo n.º 4
0
 def login(self, identifier: ID):
     # logout first
     self.logout()
     # login with user ID
     facebook = g_messenger.facebook
     facebook.current_user = facebook.user(identifier=identifier)
     self.info('connecting to %s ...' % g_station)
     client = Terminal()
     dims_connect(terminal=client, messenger=g_messenger, server=g_station)
     self.client = client
     if self.receiver is None:
         self.receiver = g_station.identifier
Exemplo n.º 5
0
        #
        #  3. send Welcome!
        #
        text = self.__welcome(freshmen=freshmen)
        gm.send(content=text)
        self.info('Welcome sent to %s: %s' % (gid, text))

    def run(self):
        while True:
            time.sleep(30)
            self.info('try to scan freshmen ...')
            try:
                self.__run_unsafe()
            except Exception as error:
                self.error('scan freshmen error: %s' % error)


if __name__ == '__main__':

    # set current user
    facebook = g_messenger.facebook
    facebook.current_user = load_user(xiaoxiao_id, facebook=facebook)

    # create client and connect to the station
    client = Terminal()
    dims_connect(terminal=client, messenger=g_messenger, server=g_station)

    # start scanner
    scanner = FreshmenScanner(messenger=g_messenger)
    scanner.start()