当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Bridge.getRoomStore方法代码示例

本文整理汇总了TypeScript中matrix-appservice-bridge.Bridge.getRoomStore方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Bridge.getRoomStore方法的具体用法?TypeScript Bridge.getRoomStore怎么用?TypeScript Bridge.getRoomStore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matrix-appservice-bridge.Bridge的用法示例。


在下文中一共展示了Bridge.getRoomStore方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: GetRoomIdsFromGuild

 public async GetRoomIdsFromGuild(guild: Discord.Guild, member?: Discord.GuildMember): Promise<string[]> {
     if (member) {
         let rooms: string[] = [];
         await Util.AsyncForEach(guild.channels.array(), async (channel) => {
             if (channel.type !== "text" || !channel.members.has(member.id)) {
                 return;
             }
             try {
                 rooms = rooms.concat(await this.channelSync.GetRoomIdsFromChannel(channel));
             } catch (e) { } // no bridged rooms for this channel
         });
         if (rooms.length === 0) {
             log.verbose(`No rooms were found for this guild and member (guild:${guild.id} member:${member.id})`);
             throw new Error("Room(s) not found.");
         }
         return rooms;
     } else {
         const rooms = await this.bridge.getRoomStore().getEntriesByRemoteRoomData({
             discord_guild: guild.id,
         });
         if (rooms.length === 0) {
             log.verbose(`Couldn't find room(s) for guild id:${guild.id}.`);
             throw new Error("Room(s) not found.");
         }
         return rooms.map((room) => room.matrix.getId());
     }
 }
开发者ID:Half-Shot,项目名称:matrix-appservice-discord,代码行数:27,代码来源:bot.ts

示例2: run

async function run() {
    try {
        await bridge.loadDatabases();
    } catch (e) {
        log.error(`Failed to load database`, e);
    }

    let rooms = await bridge.getRoomStore().getEntriesByRemoteRoomData({
        discord_type: "text",
    });
    rooms = rooms.filter((r) => r.remote.get("plumbed") !== true );
    const client = clientFactory.getClientAs();
    log.info(`Got ${rooms.length} rooms to set`);
    try {
        await Util.AsyncForEach(rooms, async (room) => {
            const guild = room.remote.get("discord_guild");
            const roomId = room.matrix.getId();
            try {
                await client.setRoomDirectoryVisibilityAppService(
                    guild,
                    roomId,
                    "public",
                );
                log.info(`Set ${roomId} to visible in ${guild}'s directory`);
            } catch (e) {
                log.error(`Failed to set ${roomId} to visible in ${guild}'s directory`, e);
            }
        });
    } catch (e) {
        log.error(`Failed to run script`, e);
    }
}
开发者ID:Half-Shot,项目名称:matrix-appservice-discord,代码行数:32,代码来源:addRoomsToDirectory.ts

示例3:

 mxRoomEntries.forEach((entry) => {
     if (entry.remote.get("plumbed")) {
         return; // skipping plumbed rooms
     }
     const updateIcon = entry.remote.get("update_icon");
     if (updateIcon !== undefined && updateIcon !== null) {
         return; // skipping because something was set manually
     }
     entry.remote.set("update_icon", true);
     promiseList.push(bridge.getRoomStore().upsertEntry(entry));
 });
开发者ID:Half-Shot,项目名称:matrix-appservice-discord,代码行数:11,代码来源:chanfix.ts

示例4: run

async function run() {
    try {
        await bridge.loadDatabases();
    } catch (e) {
        await discordstore.init();
    }
    bridge._clientFactory = clientFactory;
    bridge._botClient = bridge._clientFactory.getClientAs();
    bridge._botIntent = new Intent(bridge._botClient, bridge._botClient, { registered: true });
    await discordbot.ClientFactory.init();
    const client = await discordbot.ClientFactory.getClient();

    // first set update_icon to true if needed
    const mxRoomEntries = await bridge.getRoomStore().getEntriesByRemoteRoomData({
        update_name: true,
        update_topic: true,
    });

    const promiseList: Promise<void>[] = [];
    mxRoomEntries.forEach((entry) => {
        if (entry.remote.get("plumbed")) {
            return; // skipping plumbed rooms
        }
        const updateIcon = entry.remote.get("update_icon");
        if (updateIcon !== undefined && updateIcon !== null) {
            return; // skipping because something was set manually
        }
        entry.remote.set("update_icon", true);
        promiseList.push(bridge.getRoomStore().upsertEntry(entry));
    });
    await Promise.all(promiseList);

    // now it is time to actually run the updates
    const promiseList2: Promise<void>[] = [];

    let curDelay = config.limits.roomGhostJoinDelay; // we'll just re-use this
    client.guilds.forEach((guild) => {
        promiseList2.push((async () => {
            await Bluebird.delay(curDelay);
            try {
                await discordbot.ChannelSyncroniser.OnGuildUpdate(guild, true);
            } catch (err) {
                log.warn(`Couldn't update rooms of guild ${guild.id}`, err);
            }
        })());
        curDelay += config.limits.roomGhostJoinDelay;
    });
    try {
        await Promise.all(promiseList2);
    } catch (err) {
        log.error(err);
    }
    process.exit(0);
}
开发者ID:Half-Shot,项目名称:matrix-appservice-discord,代码行数:54,代码来源:chanfix.ts

