/// <summary> /// Sets whether a user is allowed to join a VC /// </summary> /// <param name="vc">VC to set permissions on</param> /// <param name="user">User to set permissions on</param> /// <param name="allowUser">If the user is allowed to join</param> public async Task SetUserAllowed(IVoiceChannel vc, IGuildUser user, bool allowUser) { var newPerm = allowUser ? PermValue.Allow : PermValue.Inherit; var userPerms = vc.GetPermissionOverwrite(user) ?? OverwritePermissions.InheritAll; await vc.AddPermissionOverwriteAsync(user, userPerms.Modify(viewChannel: newPerm, connect: newPerm)).ConfigureAwait(false); }
/// <summary> /// Returns if everyone is able to join the VC /// </summary> /// <param name="vc">VC to check</param> /// <returns>If everyone is able to join the VC</returns> public bool IsVcPublic(IVoiceChannel vc) { var perms = vc.GetPermissionOverwrite(vc.Guild.EveryoneRole) ?? OverwritePermissions.InheritAll; return((perms.ViewChannel == PermValue.Allow || perms.ViewChannel == PermValue.Inherit) && (perms.Connect == PermValue.Allow || perms.Connect == PermValue.Inherit)); }
/// <summary> /// Sets if a VC should be NSFW or not /// </summary> /// <param name="vc">VC to modify</param> /// <param name="nsfw">If the VC should be nsfw</param> public async Task SetVcNsfw(IVoiceChannel vc, bool nsfw) { var props = SpService.GetProperties(vc.GuildId); var newPerm = nsfw ? PermValue.Allow : PermValue.Inherit; var nsfwRole = vc.Guild.GetRole(props.NsfwRoleId); var perms = vc.GetPermissionOverwrite(nsfwRole) ?? OverwritePermissions.InheritAll; await vc.AddPermissionOverwriteAsync(nsfwRole, perms.Modify(viewChannel: newPerm, connect: newPerm)).ConfigureAwait(false); }
/// <summary> /// Checks if a VC is NSFW /// </summary> /// <param name="vc"></param> /// <returns></returns> public bool IsVcNsfw(IVoiceChannel vc) { var props = SpService.GetProperties(vc.GuildId); if (props.NsfwRoleId == 0) { return(false); } var isPrivate = !IsVcPublic(vc); var perms = vc.GetPermissionOverwrite(vc.Guild.GetRole(props.NsfwRoleId)) ?? OverwritePermissions.InheritAll; return(isPrivate && (perms.ViewChannel == PermValue.Allow && perms.Connect == PermValue.Allow)); }
/// <summary> /// Checks if a user is trusted to modify a VC /// </summary> /// <param name="vc">VC to check permissions on</param> /// <param name="user">User to check permissions on</param> /// <returns>If the user is trusted to modify the VC</returns> public bool IsUserTrusted(IVoiceChannel vc, IGuildUser user) { var targetPerms = vc.GetPermissionOverwrite(user) ?? OverwritePermissions.InheritAll; return(targetPerms.ManageRoles == PermValue.Allow); }
/// <summary> /// Makes the VC public or private /// </summary> /// <param name="vc">VC to make private</param> /// <param name="makePrivate">If the VC should be private</param> public async Task SetPrivate(IVoiceChannel vc, bool makePrivate) { var perms = vc.GetPermissionOverwrite(vc.Guild.EveryoneRole) ?? OverwritePermissions.InheritAll; var newPerm = makePrivate ? PermValue.Deny : PermValue.Allow; await vc.AddPermissionOverwriteAsync(vc.Guild.EveryoneRole, perms.Modify(viewChannel: newPerm, connect: newPerm)).ConfigureAwait(false); }