本文整理汇总了TypeScript中matrix-appservice-bridge.Bridge.loadDatabases方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Bridge.loadDatabases方法的具体用法?TypeScript Bridge.loadDatabases怎么用?TypeScript Bridge.loadDatabases使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matrix-appservice-bridge.Bridge
的用法示例。
在下文中一共展示了Bridge.loadDatabases方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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);
}
}
示例2: run
async function run() {
try {
await bridge.loadDatabases();
} catch (e) {
await discordstore.init();
}
const userSync = new UserSyncroniser(bridge, config, discordbot);
bridge._clientFactory = clientFactory;
await discordbot.ClientFactory.init();
const client = await discordbot.ClientFactory.getClient();
const promiseList: Promise<void>[] = [];
let curDelay = config.limits.roomGhostJoinDelay;
try {
client.guilds.forEach((guild) => {
guild.members.forEach((member) => {
if (member.id === client.user.id) {
return;
}
promiseList.push((async () => {
await Bluebird.delay(curDelay);
let currentSchedule = JOIN_ROOM_SCHEDULE[0];
const doJoin = async () => {
await Util.DelayedPromise(currentSchedule);
await userSync.OnUpdateGuildMember(member, true);
};
const errorHandler = async (err) => {
log.error(`Error joining rooms for ${member.id}`);
log.error(err);
const idx = JOIN_ROOM_SCHEDULE.indexOf(currentSchedule);
if (idx === JOIN_ROOM_SCHEDULE.length - 1) {
log.warn(`Cannot join rooms for ${member.id}`);
throw new Error(err);
} else {
currentSchedule = JOIN_ROOM_SCHEDULE[idx + 1];
try {
await doJoin();
} catch (e) {
await errorHandler(e);
}
}
};
try {
await doJoin();
} catch (e) {
await errorHandler(e);
}
})());
curDelay += config.limits.roomGhostJoinDelay;
});
});
await Promise.all(promiseList);
} catch (err) {
log.error(err);
}
process.exit(0);
}
示例3: 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);
}