示例5: GetRoomIdsFromChannel

 public async GetRoomIdsFromChannel(channel: Discord.Channel): Promise<string[]> {
     if (!this.roomStore) {
         this.roomStore = this.bridge.getRoomStore();
     }
     const rooms = await this.roomStore.getEntriesByRemoteRoomData({
         discord_channel: channel.id,
     });
     if (rooms.length === 0) {
         log.verbose(`Couldn't find room(s) for channel ${channel.id}.`);
         return Promise.reject("Room(s) not found.");
     }
     return rooms.map((room) => room.matrix.getId() as string);
 }
开发者ID:Half-Shot,项目名称:matrix-appservice-discord,代码行数:13,代码来源:channelsyncroniser.ts

示例6: GetChannelFromRoomId

    public async GetChannelFromRoomId(roomId: string, client?: Discord.Client): Promise<Discord.Channel> {
        const entries = await this.bridge.getRoomStore().getEntriesByMatrixId(
            roomId,
        );

        if (!client) {
            client = this.bot;
        }

        if (entries.length === 0) {
            log.verbose(`Couldn"t find channel for roomId ${roomId}.`);
            throw Error("Room(s) not found.");
        }
        const entry = entries[0];
        const guild = client.guilds.get(entry.remote.get("discord_guild"));
        if (guild) {
            const channel = client.channels.get(entry.remote.get("discord_channel"));
            if (channel) {
                return channel;
            }
            throw Error("Channel given in room entry not found");
        }
        throw Error("Guild given in room entry not found");
    }
开发者ID:Half-Shot,项目名称:matrix-appservice-discord,代码行数:24,代码来源:bot.ts

示例7: constructor

 constructor(
     private bridge: Bridge,
     private config: DiscordBridgeConfig,
     private bot: DiscordBot) {
     this.roomStore = this.bridge.getRoomStore();
 }
开发者ID:Half-Shot,项目名称:matrix-appservice-discord,代码行数:6,代码来源:channelsyncroniser.ts

示例8: GetChannelUpdateState

    public async GetChannelUpdateState(channel: Discord.TextChannel, forceUpdate = false): Promise<IChannelState> {
        log.verbose(`State update request for ${channel.id}`);
        const channelState: IChannelState = Object.assign({}, DEFAULT_CHANNEL_STATE, {
            id: channel.id,
            mxChannels: [],
        });

        if (!this.roomStore) {
            this.roomStore = this.bridge.getRoomStore();
        }
        const remoteRooms = await this.roomStore.getEntriesByRemoteRoomData({discord_channel: channel.id});
        if (remoteRooms.length === 0) {
            log.verbose(`Could not find any channels in room store.`);
            return channelState;
        }

        const patternMap = {
            guild: channel.guild.name,
            name: "#" + channel.name,
        };
        let name: string = this.config.channel.namePattern;
        for (const p of Object.keys(patternMap)) {
            name = name.replace(new RegExp(":" + p, "g"), patternMap[p]);
        }
        const topic = channel.topic;
        const icon = channel.guild.icon;
        let iconUrl: string | null = null;
        if (icon) {
            iconUrl = `https://cdn.discordapp.com/icons/${channel.guild.id}/${icon}.png`;
        }
        remoteRooms.forEach((remoteRoom) => {
            const mxid = remoteRoom.matrix.getId();
            const singleChannelState: ISingleChannelState = Object.assign({}, DEFAULT_SINGLECHANNEL_STATE, {
                mxid,
            });

            const oldName = remoteRoom.remote.get("discord_name");
            if (remoteRoom.remote.get("update_name") && (forceUpdate || oldName !== name)) {
                log.verbose(`Channel ${mxid} name should be updated`);
                singleChannelState.name = name;
            }

            const oldTopic = remoteRoom.remote.get("discord_topic");
            if (remoteRoom.remote.get("update_topic") && (forceUpdate || oldTopic !== topic)) {
                log.verbose(`Channel ${mxid} topic should be updated`);
                singleChannelState.topic = topic;
            }

            const oldIconUrl = remoteRoom.remote.get("discord_iconurl");
            // no force on icon update as we don't want to duplicate ALL the icons
            if (remoteRoom.remote.get("update_icon") && oldIconUrl !== iconUrl) {
                log.verbose(`Channel ${mxid} icon should be updated`);
                if (iconUrl !== null) {
                    singleChannelState.iconUrl = iconUrl;
                    singleChannelState.iconId = icon;
                } else {
                    singleChannelState.removeIcon = oldIconUrl !== null;
                }
            }
            channelState.mxChannels.push(singleChannelState);
        });
        return channelState;
    }
开发者ID:Half-Shot,项目名称:matrix-appservice-discord,代码行数:63,代码来源:channelsyncroniser.ts


注:本文中的matrix-appservice-bridge.Bridge.getRoomStore方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。