Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const yamlConfig = yaml.safeLoad(fs.readFileSync("discord-registration.yaml", "utf8"));
const registration = AppServiceRegistration.fromObject(yamlConfig);
const config: DiscordBridgeConfig = yaml.safeLoad(fs.readFileSync(options.config, "utf8")) as DiscordBridgeConfig;
if (registration === null) {
throw new Error("Failed to parse registration file");
}
const clientFactory = new ClientFactory({
appServiceUserId: `@${registration.sender_localpart}:${config.bridge.domain}`,
token: registration.as_token,
url: config.bridge.homeserverUrl,
});
const client = clientFactory.getClientAs();
const intent = new Intent(client, client, {registered: true});
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);
}
}
run(); // tslint:disable-line no-floating-promises
async function run() {
await bridge.loadDatabases();
const store = new DiscordStore(config.database);
await store.init(undefined, bridge.getRoomStore());
const discordbot = new DiscordBot(botUserId, config, bridge, store);
await discordbot.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[] = [];
mxRoomEntries.forEach((entry) => {
if (entry.remote.get("plumbed")) {
return; // skipping plumbed rooms
}
const updateIcon = entry.remote.get("update_icon");
if (updateIcon !== undefined && updateIcon !== null) {