當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript matrix-appservice-bridge.Intent類代碼示例

本文整理匯總了TypeScript中matrix-appservice-bridge.Intent的典型用法代碼示例。如果您正苦於以下問題:TypeScript Intent類的具體用法?TypeScript Intent怎麽用?TypeScript Intent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Intent類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: UploadContentFromUrl

    /**
     * uploadContentFromUrl - Upload content from a given URL to the homeserver
     * and return a MXC URL.
     */
    public static async UploadContentFromUrl(url: string, intent: Intent, name: string | null): Promise<IUploadResult> {
        let contenttype;
        name = name || null;
        try {
            const bufferRet = (await (new Promise((resolve, reject) => {
                let ht;
                if (url.startsWith("https")) {
                    ht = https;
                } else {
                    ht = http;
                }
                const req = ht.get( url, (res) => {
                    let buffer = Buffer.alloc(0);

                    if (res.headers.hasOwnProperty("content-type")) {
                        contenttype = res.headers["content-type"];
                    } else {
                        log.verbose("No content-type given by server, guessing based on file name.");
                        contenttype = mime.lookup(url);
                    }

                    if (name === null) {
                        const names = url.split("/");
                        name = names[names.length - 1];
                    }

                    res.on("data", (d) => {
                        buffer = Buffer.concat([buffer, d]);
                    });

                    res.on("end", () => {
                        resolve(buffer);
                    });
                });
                req.on("error", (err) => {
                    reject(`Failed to download. ${err.code}`);
                });
            }))) as Buffer;
            const size = bufferRet.length;
            const contentUri = await intent.getClient().uploadContent(bufferRet, {
                name,
                onlyContentUri: true,
                rawResponse: false,
                type: contenttype,
            });
            log.verbose("Media uploaded to ", contentUri);
            return {
                mxcUrl: contentUri,
                size,
            };
        } catch (reason) {
            log.error("Failed to upload content:\n", reason);
            throw reason;
        }
    }
開發者ID:Half-Shot,項目名稱:matrix-appservice-discord,代碼行數:59,代碼來源:util.ts

示例2: GetMxidFromName

 public static async GetMxidFromName(intent: Intent, name: string, channelMxids: string[]) {
     if (name[0] === "@" && name.includes(":")) {
         return name;
     }
     const client = intent.getClient();
     const matrixUsers = {};
     let matches = 0;
     await Promise.all(channelMxids.map((chan) => {
         // we would use this.bridge.getBot().getJoinedMembers()
         // but we also want to be able to search through banned members
         // so we gotta roll our own thing
         return client._http.authedRequestWithPrefix(
             undefined,
             "GET",
             `/rooms/${encodeURIComponent(chan)}/members`,
             undefined,
             undefined,
             "/_matrix/client/r0",
         ).then((res) => {
             res.chunk.forEach((member) => {
                 if (member.membership !== "join" && member.membership !== "ban") {
                     return;
                 }
                 const mxid = member.state_key;
                 if (mxid.startsWith("@_discord_")) {
                     return;
                 }
                 let displayName = member.content.displayname;
                 if (!displayName && member.unsigned && member.unsigned.prev_content &&
                     member.unsigned.prev_content.displayname) {
                     displayName = member.unsigned.prev_content.displayname;
                 }
                 if (!displayName) {
                     displayName = mxid.substring(1, mxid.indexOf(":"));
                 }
                 if (name.toLowerCase() === displayName.toLowerCase() || name === mxid) {
                     matrixUsers[mxid] = displayName;
                     matches++;
                 }
             });
         });
     }));
     if (matches === 0) {
         throw Error(`No users matching ${name} found`);
     }
     if (matches > 1) {
         let errStr = "Multiple matching users found:\n";
         for (const mxid of Object.keys(matrixUsers)) {
             errStr += `${matrixUsers[mxid]} (\`${mxid}\`)\n`;
         }
         throw Error(errStr);
     }
     return Object.keys(matrixUsers)[0];
 }
開發者ID:Half-Shot,項目名稱:matrix-appservice-discord,代碼行數:54,代碼來源:util.ts

示例3: run

async function run() {
    try {
        await intent.setPowerLevel(options.roomid, options.userid, options.power);
        console.log("Power levels set");
        process.exit(0);
    } catch (err) {
        console.error("Could not apply power levels to room:", err);
        process.exit(1);
    }
}
開發者ID:Half-Shot,項目名稱:matrix-appservice-discord,代碼行數:10,代碼來源:adminme.ts


注:本文中的matrix-appservice-bridge.Intent類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。