本文整理汇总了TypeScript中matrix-appservice-bridge.RoomBridgeStore类的典型用法代码示例。如果您正苦于以下问题:TypeScript RoomBridgeStore类的具体用法?TypeScript RoomBridgeStore怎么用?TypeScript RoomBridgeStore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RoomBridgeStore类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
}
示例2: 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);
}
示例3: OnDelete
public async OnDelete(channel: Discord.Channel) {
if (channel.type !== "text") {
log.info(`Channel ${channel.id} was deleted but isn't a text channel, so ignoring.`);
return;
}
log.info(`Channel ${channel.id} has been deleted.`);
let roomids;
let entries;
try {
roomids = await this.GetRoomIdsFromChannel(channel);
entries = await this.roomStore.getEntriesByMatrixIds(roomids);
} catch (e) {
log.warn(`Couldn't find roomids for deleted channel ${channel.id}`);
return;
}
for (const roomid of roomids) {
try {
await this.handleChannelDeletionForRoom(channel as Discord.TextChannel, roomid, entries[roomid][0]);
} catch (e) {
log.error(`Failed to delete channel from room: ${e}`);
}
}
}
示例4: 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);
}
示例5: 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;
}