コード例 #1
0
ファイル: connector.py プロジェクト: itsyaasir/opsdroid
    async def connect(self):
        """Create connection object with chat library."""
        session = aiohttp.ClientSession(trust_env=True)
        mapi = AsyncHTTPAPI(self.homeserver, session)

        self.session = session
        login_response = await mapi.login("m.login.password",
                                          user=self.mxid,
                                          password=self.password)
        mapi.token = login_response["access_token"]
        mapi.sync_token = None

        for roomname, room in self.rooms.items():
            response = await mapi.join_room(room)
            self.room_ids[roomname] = response["room_id"]
        self.connection = mapi

        # Create a filter now, saves time on each later sync
        self.filter_id = await self.make_filter(mapi, self.room_ids.values())

        # Do initial sync so we don't get old messages later.
        response = await self.connection.sync(
            timeout_ms=3000,
            filter='{ "room": { "timeline" : { "limit" : 1 } } }',
            set_presence="online",
        )
        self.connection.sync_token = response["next_batch"]

        if self.nick:
            display_name = await self.connection.get_display_name(self.mxid)
            if display_name != self.nick:
                await self.connection.set_display_name(self.mxid, self.nick)
コード例 #2
0
ファイル: connector.py プロジェクト: opsdroid/opsdroid
    async def connect(self):
        """Create connection object with chat library."""
        session = aiohttp.ClientSession()
        mapi = AsyncHTTPAPI(self.homeserver, session)

        self.session = session
        login_response = await mapi.login(
            "m.login.password", user=self.mxid, password=self.password)
        mapi.token = login_response['access_token']
        mapi.sync_token = None

        for roomname, room in self.rooms.items():
            response = await mapi.join_room(room)
            self.room_ids[roomname] = response['room_id']
        self.connection = mapi

        # Create a filter now, saves time on each later sync
        self.filter_id = await self.make_filter(mapi, self.room_ids.values())

        # Do initial sync so we don't get old messages later.
        response = await self.connection.sync(
            timeout_ms=3000,
            filter='{ "room": { "timeline" : { "limit" : 1 } } }',
            set_presence="online")
        self.connection.sync_token = response["next_batch"]

        if self.nick:
            display_name = await self.connection.get_display_name(self.mxid)
            if display_name != self.nick:
                await self.connection.set_display_name(self.mxid, self.nick)