cordis/server/scripts/example-roles.js

30 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-10-30 17:26:41 +00:00
const ExitCodes = require('../../exit-codes/exit-codes.js');
const LOG = require('../../logger/logger.js')('setup-test-server');
const DB = require('../db.js');
process.on('unhandledRejection', async (reason, promise) => {
LOG.error('unhandled promise rejection:', reason);
ExitCodes.exit(ExitCodes.GENERAL_ERROR);
});
(async () => {
await DB.connect();
try {
let servers = await DB.getAllServers();
let targetServer = servers.find(server => server.name == 'no chicoms');
LOG.debug('target server:', { targetServer });
let members = await DB.getMembers(targetServer.id);
let targetMember = members.find(member => member.display_name == 'Elipzer');
LOG.debug('target member:', { targetMember });
let roleId = await DB.createRole(targetServer.id, 'Admin', '#ee0000', 2);
await DB.assignRolePrivilege(targetServer.id, roleId, 'modify_profile');
await DB.assignRolePrivilege(targetServer.id, roleId, 'modify_channels');
await DB.assignRolePrivilege(targetServer.id, roleId, 'modify_members');
await DB.assignRoleToMember(targetServer.id, roleId, targetMember.id);
LOG.info('role created and assigned');
} catch (e) {
LOG.error('error creating permissions');
}
await DB.end();
})();