当前位置: 首页>>代码示例>>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;未经允许,请勿转载。