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


TypeScript RoomBridgeStore.upsertEntry方法代碼示例

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


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

示例1: ApplyStateToChannel

    private async ApplyStateToChannel(channelsState: IChannelState) {
        const intent = this.bridge.getIntent();
        for (const channelState of channelsState.mxChannels) {
            let roomUpdated = false;
            const remoteRoom = (await this.roomStore.getEntriesByMatrixId(channelState.mxid))[0];
            if (channelState.name !== null) {
                log.verbose(`Updating channelname for ${channelState.mxid} to "${channelState.name}"`);
                await intent.setRoomName(channelState.mxid, channelState.name);
                remoteRoom.remote.set("discord_name", channelState.name);
                roomUpdated = true;
            }

            if (channelState.topic !== null) {
                log.verbose(`Updating channeltopic for ${channelState.mxid} to "${channelState.topic}"`);
                await intent.setRoomTopic(channelState.mxid, channelState.topic);
                remoteRoom.remote.set("discord_topic", channelState.topic);
                roomUpdated = true;
            }

            if (channelState.iconUrl !== null && channelState.iconId !== null) {
                log.verbose(`Updating icon_url for ${channelState.mxid} to "${channelState.iconUrl}"`);
                if (channelsState.iconMxcUrl === null) {
                    const iconMxc = await Util.UploadContentFromUrl(
                        channelState.iconUrl,
                        intent,
                        channelState.iconId,
                    );
                    channelsState.iconMxcUrl = iconMxc.mxcUrl;
                }
                await intent.setRoomAvatar(channelState.mxid, channelsState.iconMxcUrl);
                remoteRoom.remote.set("discord_iconurl", channelState.iconUrl);
                remoteRoom.remote.set("discord_iconurl_mxc", channelsState.iconMxcUrl);
                roomUpdated = true;
            }

            if (channelState.removeIcon) {
                log.verbose(`Clearing icon_url for ${channelState.mxid}`);
                await intent.setRoomAvatar(channelState.mxid, null);
                remoteRoom.remote.set("discord_iconurl", null);
                remoteRoom.remote.set("discord_iconurl_mxc", null);
                roomUpdated = true;
            }

            if (roomUpdated) {
                await this.roomStore.upsertEntry(remoteRoom);
            }
        }
    }
開發者ID:Half-Shot,項目名稱:matrix-appservice-discord,代碼行數:48,代碼來源:channelsyncroniser.ts

示例2: handleChannelDeletionForRoom

    private async handleChannelDeletionForRoom(
        channel: Discord.TextChannel,
        roomId: string,
        entry: Entry): Promise<void> {
        log.info(`Deleting ${channel.id} from ${roomId}.`);
        const intent = await this.bridge.getIntent();
        const options = this.config.channel.deleteOptions;
        const plumbed = entry.remote.get("plumbed");

        this.roomStore.upsertEntry(entry);
        if (options.ghostsLeave) {
            for (const member of channel.members.array()) {
                try {
                    const mIntent = await this.bot.GetIntentFromDiscordMember(member);
                    mIntent.leave(roomId);
                    log.info(`${member.id} left ${roomId}.`);
                } catch (e) {
                    log.warn(`Failed to make ${member.id} leave `);
                }
            }
        }
        if (options.namePrefix) {
            try {
                const name = await intent.getClient().getStateEvent(roomId, "m.room.name");
                name.name = options.namePrefix + name.name;
                await intent.getClient().setRoomName(roomId, name.name);
            } catch (e) {
                log.error(`Failed to set name of room ${roomId} ${e}`);
            }
        }
        if (options.topicPrefix) {
            try {
                const topic = await intent.getClient().getStateEvent(roomId, "m.room.topic");
                topic.topic = options.topicPrefix + topic.topic;
                await intent.getClient().setRoomTopic(roomId, topic.topic);
            } catch (e) {
                log.error(`Failed to set topic of room ${roomId} ${e}`);
            }
        }

        if (plumbed !== true) {
            if (options.unsetRoomAlias) {
                try {
                    const alias = `#_${entry.remote.roomId}:${this.config.bridge.domain}`;
                    const canonicalAlias = await intent.getClient().getStateEvent(roomId, "m.room.canonical_alias");
                    if (canonicalAlias.alias === alias) {
                        await intent.getClient().sendStateEvent(roomId, "m.room.canonical_alias", {});
                    }
                    await intent.getClient().deleteAlias(alias);
                } catch (e) {
                    log.error(`Couldn't remove alias of ${roomId} ${e}`);
                }
            }

            if (options.unlistFromDirectory) {
                try {
                    await intent.getClient().setRoomDirectoryVisibility(roomId, "private");
                } catch (e) {
                    log.error(`Couldn't remove ${roomId} from room directory ${e}`);
                }

            }

            if (options.setInviteOnly) {
                try {
                    await intent.getClient().sendStateEvent(roomId, "m.room.join_rules", {join_role: "invite"});
                } catch (e) {
                    log.error(`Couldn't set ${roomId} to private ${e}`);
                }
            }

            if (options.disableMessaging) {
                try {
                    const state = await intent.getClient().getStateEvent(roomId, "m.room.power_levels");
                    state.events_default = POWER_LEVEL_MESSAGE_TALK;
                    await intent.getClient().sendStateEvent(roomId, "m.room.power_levels", state);
                } catch (e) {
                    log.error(`Couldn't disable messaging for ${roomId} ${e}`);
                }
            }
        }
        // Unlist

        // Remove entry
        await this.roomStore.removeEntriesByMatrixRoomId(roomId);
    }
開發者ID:Half-Shot,項目名稱:matrix-appservice-discord,代碼行數:86,代碼來源:channelsyncroniser.ts


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