cordis/server/scripts/example-roles.ts
2021-12-04 06:02:11 -06:00

31 lines
1.2 KiB
TypeScript

import { ExitCode, ExitCodes } from "../../exit-codes/exit-codes";
import Logger from "../../logger/logger";
import DB from "../db";
const LOG = Logger.create('setup-test-guild');
process.on('unhandledRejection', async (reason, promise) => {
LOG.error('unhandled promise rejection:', reason);
ExitCodes.exit(ExitCode.GENERAL_ERROR);
});
(async () => {
await DB.connect();
try {
let guilds = await DB.getAllGuilds();
let targetGuild = guilds.find(guild => guild.name == 'no chicoms');
LOG.debug('target guild:', { targetGuild });
let members = await DB.getMembers(targetGuild.id);
let targetMember = members.find(member => member.display_name == 'Elipzer');
LOG.debug('target member:', { targetMember });
let roleId = await DB.createRole(targetGuild.id, 'Admin', '#ee0000', 2);
await DB.assignRolePrivilege(targetGuild.id, roleId, 'modify_profile');
await DB.assignRolePrivilege(targetGuild.id, roleId, 'modify_channels');
await DB.assignRolePrivilege(targetGuild.id, roleId, 'modify_members');
await DB.assignRoleToMember(targetGuild.id, roleId, targetMember.id);
LOG.info('role created and assigned');
} catch (e) {
LOG.error('error creating permissions', e);
}
await DB.end();
})();